From 79748a60124bb77228ed6ab0822272d493d50c39 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Tue, 17 Mar 2020 23:10:16 +0000 Subject: [PATCH] Uplift of #4970 (squashed) to beta --- .../preferences/BravePreferenceKeys.java | 4 +- .../upgrade/BraveUpgradeJobIntentService.java | 55 ++++++++++++++----- .../java/res/xml/appearance_preferences.xml | 2 +- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java b/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java index 6042de52be62..caa66990c3c2 100644 --- a/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java +++ b/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java @@ -6,6 +6,6 @@ package org.chromium.chrome.browser.preferences; public final class BravePreferenceKeys { - public static final String BRAVE_BOTTOM_TOOLBAR_SET_KEY = "brave_bottom_toolbar_set"; - public static final String BRAVE_BOTTOM_TOOLBAR_ENABLED_KEY = "brave_bottom_toolbar_enabled"; + public static final String BRAVE_BOTTOM_TOOLBAR_ENABLED_KEY = "brave_bottom_toolbar_enabled_key"; + public static final String BRAVE_BOTTOM_TOOLBAR_SET_KEY = "brave_bottom_toolbar_enabled"; } \ No newline at end of file diff --git a/android/java/org/chromium/chrome/browser/upgrade/BraveUpgradeJobIntentService.java b/android/java/org/chromium/chrome/browser/upgrade/BraveUpgradeJobIntentService.java index 19cfebfa6043..e30997de46f8 100644 --- a/android/java/org/chromium/chrome/browser/upgrade/BraveUpgradeJobIntentService.java +++ b/android/java/org/chromium/chrome/browser/upgrade/BraveUpgradeJobIntentService.java @@ -15,6 +15,7 @@ import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.task.PostTask; import org.chromium.chrome.browser.BraveHelper; +import org.chromium.chrome.browser.preferences.BravePreferenceKeys; import org.chromium.chrome.browser.preferences.BravePrefServiceBridge; import org.chromium.chrome.browser.preferences.website.BraveShieldsContentSettings; import org.chromium.chrome.browser.profiles.Profile; @@ -53,12 +54,51 @@ public class BraveUpgradeJobIntentService extends JobIntentService { private static final String DSE_NAME = "Google"; private static final String DSE_KEYWORD = "google.com"; + // Old tabs bottom toolbar settings + private static final String BOTTOM_TOOLBAR_ENABLED_KEY = "bottom_toolbar_enabled"; + + // To detect update from tabs + private static final String PREF_STATS_PREFERENCES_NAME = "StatsPreferences"; + private static final String PREF_WEEK_OF_INSTALLATION_NAME = "WeekOfInstallation"; + public static void startMigrationIfNecessary(Context context) { + if (BraveUpgradeJobIntentService.needToMigratePreferences()) { + // Migrate bottom toolbar settings + SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); + SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit(); + sharedPreferencesEditor.putBoolean(BravePreferenceKeys.BRAVE_BOTTOM_TOOLBAR_ENABLED_KEY, + sharedPreferences.getBoolean(BOTTOM_TOOLBAR_ENABLED_KEY, true)); + sharedPreferencesEditor.apply(); + } // Start migration in any case as we can have only partial data // to migrate available BraveUpgradeJobIntentService.enqueueWork(context, new Intent()); } + private static boolean needToMigratePreferences() { + SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); + boolean migrated = sharedPreferences.getBoolean(BraveHelper.PREF_TABS_SETTINGS_MIGRATED, false); + if (migrated) { + // Everything was already migrated + return false; + } + + // Detect whether it is update from tabs + SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit(); + SharedPreferences prefStatsFromTabs = ContextUtils.getApplicationContext() + .getSharedPreferences(PREF_STATS_PREFERENCES_NAME, 0); + boolean updateFormTabs = prefStatsFromTabs.contains(PREF_WEEK_OF_INSTALLATION_NAME); + if (!updateFormTabs) { + // We assume that everything was migrated in that case + sharedPreferencesEditor.putBoolean(BraveHelper.PREF_TABS_SETTINGS_MIGRATED, true); + sharedPreferencesEditor.apply(); + + return false; + } + + return true; + } + private static void enqueueWork(Context context, Intent work) { enqueueWork(context, BraveUpgradeJobIntentService.class, JOB_ID, work); } @@ -184,12 +224,10 @@ private boolean migrateShieldsSettingsForHost(String host, String settings) { } private void migrateTotalStatsAndPreferences() { - SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); - boolean migrated = sharedPreferences.getBoolean(BraveHelper.PREF_TABS_SETTINGS_MIGRATED, false); - if (migrated) { - // Everything was already migrated + if (!BraveUpgradeJobIntentService.needToMigratePreferences()) { return; } + SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); // Total stats migration long trackersBlockedCount = sharedPreferences.getLong(PREF_TRACKERS_BLOCKED_COUNT, 0); long adsBlockedCount = sharedPreferences.getLong(PREF_ADS_BLOCKED_COUNT, 0); @@ -205,15 +243,6 @@ private void migrateTotalStatsAndPreferences() { BravePrefServiceBridge.getInstance().setOldHttpsUpgradesCount(profile, httpsUpgradesCount); } SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit(); - if (trackersBlockedCount == 0 && - adsBlockedCount == 0 && - httpsUpgradesCount == 0) { - // We assume that everything was migrated in that case - sharedPreferencesEditor.putBoolean(BraveHelper.PREF_TABS_SETTINGS_MIGRATED, true); - sharedPreferencesEditor.apply(); - - return; - } sharedPreferencesEditor.putLong(PREF_TRACKERS_BLOCKED_COUNT, 0); sharedPreferencesEditor.putLong(PREF_ADS_BLOCKED_COUNT, 0); sharedPreferencesEditor.putLong(PREF_HTTPS_UPGRADES_COUNT, 0); diff --git a/android/java/res/xml/appearance_preferences.xml b/android/java/res/xml/appearance_preferences.xml index 1317290a55b9..e6bdda978a34 100644 --- a/android/java/res/xml/appearance_preferences.xml +++ b/android/java/res/xml/appearance_preferences.xml @@ -12,7 +12,7 @@ android:summaryOff="@string/hide_brave_rewards_icon_description" />