From 4fbbf9cbaaac2b9793e705e11c924effdcd2d0e5 Mon Sep 17 00:00:00 2001 From: Amogh Pradeep Date: Fri, 17 Jul 2015 13:27:07 -0400 Subject: [PATCH] Bug 25741 - TBA: Remove sync option from preferences We don't want this while the Sync subsystem is a proxy-bypass risk. We can drop this when the feature is patched (Bug 1314778). Signed-off-by: Amogh Pradeep Also: Bug 28507 - Don't call Push and Sync services during Sanitize Bug 30086 - Prevent Sync-related crashes on Android Bug 25741 - TBA: Only include Firefox Account permissions if we want them (using MOZ_ACCOUNT) Bug 25741 - TBA: Neuter Firefox Accounts --- .../app/src/main/res/xml/preferences.xml | 6 -- mobile/android/base/AndroidManifest.xml.in | 4 + .../base/FennecManifest_permissions.xml.in | 2 + .../java/org/mozilla/gecko/BrowserApp.java | 8 -- .../gecko/home/CombinedHistoryPanel.java | 14 +++- .../service/sharemethods/SendTab.java | 6 +- .../base/locales/en-US/torbrowser_strings.dtd | 2 + mobile/android/base/strings.xml.in | 2 + mobile/android/modules/Sanitizer.jsm | 47 +++++++----- .../mozilla/gecko/fxa/FirefoxAccounts.java | 73 ++++++++++++------- .../fxa/authenticator/AndroidFxAccount.java | 13 +++- 11 files changed, 107 insertions(+), 70 deletions(-) diff --git a/mobile/android/app/src/main/res/xml/preferences.xml b/mobile/android/app/src/main/res/xml/preferences.xml index a9cec32ca3ef7..f9c5c9e1ac535 100644 --- a/mobile/android/app/src/main/res/xml/preferences.xml +++ b/mobile/android/app/src/main/res/xml/preferences.xml @@ -9,12 +9,6 @@ xmlns:gecko="http://schemas.android.com/apk/res-auto" android:enabled="false"> - - +#ifdef MOZ_ACCOUNT #include ../services/manifests/FxAccountAndroidManifest_activities.xml.in +#endif #ifdef MOZ_CRASHREPORTER +#ifdef MOZ_ACCOUNT #include ../services/manifests/FxAccountAndroidManifest_services.xml.in +#endif + + diff --git a/mobile/android/base/strings.xml.in b/mobile/android/base/strings.xml.in index 208389c27c0c0..8018ebefc6062 100644 --- a/mobile/android/base/strings.xml.in +++ b/mobile/android/base/strings.xml.in @@ -55,6 +55,8 @@ &onboard_start_restricted1; + &sync_not_supported; + &bookmarks_title; &history_title; diff --git a/mobile/android/modules/Sanitizer.jsm b/mobile/android/modules/Sanitizer.jsm index f244e4a2008bb..d3538d49e07fe 100644 --- a/mobile/android/modules/Sanitizer.jsm +++ b/mobile/android/modules/Sanitizer.jsm @@ -183,18 +183,22 @@ Sanitizer.prototype = { sss.clearAll(); // Clear push subscriptions - await new Promise((resolve, reject) => { - let push = Cc["@mozilla.org/push/Service;1"].getService( - Ci.nsIPushService - ); - push.clearForDomain("*", status => { - if (Components.isSuccessCode(status)) { - resolve(); - } else { - reject(new Error("Error clearing push subscriptions: " + status)); - } - }); - }); + //await new Promise((resolve, reject) => { + // let push = Cc["@mozilla.org/push/Service;1"].getService( + // Ci.nsIPushService + // ); + // push.clearForDomain("*", status => { + // if (Components.isSuccessCode(status)) { + // resolve(); + // } else { + // reject(new Error("Error clearing push subscriptions: " + status)); + // } + // }); + //}); + + // Avoid throwing an error because Ci.nsIPushService isn't implemented + // All other clearing actions should succeed if we arrive here. + Promise.resolve(); TelemetryStopwatch.finish("FX_SANITIZE_SITESETTINGS", refObj); }, @@ -491,14 +495,17 @@ Sanitizer.prototype = { }, canClear: function(aCallback) { - Accounts.anySyncAccountsExist() - .then(aCallback) - .catch(function(err) { - Cu.reportError("Java-side synced tabs clearing failed: " + err); - aCallback(false); - }); - }, - }, + //Accounts.anySyncAccountsExist() + // .then(aCallback) + // .catch(function(err) { + // Cu.reportError("Java-side synced tabs clearing failed: " + err); + // aCallback(false); + // }); + + // We can't clear syncedTabs because Sync is non-functional + aCallback(false); + } + } }, }; diff --git 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 index 74b10c477237e..a207f9b237adb 100644 --- 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 @@ -7,6 +7,7 @@ package org.mozilla.gecko.fxa; import java.io.File; import java.util.concurrent.CountDownLatch; +import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.fxa.authenticator.AccountPickler; import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount; @@ -49,15 +50,22 @@ public class FirefoxAccounts { * @return Firefox account objects. */ public static Account[] getFirefoxAccounts(final Context context) { - final Account[] accounts = - AccountManager.get(context).getAccountsByType(FxAccountConstants.ACCOUNT_TYPE); - if (accounts.length > 0) { - FirefoxAccountsUtils.optionallySeparateAccountsDuringFirstRun(context, accounts); - return accounts; - } + if (AppConstants.isTorBrowser()) { + return new Account[0]; + } else { + // TBA: Conditionally disable this at run-time. + // XXX This will throw a java.lang.SecurityException because we don't declare + // the android.permission.GET_ACCOUNTS permission. + final Account[] accounts = + AccountManager.get(context).getAccountsByType(FxAccountConstants.ACCOUNT_TYPE); + if (accounts.length > 0) { + FirefoxAccountsUtils.optionallySeparateAccountsDuringFirstRun(context, accounts); + return accounts; + } - final Account pickledAccount = getPickledAccount(context); - return (pickledAccount != null) ? new Account[] {pickledAccount} : new Account[0]; + final Account pickledAccount = getPickledAccount(context); + return (pickledAccount != null) ? new Account[] {pickledAccount} : new Account[0]; + } } private static Account getPickledAccount(final Context context) { @@ -111,9 +119,14 @@ public class FirefoxAccounts { } public static void logSyncOptions(Bundle syncOptions) { - final boolean scheduleNow = syncOptions.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false); + if (AppConstants.isTorBrowser()) { + // Don't log an erroneous message, this'll only confuse someone looking at the logs. + return; + } else { + final boolean scheduleNow = syncOptions.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false); - Logger.info(LOG_TAG, "Sync options -- scheduling now: " + scheduleNow); + Logger.info(LOG_TAG, "Sync options -- scheduling now: " + scheduleNow); + } } public static void requestImmediateSync(final Account account, String[] stagesToSync, String[] stagesToSkip, boolean ignoreSettings) { @@ -145,28 +158,32 @@ public class FirefoxAccounts { * @param stagesToSkip stage names to skip. */ protected static void requestSync(final Account account, final Bundle syncOptions, String[] stagesToSync, String[] stagesToSkip) { - if (account == null) { - throw new IllegalArgumentException("account must not be null"); - } - if (syncOptions == null) { - throw new IllegalArgumentException("syncOptions must not be null"); - } + if (AppConstants.isTorBrowser()) { + return; + } else { + if (account == null) { + throw new IllegalArgumentException("account must not be null"); + } + if (syncOptions == null) { + throw new IllegalArgumentException("syncOptions must not be null"); + } - Utils.putStageNamesToSync(syncOptions, stagesToSync, stagesToSkip); + Utils.putStageNamesToSync(syncOptions, stagesToSync, stagesToSkip); - Logger.info(LOG_TAG, "Requesting sync."); - logSyncOptions(syncOptions); + Logger.info(LOG_TAG, "Requesting sync."); + logSyncOptions(syncOptions); - // We get strict mode warnings on some devices, so make the request on a - // background thread. - ThreadPool.run(new Runnable() { - @Override - public void run() { - for (String authority : AndroidFxAccount.DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.keySet()) { - ContentResolver.requestSync(account, authority, syncOptions); + // We get strict mode warnings on some devices, so make the request on a + // background thread. + ThreadPool.run(new Runnable() { + @Override + public void run() { + for (String authority : AndroidFxAccount.DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.keySet()) { + ContentResolver.requestSync(account, authority, syncOptions); + } } - } - }); + }); + } } /** diff --git 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 index 4562559afc440..8d2b8bd2cd4af 100644 --- 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 @@ -29,6 +29,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; import android.util.Log; +import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.background.common.GlobalConstants; import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.fxa.FxAccountUtils; @@ -708,7 +709,11 @@ public class AndroidFxAccount { * @param ignoreSettings whether we should check if syncing is allowed via in-app or system settings. */ public void requestImmediateSync(String[] stagesToSync, String[] stagesToSkip, boolean ignoreSettings) { - FirefoxAccounts.requestImmediateSync(getAndroidAccount(), stagesToSync, stagesToSkip, ignoreSettings); + if (AppConstants.isTorBrowser()) { + return; + } else { + FirefoxAccounts.requestImmediateSync(getAndroidAccount(), stagesToSync, stagesToSkip, ignoreSettings); + } } /** @@ -719,7 +724,11 @@ public class AndroidFxAccount { * @param stagesToSkip stage names to skip; can be null to skip no known stages. */ public void requestEventualSync(String[] stagesToSync, String[] stagesToSkip) { - FirefoxAccounts.requestEventualSync(getAndroidAccount(), stagesToSync, stagesToSkip); + if (AppConstants.isTorBrowser()) { + return; + } else { + FirefoxAccounts.requestEventualSync(getAndroidAccount(), stagesToSync, stagesToSkip); + } } public synchronized void setState(State state) { -- GitLab