Skip to content

Commit 54ba711

Browse files
authored
Implement custom tab handling for app links in BrowserTabViewModel. (#6866)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1211450043710855?focus=true ### Description Added support for better handling app links in custom tabs. When an app link is opened in a custom tab, the app will now directly open the app link without showing the app link prompt, regardless of the user's app link prompt settings. ### Steps to test this PR _App Links in Custom Tabs_ - [x] Install from this branch. - [x] See https://app.asana.com/1/137249556945/task/1211450043710855/comment/1211477223443413?focus=true for steps and credentials. - [x] See attached video to understand the flow and prerequisites (DDG is custom tab and DDG -> Settings -> Permissions -> Open Links is Apps is set to either `Ask Every Time` or `Never`). _Regular App Links_ - [x] Install from this branch. - [x] Open the app and set prerequisites: DDG is custom tab and DDG -> Settings -> Permissions -> Open Links is Apps is set to either `Ask Every Time` or `Never`. - [x] Navigate to a page with an app link. I.e: https://play.google.com/store/apps/details?id=com.duckduckgo.mobile.android&hl=en-US - [x] Verify that you are prompted to open the link in the Play Store app. ### UI changes No UI changes, only behavior changes in Custom Tab for app links.
1 parent 48b6103 commit 54ba711

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,6 +3820,18 @@ class BrowserTabViewModelTest {
38203820
assertCommandIssued<Command.OpenAppLink>()
38213821
}
38223822

3823+
@Test
3824+
fun whenHandleAppLinkCalledAndCustomTabIsTrueThenOpenAppLink() {
3825+
val urlType = SpecialUrlDetector.UrlType.AppLink(uriString = exampleUrl)
3826+
testee.setIsCustomTab(true)
3827+
testee.handleAppLink(urlType, isForMainFrame = true)
3828+
whenever(mockAppLinksHandler.isUserQuery()).thenReturn(false)
3829+
whenever(ctaViewModelMockSettingsStore.showAppLinksPrompt).thenReturn(false)
3830+
verify(mockAppLinksHandler).handleAppLink(eq(true), eq(exampleUrl), eq(false), eq(true), appLinkCaptor.capture())
3831+
appLinkCaptor.lastValue.invoke()
3832+
assertCommandIssued<Command.OpenAppLink>()
3833+
}
3834+
38233835
@Test
38243836
fun whenHandleNonHttpAppLinkCalledThenHandleNonHttpAppLink() {
38253837
val urlType = SpecialUrlDetector.UrlType.NonHttpAppLink("market://details?id=com.example", Intent(), exampleUrl)

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ class BrowserTabFragment :
10311031

10321032
if (savedInstanceState == null) {
10331033
viewModel.onViewReady()
1034+
viewModel.setIsCustomTab(tabDisplayedInCustomTabScreen)
10341035
messageFromPreviousTab?.let {
10351036
processMessage(it)
10361037
}

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ class BrowserTabViewModel @Inject constructor(
588588
private var isProcessingTrackingLink = false
589589
private var isLinkOpenedInNewTab = false
590590
private var allowlistRefreshTriggerJob: Job? = null
591+
private var isCustomTabScreen: Boolean = false
591592

592593
private val fireproofWebsitesObserver =
593594
Observer<List<FireproofWebsiteEntity>> {
@@ -802,6 +803,10 @@ class BrowserTabViewModel @Inject constructor(
802803
initialUrl?.let { buildSiteFactory(it, stillExternal = isExternal) }
803804
}
804805

806+
fun setIsCustomTab(isCustomTab: Boolean) {
807+
this.isCustomTabScreen = isCustomTab
808+
}
809+
805810
fun onViewReady() {
806811
url?.let {
807812
onUserSubmittedQuery(it)
@@ -3062,11 +3067,16 @@ class BrowserTabViewModel @Inject constructor(
30623067
}
30633068

30643069
private fun appLinkClicked(appLink: AppLink) {
3065-
if (appSettingsPreferencesStore.showAppLinksPrompt || appLinksHandler.isUserQuery()) {
3066-
command.value = ShowAppLinkPrompt(appLink)
3067-
appLinksHandler.setUserQueryState(false)
3068-
} else {
3069-
command.value = OpenAppLink(appLink)
3070+
when {
3071+
// When in custom tab, always open the app link directly, without prompting.
3072+
isCustomTabScreen -> command.value = OpenAppLink(appLink)
3073+
3074+
appSettingsPreferencesStore.showAppLinksPrompt || appLinksHandler.isUserQuery() -> {
3075+
command.value = ShowAppLinkPrompt(appLink)
3076+
appLinksHandler.setUserQueryState(false)
3077+
}
3078+
3079+
else -> command.value = OpenAppLink(appLink)
30703080
}
30713081
}
30723082

0 commit comments

Comments
 (0)