Commit 64769ff4 authored by Luca Hunkeler's avatar Luca Hunkeler Committed by Commit Bot

[Autofill Assistant] Migrate to SharedPreferencesManager

Bug: 1034952, 1022108
Change-Id: Ie9515b495f541f632b94d24553a16abc6ab6c58b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993812
Commit-Queue: Luca Hunkeler <hluca@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730220}
parent 8d70d4a3
......@@ -261,6 +261,7 @@ android_library("test_java") {
"//chrome/android:chrome_test_util_java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library:feed_lib_java",
"//chrome/browser/image_fetcher:java",
"//chrome/browser/preferences:java",
"//chrome/browser/ui/android/widget:java",
"//chrome/test/android:chrome_java_test_support",
"//components/autofill_assistant/browser:proto_java",
......
......@@ -26,7 +26,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf;
......@@ -37,6 +36,8 @@ import org.chromium.chrome.browser.directactions.DirectActionHandler;
import org.chromium.chrome.browser.directactions.DirectActionReporter;
import org.chromium.chrome.browser.directactions.DirectActionReporter.Type;
import org.chromium.chrome.browser.directactions.FakeDirectActionReporter;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -54,6 +55,8 @@ public class AutofillAssistantDirectActionHandlerTest {
private BottomSheetController mBottomSheetController;
private DirectActionHandler mHandler;
private TestingAutofillAssistantModuleEntryProvider mModuleEntryProvider;
private final SharedPreferencesManager mSharedPreferencesManager =
SharedPreferencesManager.getInstance();
@Before
public void setUp() throws Exception {
......@@ -69,11 +72,10 @@ public class AutofillAssistantDirectActionHandlerTest {
mActivity.getScrim(), mActivity.getTabModelSelector()::getCurrentTab,
mModuleEntryProvider);
ContextUtils.getAppSharedPreferences()
.edit()
.remove(AutofillAssistantPreferencesUtil.AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED)
.remove(AutofillAssistantPreferencesUtil.AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN)
.apply();
mSharedPreferencesManager.removeKey(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED);
mSharedPreferencesManager.removeKey(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN);
}
@Test
......
......@@ -4,41 +4,29 @@
package org.chromium.chrome.browser.autofill_assistant;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
/** Autofill Assistant related preferences util class. */
@SuppressWarnings("UseSharedPreferencesManagerFromChromeCheck")
class AutofillAssistantPreferencesUtil {
// Avoid instatiation by accident.
private AutofillAssistantPreferencesUtil() {}
/** Peference keeping track of whether the onboarding has been accepted. */
@VisibleForTesting
static final String AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED =
"AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED";
/** LEGACY preference for when the `do not show again' checkbox still existed. */
@VisibleForTesting
static final String AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN = "AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN";
/** Checks whether the Autofill Assistant switch preference in settings is on. */
static boolean isAutofillAssistantSwitchOn() {
return ContextUtils.getAppSharedPreferences().getBoolean(
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, true);
}
/** Checks whether the Autofill Assistant onboarding has been accepted. */
static boolean isAutofillOnboardingAccepted() {
return ContextUtils.getAppSharedPreferences().getBoolean(
AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED, false)
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED, false)
||
/* Legacy treatment: users of earlier versions should not have to see the onboarding
again if they checked the `do not show again' checkbox*/
ContextUtils.getAppSharedPreferences().getBoolean(
AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN, false);
SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN, false);
}
/** Checks whether the Autofill Assistant onboarding screen should be shown. */
......@@ -52,13 +40,9 @@ class AutofillAssistantPreferencesUtil {
* @param accept Flag indicating whether the ToS have been accepted.
*/
static void setInitialPreferences(boolean accept) {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, accept)
.apply();
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED, accept)
.apply();
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, accept);
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED, accept);
}
}
......@@ -49,6 +49,15 @@ public final class ChromePreferenceKeys {
/** Whether Autofill Assistant is enabled */
public static final String AUTOFILL_ASSISTANT_ENABLED = "autofill_assistant_switch";
/** Whether the Autofill Assistant onboarding has been accepted. */
public static final String AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED =
"AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED";
/**
* LEGACY preference indicating whether "do not show again" was checked in the autofill
* assistant onboarding
*/
public static final String AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN =
"AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN";
public static final String BOOKMARKS_LAST_MODIFIED_FOLDER_ID = "last_bookmark_folder_id";
public static final String BOOKMARKS_LAST_USED_URL = "enhanced_bookmark_last_used_url";
......@@ -592,6 +601,8 @@ public final class ChromePreferenceKeys {
return Arrays.asList(
ACCESSIBILITY_TAB_SWITCHER,
AUTOFILL_ASSISTANT_ENABLED,
AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED,
AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN,
BOOKMARKS_LAST_MODIFIED_FOLDER_ID,
BOOKMARKS_LAST_USED_URL,
BOOKMARKS_LAST_USED_PARENT,
......
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