Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

FxA sync fixes #2586

Merged
merged 1 commit into from
Jan 14, 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 @@ -25,8 +25,8 @@ import mozilla.components.service.fxa.sync.SyncStatusObserver
import mozilla.components.service.fxa.sync.getLastSynced
import org.mozilla.vrbrowser.R
import org.mozilla.vrbrowser.VRBrowserApplication
import org.mozilla.vrbrowser.utils.BitmapCache
import org.mozilla.vrbrowser.telemetry.GleanMetricsService
import org.mozilla.vrbrowser.utils.BitmapCache
import org.mozilla.vrbrowser.utils.SystemUtils
import org.mozilla.vrbrowser.utils.ViewUtils
import java.net.URL
Expand Down Expand Up @@ -127,8 +127,6 @@ class Accounts constructor(val context: Context) {
accountStatus = AccountStatus.SIGNED_IN

// Enable syncing after signing in
syncStorage.setStatus(SyncEngine.Bookmarks, SettingsStore.getInstance(context).isBookmarksSyncEnabled)
syncStorage.setStatus(SyncEngine.History, SettingsStore.getInstance(context).isHistorySyncEnabled)
services.accountManager.syncNowAsync(SyncReason.EngineChange, true)

// Update device list
Expand Down Expand Up @@ -319,11 +317,9 @@ class Accounts constructor(val context: Context) {
when(engine) {
SyncEngine.Bookmarks -> {
GleanMetricsService.FxA.bookmarksSyncStatus(value)
SettingsStore.getInstance(context).isBookmarksSyncEnabled = value
}
SyncEngine.History -> {
GleanMetricsService.FxA.historySyncStatus(value)
SettingsStore.getInstance(context).isHistorySyncEnabled = value
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,25 +621,6 @@ public void setPopUpsBlockingEnabled(boolean isEnabled) {
editor.putBoolean(mContext.getString(R.string.settings_key_pop_up_blocking), isEnabled);
editor.commit();
}
public void setBookmarksSyncEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_bookmarks_sync), isEnabled);
editor.commit();
}

public boolean isBookmarksSyncEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_bookmarks_sync), BOOKMARKS_SYNC_DEFAULT);
}

public void setHistorySyncEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_history_sync), isEnabled);
editor.commit();
}

public boolean isHistorySyncEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_history_sync), HISTORY_SYNC_DEFAULT);
}

public void setWhatsNewDisplayed(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class FxAAccountOptionsView extends SettingsView {
private Accounts mAccounts;
private Places mPlaces;
private Executor mUIThreadExecutor;
private boolean mInitialBookmarksState;
private boolean mInitialHistoryState;
private SignOutDialogWidget mSignOutDialog;

public FxAAccountOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
Expand Down Expand Up @@ -92,11 +90,8 @@ public void onShown() {
mAccounts.addAccountListener(mAccountListener);
mAccounts.addSyncListener(mSyncListener);

mInitialBookmarksState = mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE);
mInitialHistoryState = mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE);

mBinding.bookmarksSyncSwitch.setValue(mInitialBookmarksState, false);
mBinding.historySyncSwitch.setValue(mInitialHistoryState, false);
mBinding.bookmarksSyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE), false);
mBinding.historySyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE), false);

updateSyncBindings(mAccounts.isSyncing());
}
Expand All @@ -107,20 +102,16 @@ public void onHidden() {

mAccounts.removeAccountListener(mAccountListener);
mAccounts.removeSyncListener(mSyncListener);

// We only sync engines in case the user has changed the sync engines since previous sync
if (mBinding.bookmarksSyncSwitch.isChecked() != mInitialBookmarksState ||
mBinding.historySyncSwitch.isChecked() != mInitialHistoryState) {
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
}
}

private SwitchSetting.OnCheckedChangeListener mBookmarksSyncListener = (compoundButton, value, apply) -> {
mAccounts.setSyncStatus(SyncEngine.Bookmarks.INSTANCE, value);
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
};

private SwitchSetting.OnCheckedChangeListener mHistorySyncListener = (compoundButton, value, apply) -> {
mAccounts.setSyncStatus(SyncEngine.History.INSTANCE, value);
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
};

private void resetOptions() {
Expand All @@ -138,6 +129,9 @@ public void onStarted() {
public void onIdle() {
updateSyncBindings(false);

mBinding.bookmarksSyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.Bookmarks.INSTANCE), false);
mBinding.historySyncSwitch.setValue(mAccounts.isEngineEnabled(SyncEngine.History.INSTANCE), false);

// This shouldn't be necessary but for some reason the buttons stays hovered after the sync.
// I guess Android restoring it to the latest state (hovered) before being disabled
// Probably an Android bindings bug.
Expand Down Expand Up @@ -201,12 +195,7 @@ private void updateProfile(Profile profile) {
}

private void sync(View view) {
if (mBinding.bookmarksSyncSwitch.isChecked() != mInitialBookmarksState ||
mBinding.historySyncSwitch.isChecked() != mInitialHistoryState) {
mAccounts.syncNowAsync(SyncReason.EngineChange.INSTANCE, false);
} else {
mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
}
mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
mAccounts.updateProfileAsync();
}

Expand Down