Skip to content

Commit 765cc75

Browse files
authored
Fix location permissions messaging (#6013)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1174433894299346/task/1210122474301984?focus=true ### Description The location permission messages are being shown more than expected. ### Steps to test this PR _Message shown once_ - [x] Install app and visit serp - [x] Search for restaurants near me so that the location permission journey starts - [x] Allow location permission, make sure you check the “Always” checkbox - [x] Verify a snackbar appears - [x] Refresh page and verify snackbar doesn’t appear - [x] In the same tab, open a new site and navigate back - [x] Verify snackbar doesn’t appear - [x] Try with other sites _Message doesn’t show_ - [x] Re-Install app and visit serp - [x] Search for restaurants near me so that the location permission journey starts - [x] Allow location permission, don’t check “Always” checkbox - [x] Verify a snackbar appears - [x] In the same tab, open a new site and navigate back - [x] Verify snackbar doesn’t appear _Message shown on app restart_ - [x] Re-Install app and visit serp - [x] Search for restaurants near me so that the location permission journey starts - [x] Allow location permission, don’t check “Always” checkbox - [x] Verify a snackbar appears - [x] Force close the app and restart - [x] Verify snackbar appears - [x] Refresh page and verify snackbar doesn’t appear
1 parent c9bdb2e commit 765cc75

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,7 @@ class BrowserTabFragment :
20072007
it.isMainFrame,
20082008
it.onMaliciousWarningShown,
20092009
)
2010+
20102011
is Command.HideWarningMaliciousSite -> hideMaliciousWarning(it.canGoBack)
20112012
is Command.EscapeMaliciousSite -> onEscapeMaliciousSite()
20122013
is Command.CloseCustomTab -> closeCustomTab()
@@ -2062,6 +2063,7 @@ class BrowserTabFragment :
20622063

20632064
browserActivity?.openExistingTab(it.tabId)
20642065
}
2066+
20652067
is Command.ShowAutoconsentAnimation -> showAutoconsentAnimation(it.isCosmetic)
20662068

20672069
is Command.LaunchPopupMenu -> {

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ class BrowserTabViewModel @Inject constructor(
16011601
viewModelScope.launch { updateBookmarkAndFavoriteState(url) }
16021602

16031603
val permissionOrigin = site?.uri?.host?.asLocationPermissionOrigin()
1604-
permissionOrigin?.let { viewModelScope.launch { notifyPermanentLocationPermission(permissionOrigin) } }
1604+
permissionOrigin?.let { notifyPermanentLocationPermission(permissionOrigin) }
16051605

16061606
registerSiteVisit()
16071607

@@ -1711,13 +1711,33 @@ class BrowserTabViewModel @Inject constructor(
17111711
}
17121712
}
17131713

1714-
private suspend fun notifyPermanentLocationPermission(domain: String) {
1715-
if (sitePermissionsManager.hasSitePermanentPermission(domain, LocationPermissionRequest.RESOURCE_LOCATION_PERMISSION)) {
1716-
Timber.d("Location Permission: domain $domain site url ${site?.url} has location permission")
1717-
command.postValue(ShowDomainHasPermissionMessage(domain))
1714+
private fun notifyPermanentLocationPermission(domain: String) {
1715+
viewModelScope.launch(dispatchers.io()) {
1716+
if (sitePermissionsManager.hasSitePermanentPermission(domain, LocationPermissionRequest.RESOURCE_LOCATION_PERMISSION)) {
1717+
Timber.d("Location Permission: domain $domain site url ${site?.url} has location permission")
1718+
if (!locationPermissionMessages.containsKey(domain)) {
1719+
Timber.d("Location Permission: We haven't shown message for $domain this session")
1720+
setDomainHasLocationPermissionShown(domain)
1721+
if (shouldShowLocationPermissionMessage()) {
1722+
Timber.d("Location Permission: Show location permission for $domain")
1723+
withContext(dispatchers.main()) {
1724+
command.postValue(ShowDomainHasPermissionMessage(domain))
1725+
}
1726+
}
1727+
}
1728+
}
17181729
}
17191730
}
17201731

1732+
private fun setDomainHasLocationPermissionShown(domain: String) {
1733+
locationPermissionMessages[domain] = true
1734+
}
1735+
1736+
private fun shouldShowLocationPermissionMessage(): Boolean {
1737+
val url = site?.url ?: return true
1738+
return !duckDuckGoUrlDetector.isDuckDuckGoChatUrl(url)
1739+
}
1740+
17211741
private fun urlUpdated(url: String) {
17221742
Timber.v("Page url updated: $url")
17231743
site?.url = url
@@ -1998,9 +2018,9 @@ class BrowserTabViewModel @Inject constructor(
19982018
loadingViewState.value = currentLoadingViewState().copy(
19992019
isLoading = true,
20002020
trackersAnimationEnabled = true,
2001-
/*We set the progress to 20 so the omnibar starts animating and the user knows we are loading the page.
2002-
* We don't show the browser until the page actually starts loading, to prevent previous sites from briefly
2003-
* showing in case the URL was blocked locally and therefore never started to show*/
2021+
/*We set the progress to 20 so the omnibar starts animating and the user knows we are loading the page.
2022+
* We don't show the browser until the page actually starts loading, to prevent previous sites from briefly
2023+
* showing in case the URL was blocked locally and therefore never started to show*/
20042024
progress = 20,
20052025
url = documentUrlString,
20062026
)
@@ -2157,7 +2177,8 @@ class BrowserTabViewModel @Inject constructor(
21572177
val autoCompleteSuggestionsEnabled = appSettingsPreferencesStore.autoCompleteSuggestionsEnabled
21582178
val showAutoCompleteSuggestions = hasFocus && query.isNotBlank() && hasQueryChanged && autoCompleteSuggestionsEnabled
21592179
val showFavoritesAsSuggestions = if (!showAutoCompleteSuggestions) {
2160-
val urlFocused = hasFocus && query.isNotBlank() && !hasQueryChanged && (UriString.isWebUrl(query) || duckPlayer.isDuckPlayerUri(query))
2180+
val urlFocused =
2181+
hasFocus && query.isNotBlank() && !hasQueryChanged && (UriString.isWebUrl(query) || duckPlayer.isDuckPlayerUri(query))
21612182
val emptyQueryBrowsing = query.isBlank() && currentBrowserViewState().browserShowing
21622183
val favoritesAvailable = currentAutoCompleteViewState().favorites.isNotEmpty()
21632184
hasFocus && (urlFocused || emptyQueryBrowsing) && favoritesAvailable
@@ -2848,7 +2869,8 @@ class BrowserTabViewModel @Inject constructor(
28482869
command.value = HideOnboardingDaxDialog(cta)
28492870
if (cta is OnboardingDaxDialogCta.DaxTrackersBlockedCta) {
28502871
if (currentBrowserViewState().showPrivacyShield.isHighlighted()) {
2851-
browserViewState.value = currentBrowserViewState().copy(showPrivacyShield = HighlightableButton.Visible(highlighted = false))
2872+
browserViewState.value =
2873+
currentBrowserViewState().copy(showPrivacyShield = HighlightableButton.Visible(highlighted = false))
28522874
ctaViewModel.dismissPulseAnimation()
28532875
}
28542876
}

0 commit comments

Comments
 (0)