From d0e2d02b343ab913639b1098fc5622b14046ebf3 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Wed, 27 May 2020 16:34:11 +0300 Subject: [PATCH] For #10948 - Avoid PWA onboarding if user already has them on screen It is possible that after migration users would already have Firefox PWAs on their screen. Since they already know about this functionality, we should not promote it to them with the one-off `FirstTimePwaFragment`. To query installed PWAs we'll use an API available only on Android >= 26 which means that we will probably have half of users with PWAs still see the onboarding but half which will not. --- .../java/org/mozilla/fenix/utils/Settings.kt | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index af0ba9b53..b80125c42 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -9,6 +9,8 @@ import android.app.Application import android.content.Context import android.content.Context.MODE_PRIVATE import android.content.SharedPreferences +import android.content.pm.ShortcutManager +import android.os.Build import android.view.accessibility.AccessibilityManager import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting.PRIVATE @@ -454,10 +456,34 @@ class Settings private constructor( default = false ) - var shouldShowFirstTimePwaFragment by booleanPreference( - appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa), - default = true - ) + var shouldShowFirstTimePwaFragment: Boolean + get() { + val alreadyShownPwaOnboarding = preferences.getBoolean( + appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa), false) + + // ShortcutManager::pinnedShortcuts is only available on Oreo+ + if (!alreadyShownPwaOnboarding && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val alreadyHavePWaInstalled = + appContext.getSystemService(ShortcutManager::class.java) + .pinnedShortcuts.size > 0 + + // Users don't need to be shown the PWA onboarding if they already have PWAs installed. + preferences.edit() + .putBoolean( + appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa), + alreadyHavePWaInstalled) + .apply() + + return !alreadyHavePWaInstalled + } + + return !alreadyShownPwaOnboarding + } + set(value) { + preferences.edit() + .putBoolean(appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa), value) + .apply() + } @VisibleForTesting(otherwise = PRIVATE) internal val trackingProtectionOnboardingCount by intPreference(