Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate android toolbar settings (uplift to 1.7.x) #4971

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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";
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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