Commit a82983af authored by asvitkine's avatar asvitkine Committed by Commit bot

Expand code that syncs ToS-seen prefs on Android.

With this change, this code will set both the Java and native side
prefs if any of the three indicators of TOS being seen are true,
i.e. either of the two prefs or "any user has seen ToS".

This is especially needed to fix variations seed fetching from
native code in the case of Backup & Restore, which does not
appear to restore the Chrome native pref.

BUG=669543

Review-Url: https://codereview.chromium.org/2614183002
Cr-Commit-Position: refs/heads/master@{#442065}
parent 9276998c
...@@ -24,15 +24,28 @@ public class FirstRunGlueImpl implements FirstRunGlue { ...@@ -24,15 +24,28 @@ public class FirstRunGlueImpl implements FirstRunGlue {
private static final String CACHED_TOS_ACCEPTED_PREF = "first_run_tos_accepted"; private static final String CACHED_TOS_ACCEPTED_PREF = "first_run_tos_accepted";
/** /**
* Synchronizes first run native and Java preferences. Previous versions would * Synchronizes first run native and Java preferences.
* set only the native pref so this function synchronizes that state to Java.
* Must be called after native initialization. * Must be called after native initialization.
*/ */
public static void cacheFirstRunPrefs() { public static void cacheFirstRunPrefs() {
SharedPreferences javaPrefs = ContextUtils.getAppSharedPreferences(); SharedPreferences javaPrefs = ContextUtils.getAppSharedPreferences();
if (!javaPrefs.getBoolean(CACHED_TOS_ACCEPTED_PREF, false) PrefServiceBridge prefsBridge = PrefServiceBridge.getInstance();
&& PrefServiceBridge.getInstance().isFirstRunEulaAccepted()) { // Set both Java and native prefs if any of the three indicators indicate ToS has been
javaPrefs.edit().putBoolean(CACHED_TOS_ACCEPTED_PREF, true).apply(); // accepted. This needed because:
// - Old versions only set native pref, so this syncs Java pref.
// - Backup & restore does not restore native pref, so this needs to update it.
// - checkAnyUserHasSeenToS() may be true which needs to sync its state to the prefs.
boolean javaPrefValue = javaPrefs.getBoolean(CACHED_TOS_ACCEPTED_PREF, false);
boolean nativePrefValue = prefsBridge.isFirstRunEulaAccepted();
boolean userHasSeenTos =
ToSAckedReceiver.checkAnyUserHasSeenToS(ContextUtils.getApplicationContext());
if (javaPrefValue || nativePrefValue || userHasSeenTos) {
if (!javaPrefValue) {
javaPrefs.edit().putBoolean(CACHED_TOS_ACCEPTED_PREF, true).apply();
}
if (!nativePrefValue) {
prefsBridge.setEulaAccepted();
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment