|
|
|
@ -12,6 +12,7 @@ import android.content.SharedPreferences
|
|
|
|
|
import android.content.pm.ShortcutManager
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.view.accessibility.AccessibilityManager
|
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
|
import androidx.annotation.VisibleForTesting
|
|
|
|
|
import androidx.annotation.VisibleForTesting.PRIVATE
|
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
@ -39,6 +40,7 @@ import org.mozilla.fenix.settings.logins.SavedLoginsSortingStrategyMenu
|
|
|
|
|
import org.mozilla.fenix.settings.logins.SortingStrategy
|
|
|
|
|
import org.mozilla.fenix.settings.registerOnSharedPreferenceChangeListener
|
|
|
|
|
import java.security.InvalidParameterException
|
|
|
|
|
import java.time.LocalDate
|
|
|
|
|
|
|
|
|
|
private const val AUTOPLAY_USER_SETTING = "AUTOPLAY_USER_SETTING"
|
|
|
|
|
|
|
|
|
@ -63,6 +65,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
|
|
|
|
|
private const val ALLOWED_INT = 2
|
|
|
|
|
private const val CFR_COUNT_CONDITION_FOCUS_INSTALLED = 1
|
|
|
|
|
private const val CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED = 3
|
|
|
|
|
private const val MIN_DAYS_SINCE_FEEDBACK_PROMPT = 120
|
|
|
|
|
|
|
|
|
|
private fun Action.toInt() = when (this) {
|
|
|
|
|
Action.BLOCKED -> BLOCKED_INT
|
|
|
|
@ -792,6 +795,62 @@ class Settings(private val appContext: Context) : PreferencesHolder {
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private val numTimesFeedbackPromptShown: Int
|
|
|
|
|
get() = preferences.getInt(
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_feedback_prompt_shown),
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
fun incrementNumTimesFeedbackPromptShown() {
|
|
|
|
|
preferences.edit().putInt(
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_feedback_prompt_shown),
|
|
|
|
|
numTimesFeedbackPromptShown + 1
|
|
|
|
|
).apply()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val numTimesOpenedAfterInstall: Int
|
|
|
|
|
get() = preferences.getInt(
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_times_opened_after_install),
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
fun incrementNumTimesOpenedAfterInstall() {
|
|
|
|
|
preferences.edit().putInt(
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_times_opened_after_install),
|
|
|
|
|
numTimesOpenedAfterInstall + 1
|
|
|
|
|
).apply()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val timeWhenPromptWasLastShown: Int
|
|
|
|
|
get() = preferences.getInt(
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_time_prompt_shown),
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.O)
|
|
|
|
|
fun incrementTimeWhenPromptWasLastShown() {
|
|
|
|
|
preferences.edit().putInt(
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_time_prompt_shown),
|
|
|
|
|
LocalDate.now().dayOfYear
|
|
|
|
|
).apply()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* User feedback prompt is shown when Firefox is set as the default browser and after the
|
|
|
|
|
* 5th time the user opened the app. This prompt should only be shown once every four months.
|
|
|
|
|
*/
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.O)
|
|
|
|
|
val shouldShowUserFeedbackPrompt: Boolean =
|
|
|
|
|
numTimesOpenedAfterInstall >= 5
|
|
|
|
|
&& isDefaultBrowser()
|
|
|
|
|
&& (hasBeenFourMonthsSince(timeWhenPromptWasLastShown))
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.O)
|
|
|
|
|
private fun hasBeenFourMonthsSince(timeWhenPromptWasLastShown: Int): Boolean {
|
|
|
|
|
val numDays = LocalDate.now().dayOfYear - timeWhenPromptWasLastShown
|
|
|
|
|
return numDays >= MIN_DAYS_SINCE_FEEDBACK_PROMPT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val showPrivateModeContextualFeatureRecommender: Boolean
|
|
|
|
|
get() {
|
|
|
|
|
val focusInstalled = MozillaProductDetector
|
|
|
|
|