Skip to content

Commit

Permalink
Merge pull request #4971 from brave/pr4970_android_toolbar_migration_…
Browse files Browse the repository at this point in the history
…1.7.x

migrate android toolbar settings (uplift to 1.7.x)
  • Loading branch information
kjozwiak committed Mar 18, 2020
2 parents 87c03cd + 79748a6 commit 86789ff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
Expand Up @@ -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";
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion android/java/res/xml/appearance_preferences.xml
Expand Up @@ -12,7 +12,7 @@
android:summaryOff="@string/hide_brave_rewards_icon_description" />

<org.chromium.chrome.browser.settings.ChromeSwitchPreference
android:key="brave_bottom_toolbar_enabled"
android:key="brave_bottom_toolbar_enabled_key"
android:title="@string/bottom_toolbar_enable"
android:summaryOn="@string/text_on"
android:summaryOff="@string/text_off" />
Expand Down

0 comments on commit 86789ff

Please sign in to comment.