Bug 1401336 - Make user-initiated syncs ignore account sync settings. r?Grisha Kruglov
MozReview-Commit-ID: JkMQb5f0yVM
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -629,17 +629,17 @@ public class CombinedHistoryPanel extend
}
}
protected class RemoteTabsRefreshListener implements SwipeRefreshLayout.OnRefreshListener {
@Override
public void onRefresh() {
if (FirefoxAccounts.firefoxAccountsExist(getActivity())) {
final Account account = FirefoxAccounts.getFirefoxAccount(getActivity());
- FirefoxAccounts.requestImmediateSync(account, STAGES_TO_SYNC_ON_REFRESH, null);
+ FirefoxAccounts.requestImmediateSync(account, STAGES_TO_SYNC_ON_REFRESH, null, true);
} else {
Log.wtf(LOGTAG, "No Firefox Account found; this should never happen. Ignoring.");
mRefreshLayout.setRefreshing(false);
}
}
}
protected class RemoteTabsSyncListener implements SyncStatusListener {
--- a/mobile/android/base/java/org/mozilla/gecko/overlays/service/sharemethods/SendTab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/overlays/service/sharemethods/SendTab.java
@@ -288,12 +288,12 @@ public class SendTab extends ShareMethod
} catch (Exception e) {
Log.w(LOGTAG, "Could not get Firefox Account parameters or preferences; aborting.");
return null;
}
}
@Override
public void sync() {
- fxAccount.requestImmediateSync(STAGES_TO_SYNC, null);
+ fxAccount.requestImmediateSync(STAGES_TO_SYNC, null, true);
}
}
}
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FirefoxAccounts.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FirefoxAccounts.java
@@ -143,18 +143,21 @@ public class FirefoxAccounts {
}
public static void logSyncOptions(Bundle syncOptions) {
final boolean scheduleNow = syncOptions.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false);
Logger.info(LOG_TAG, "Sync options -- scheduling now: " + scheduleNow);
}
- public static void requestImmediateSync(final Account account, String[] stagesToSync, String[] stagesToSkip) {
+ public static void requestImmediateSync(final Account account, String[] stagesToSync, String[] stagesToSkip, boolean ignoreSettings) {
final Bundle syncOptions = new Bundle();
+ if (ignoreSettings) {
+ syncOptions.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
+ }
syncOptions.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, true);
syncOptions.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
requestSync(account, syncOptions, stagesToSync, stagesToSkip);
}
public static void requestEventualSync(final Account account, String[] stagesToSync, String[] stagesToSkip) {
requestSync(account, Bundle.EMPTY, stagesToSync, stagesToSkip);
}
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
@@ -79,31 +79,31 @@ public class FxAccountPushHandler {
private static void handleVerification(Context context) {
AndroidFxAccount fxAccount = AndroidFxAccount.fromContext(context);
if (fxAccount == null) {
Log.e(LOG_TAG, "The Android account does not exist anymore");
return;
}
Log.i(LOG_TAG, "Received 'accountVerified' push event, requesting immediate sync");
// This will trigger an email verification check and a sync.
- fxAccount.requestImmediateSync(null, null);
+ fxAccount.requestImmediateSync(null, null, true);
}
private static void handleCollectionChanged(Context context, JSONObject data) throws JSONException {
JSONArray collections = data.getJSONArray("collections");
int len = collections.length();
for (int i = 0; i < len; i++) {
if (collections.getString(i).equals(CLIENTS_COLLECTION)) {
final Account account = FirefoxAccounts.getFirefoxAccount(context);
if (account == null) {
Log.e(LOG_TAG, "The account does not exist anymore");
return;
}
final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
- fxAccount.requestImmediateSync(new String[] { CLIENTS_COLLECTION }, null);
+ fxAccount.requestImmediateSync(new String[] { CLIENTS_COLLECTION }, null, true);
return;
}
}
}
private static void handleDeviceDisconnection(Context context, JSONObject data) throws JSONException {
final Account account = FirefoxAccounts.getFirefoxAccount(context);
if (account == null) {
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountStatusFragment.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountStatusFragment.java
@@ -264,17 +264,17 @@ public class FxAccountStatusFragment
preference == passwordsPreference ||
preference == tabsPreference) {
saveEngineSelections();
return true;
}
if (preference == syncNowPreference) {
if (fxAccount != null) {
- fxAccount.requestImmediateSync(null, null);
+ fxAccount.requestImmediateSync(null, null, true);
}
return true;
}
if (TextUtils.equals("linktos", preference.getKey())) {
ActivityUtils.openURLInFennec(getActivity().getApplicationContext(), getResources().getString(R.string.fxaccount_link_tos));
return true;
}
@@ -852,17 +852,17 @@ public class FxAccountStatusFragment
final String key = preference.getKey();
if ("debug_refresh".equals(key)) {
Logger.info(LOG_TAG, "Refreshing.");
refresh();
} else if ("debug_dump".equals(key)) {
fxAccount.dump();
} else if ("debug_force_sync".equals(key)) {
Logger.info(LOG_TAG, "Force syncing.");
- fxAccount.requestImmediateSync(null, null);
+ fxAccount.requestImmediateSync(null, null, true);
// No sense refreshing, since the sync will complete in the future.
} else if ("debug_forget_certificate".equals(key)) {
State state = fxAccount.getState();
try {
Married married = (Married) state;
Logger.info(LOG_TAG, "Moving to Cohabiting state: Forgetting certificate.");
fxAccount.setState(married.makeCohabitingState());
refresh();
@@ -938,17 +938,17 @@ public class FxAccountStatusFragment
if (TextUtils.isEmpty(newClientName)) {
newClientName = clientsDataDelegate.getDefaultClientName();
}
final long now = System.currentTimeMillis();
clientsDataDelegate.setClientName(newClientName, now);
// Force sync the client record, we want the user to see the device name change immediately
// on the FxA Device Manager if possible ( = we are online) to avoid confusion
// ("I changed my Android's device name but I don't see it on my computer").
- fxAccount.requestImmediateSync(STAGES_TO_SYNC_ON_DEVICE_NAME_CHANGE, null);
+ fxAccount.requestImmediateSync(STAGES_TO_SYNC_ON_DEVICE_NAME_CHANGE, null, true);
hardRefresh(); // Updates the value displayed to the user, among other things.
return true;
}
// For everything else, accept the change.
return true;
}
}
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java
@@ -677,19 +677,20 @@ public class AndroidFxAccount {
return active;
}
/**
* Request an immediate sync. Use this to sync as soon as possible in response to user action.
*
* @param stagesToSync stage names to sync; can be null to sync <b>all</b> known stages.
* @param stagesToSkip stage names to skip; can be null to skip <b>no</b> known stages.
+ * @param ignoreSettings whether we should check preferences for syncing over metered connections.
*/
- public void requestImmediateSync(String[] stagesToSync, String[] stagesToSkip) {
- FirefoxAccounts.requestImmediateSync(getAndroidAccount(), stagesToSync, stagesToSkip);
+ public void requestImmediateSync(String[] stagesToSync, String[] stagesToSkip, boolean ignoreSettings) {
+ FirefoxAccounts.requestImmediateSync(getAndroidAccount(), stagesToSync, stagesToSkip, ignoreSettings);
}
/**
* Request an eventual sync. Use this to request the system queue a sync for some time in the
* future.
*
* @param stagesToSync stage names to sync; can be null to sync <b>all</b> known stages.
* @param stagesToSkip stage names to skip; can be null to skip <b>no</b> known stages.
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/receivers/FxAccountUpgradeReceiver.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/receivers/FxAccountUpgradeReceiver.java
@@ -86,17 +86,17 @@ public class FxAccountUpgradeReceiver ex
@Override
public void run() {
final Account[] accounts = FirefoxAccounts.getFirefoxAccounts(context);
Logger.info(LOG_TAG, "Trying to sync " + accounts.length + " existing Firefox Accounts.");
for (Account account : accounts) {
try {
final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
- fxAccount.requestImmediateSync(new String[] { "clients" }, null);
+ fxAccount.requestImmediateSync(new String[] { "clients" }, null, true);
} catch (Exception e) {
Logger.warn(LOG_TAG, "Got exception trying to force sync account named like " + Utils.obfuscateEmail(account.name) +
"; ignoring.", e);
}
}
}
}
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/sync/FxAccountSyncAdapter.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/sync/FxAccountSyncAdapter.java
@@ -696,17 +696,17 @@ public class FxAccountSyncAdapter extend
}
// Full sync (of all of stages) is necessary if we hit "concurrent modification" errors while
// uploading meta/global stage. This is considered both a rare and important event, so it's
// deemed safe and necessary to request an immediate sync, which will ignore any back-offs and
// will happen right away.
if (syncDelegate.fullSyncNecessary) {
Logger.info(LOG_TAG, "Syncing done. Full follow-up sync necessary, requesting immediate sync.");
- fxAccount.requestImmediateSync(null, null);
+ fxAccount.requestImmediateSync(null, null, false);
return;
}
// If there are any incomplete stages, request a follow-up sync. Otherwise, we're done.
// Incomplete stage is:
// - one that hit a 412 error during either upload or download of data, indicating that
// its collection has been modified remotely, or
// - one that hit a sync deadline
@@ -719,11 +719,11 @@ public class FxAccountSyncAdapter extend
if (stagesToSyncAgain.length == 0) {
Logger.info(LOG_TAG, "Syncing done.");
return;
}
// If there are any other stages marked as incomplete, request that they're synced again.
Logger.info(LOG_TAG, "Syncing done. Requesting an immediate follow-up sync.");
- fxAccount.requestImmediateSync(stagesToSyncAgain, null);
+ fxAccount.requestImmediateSync(stagesToSyncAgain, null, false);
}
}