1
0
Fork 0

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.
master
Mugurell 2020-05-27 16:34:11 +03:00 committed by Jeff Boek
parent 2005375db5
commit d0e2d02b34
1 changed files with 30 additions and 4 deletions

View File

@ -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(