Bug 1155684 - Part 1-3: Remove reading list sync integration. r=nalexander, a=sledru
authorRichard Newman <rnewman@mozilla.com>
Mon, 20 Apr 2015 18:02:17 -0700
changeset 260253 309ed42a5999
parent 260252 18c8180670c7
child 260254 98086516ce8f
push id727
push userryanvm@gmail.com
push date2015-04-23 14:45 +0000
treeherdermozilla-release@7c66212e4c09 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander, sledru
bugs1155684
milestone38.0
Bug 1155684 - Part 1-3: Remove reading list sync integration. r=nalexander, a=sledru
mobile/android/base/fxa/activities/FxAccountStatusFragment.java
mobile/android/base/fxa/authenticator/AndroidFxAccount.java
mobile/android/base/fxa/receivers/FxAccountUpgradeReceiver.java
mobile/android/base/resources/xml/fxaccount_status_prefscreen.xml
mobile/android/services/manifests/FxAccountAndroidManifest_services.xml.in
--- a/mobile/android/base/fxa/activities/FxAccountStatusFragment.java
+++ b/mobile/android/base/fxa/activities/FxAccountStatusFragment.java
@@ -8,35 +8,32 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.R;
-import org.mozilla.gecko.background.ReadingListConstants;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountUtils;
 import org.mozilla.gecko.background.preferences.PreferenceFragment;
-import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.fxa.login.Married;
 import org.mozilla.gecko.fxa.login.State;
 import org.mozilla.gecko.fxa.sync.FxAccountSyncStatusHelper;
 import org.mozilla.gecko.fxa.tasks.FxAccountCodeResender;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.SharedPreferencesClientsDataDelegate;
 import org.mozilla.gecko.sync.SyncConfiguration;
 import org.mozilla.gecko.util.HardwareUtils;
 
 import android.accounts.Account;
-import android.accounts.AccountManager;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.os.Handler;
 import android.preference.CheckBoxPreference;
 import android.preference.EditTextPreference;
@@ -173,19 +170,16 @@ public class FxAccountStatusFragment
     needsFinishMigratingPreference = ensureFindPreference("needs_finish_migrating");
 
     syncCategory = (PreferenceCategory) ensureFindPreference("sync_category");
 
     bookmarksPreference = (CheckBoxPreference) ensureFindPreference("bookmarks");
     historyPreference = (CheckBoxPreference) ensureFindPreference("history");
     tabsPreference = (CheckBoxPreference) ensureFindPreference("tabs");
     passwordsPreference = (CheckBoxPreference) ensureFindPreference("passwords");
-    // The Reading List toggle appears with the other Firefox Sync toggles but
-    // controls a separate Android authority.
-    readingListPreference = (CheckBoxPreference) ensureFindPreference("reading_list");
 
     if (!FxAccountUtils.LOG_PERSONAL_INFORMATION) {
       removeDebugButtons();
     } else {
       connectDebugButtons();
       ALWAYS_SHOW_AUTH_SERVER = true;
       ALWAYS_SHOW_SYNC_SERVER = true;
     }
@@ -195,17 +189,16 @@ public class FxAccountStatusFragment
     needsPasswordPreference.setOnPreferenceClickListener(this);
     needsVerificationPreference.setOnPreferenceClickListener(this);
     needsFinishMigratingPreference.setOnPreferenceClickListener(this);
 
     bookmarksPreference.setOnPreferenceClickListener(this);
     historyPreference.setOnPreferenceClickListener(this);
     tabsPreference.setOnPreferenceClickListener(this);
     passwordsPreference.setOnPreferenceClickListener(this);
-    readingListPreference.setOnPreferenceClickListener(this);
 
     deviceNamePreference = (EditTextPreference) ensureFindPreference("device_name");
     deviceNamePreference.setOnPreferenceChangeListener(this);
 
     syncServerPreference = ensureFindPreference("sync_server");
     morePreference = ensureFindPreference("more");
     morePreference.setOnPreferenceClickListener(this);
 
@@ -283,24 +276,16 @@ public class FxAccountStatusFragment
     if (preference == bookmarksPreference ||
         preference == historyPreference ||
         preference == passwordsPreference ||
         preference == tabsPreference) {
       saveEngineSelections();
       return true;
     }
 
-    if (preference == readingListPreference) {
-      final boolean syncAutomatically = readingListPreference.isChecked();
-      ContentResolver.setIsSyncable(fxAccount.getAndroidAccount(), BrowserContract.READING_LIST_AUTHORITY, 1);
-      ContentResolver.setSyncAutomatically(fxAccount.getAndroidAccount(), BrowserContract.READING_LIST_AUTHORITY, syncAutomatically);
-      FxAccountUtils.pii(LOG_TAG, (syncAutomatically ? "En" : "Dis") + "abling Reading List sync automatically.");
-      return true;
-    }
-
     if (preference == morePreference) {
       getActivity().openOptionsMenu();
       return true;
     }
 
     if (preference == syncNowPreference) {
       if (fxAccount != null) {
         FirefoxAccounts.requestSync(fxAccount.getAndroidAccount(), FirefoxAccounts.FORCE, null, null);
@@ -325,21 +310,16 @@ public class FxAccountStatusFragment
   protected void setCheckboxesEnabled(boolean enabled) {
     bookmarksPreference.setEnabled(enabled);
     historyPreference.setEnabled(enabled);
     tabsPreference.setEnabled(enabled);
     passwordsPreference.setEnabled(enabled);
     // Since we can't sync, we can't update our remote client record.
     deviceNamePreference.setEnabled(enabled);
     syncNowPreference.setEnabled(enabled);
-
-    // The checkboxes are a set of global settings: they reflect the account
-    // state and not the underlying Sync state. In the future, each checkbox
-    // will reflect its own piece of the account state.
-    readingListPreference.setEnabled(enabled);
   }
 
   /**
    * Show at most one error preference, hiding all others.
    *
    * @param errorPreferenceToShow
    *          single error preference to show; if null, hide all error preferences
    */
@@ -551,17 +531,16 @@ public class FxAccountStatusFragment
       final boolean masterSyncAutomatically = ContentResolver.getMasterSyncAutomatically();
       if (!masterSyncAutomatically) {
         showNeedsMasterSyncAutomaticallyEnabled();
         return;
       }
     } finally {
       // No matter our state, we should update the checkboxes.
       updateSelectedEngines();
-      updateReadingList();
     }
 
     final String clientName = clientsDataDelegate.getClientName();
     deviceNamePreference.setSummary(clientName);
     deviceNamePreference.setText(clientName);
 
     updateSyncNowPreference();
   }
@@ -664,29 +643,16 @@ public class FxAccountStatusFragment
       setCheckboxesEnabled(false);
     } catch (Exception e) {
       Logger.warn(LOG_TAG, "Got exception getting engines to select; ignoring.", e);
       return;
     }
   }
 
   /**
-   * Query the current reading list automatic sync state, and update the UI
-   * accordingly.
-   */
-  protected void updateReadingList() {
-    if (AppConstants.MOZ_ANDROID_READING_LIST_SERVICE) {
-      final boolean syncAutomatically = ContentResolver.getSyncAutomatically(fxAccount.getAndroidAccount(), BrowserContract.READING_LIST_AUTHORITY);
-      readingListPreference.setChecked(syncAutomatically);
-    } else {
-      syncCategory.removePreference(readingListPreference);
-    }
-  }
-
-  /**
    * Persist engine selections to local shared preferences, and request a sync
    * to persist selections to remote storage.
    */
   protected void saveEngineSelections() {
     final Map<String, Boolean> engineSelections = new HashMap<String, Boolean>();
     engineSelections.put("bookmarks", bookmarksPreference.isChecked());
     engineSelections.put("history", historyPreference.isChecked());
     engineSelections.put("passwords", passwordsPreference.isChecked());
@@ -785,26 +751,16 @@ public class FxAccountStatusFragment
         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.requestSync(FirefoxAccounts.FORCE);
         // No sense refreshing, since the sync will complete in the future.
-      } else if ("debug_forget_reading_list_oauth_token".equals(key)) {
-        final Account account = fxAccount.getAndroidAccount();
-        final AccountManager accountManager = AccountManager.get(getActivity());
-        final String authToken = accountManager.peekAuthToken(account, ReadingListConstants.AUTH_TOKEN_TYPE);
-        if (authToken != null) {
-          Logger.info(LOG_TAG, "Forgetting reading list oauth token: " + authToken);
-          accountManager.invalidateAuthToken(account.type, authToken);
-        } else {
-          Logger.warn(LOG_TAG, "No reading list oauth token to forget!");
-        }
       } 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();
         } catch (ClassCastException e) {
--- a/mobile/android/base/fxa/authenticator/AndroidFxAccount.java
+++ b/mobile/android/base/fxa/authenticator/AndroidFxAccount.java
@@ -56,37 +56,26 @@ public class AndroidFxAccount {
   public static final int CURRENT_ACCOUNT_VERSION = 3;
   public static final String ACCOUNT_KEY_ACCOUNT_VERSION = "version";
   public static final String ACCOUNT_KEY_PROFILE = "profile";
   public static final String ACCOUNT_KEY_IDP_SERVER = "idpServerURI";
 
   public static final String ACCOUNT_KEY_TOKEN_SERVER = "tokenServerURI";       // Sync-specific.
   public static final String ACCOUNT_KEY_DESCRIPTOR = "descriptor";
 
-  // The set of authorities to sync automatically changes over time. The first
-  // new authority is the Reading List. This tracks if we've enabled syncing,
-  // and opted in (or out) of syncing automatically, for the new Reading List
-  // authority. This happens either on when the account is created or when
-  // upgrading.
-  public static final String ACCOUNT_KEY_READING_LIST_AUTHORITY_INITIALIZED = "readingListAuthorityInitialized";
-
   public static final int CURRENT_BUNDLE_VERSION = 2;
   public static final String BUNDLE_KEY_BUNDLE_VERSION = "version";
   public static final String BUNDLE_KEY_STATE_LABEL = "stateLabel";
   public static final String BUNDLE_KEY_STATE = "state";
 
   public static final Map<String, Boolean> DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP;
   static {
     final HashMap<String, Boolean> m = new HashMap<String, Boolean>();
     // By default, Firefox Sync is enabled.
     m.put(BrowserContract.AUTHORITY, true);
-    if (AppConstants.MOZ_ANDROID_READING_LIST_SERVICE) {
-      // Sync the Reading List.
-      m.put(BrowserContract.READING_LIST_AUTHORITY, true);
-    }
     DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP = Collections.unmodifiableMap(m);
   }
 
   private static final String PREF_KEY_LAST_SYNCED_TIMESTAMP = "lastSyncedTimestamp";
 
   protected final Context context;
   protected final AccountManager accountManager;
   protected final Account account;
@@ -401,20 +390,16 @@ public class AndroidFxAccount {
 
     // Android has internal restrictions that require all values in this
     // bundle to be strings. *sigh*
     Bundle userdata = new Bundle();
     userdata.putString(ACCOUNT_KEY_ACCOUNT_VERSION, "" + CURRENT_ACCOUNT_VERSION);
     userdata.putString(ACCOUNT_KEY_IDP_SERVER, idpServerURI);
     userdata.putString(ACCOUNT_KEY_TOKEN_SERVER, tokenServerURI);
     userdata.putString(ACCOUNT_KEY_PROFILE, profile);
-    if (DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.containsKey(BrowserContract.READING_LIST_AUTHORITY)) {
-      // Have we initialized the Reading List authority?
-      userdata.putString(ACCOUNT_KEY_READING_LIST_AUTHORITY_INITIALIZED, "1");
-    }
 
     if (bundle == null) {
       bundle = new ExtendedJSONObject();
       // TODO: How to upgrade?
       bundle.put(BUNDLE_KEY_BUNDLE_VERSION, CURRENT_BUNDLE_VERSION);
     }
     bundle.put(BUNDLE_KEY_STATE_LABEL, state.getStateLabel().name());
     bundle.put(BUNDLE_KEY_STATE, state.toJSONObject().toJSONString());
--- a/mobile/android/base/fxa/receivers/FxAccountUpgradeReceiver.java
+++ b/mobile/android/base/fxa/receivers/FxAccountUpgradeReceiver.java
@@ -6,28 +6,25 @@ package org.mozilla.gecko.fxa.receivers;
 
 import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountUtils;
-import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.fxa.login.State;
 import org.mozilla.gecko.fxa.login.State.StateLabel;
 import org.mozilla.gecko.sync.Utils;
 
 import android.accounts.Account;
-import android.accounts.AccountManager;
 import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 
 /**
  * A receiver that takes action when our Android package is upgraded (replaced).
  */
 public class FxAccountUpgradeReceiver extends BroadcastReceiver {
   private static final String LOG_TAG = FxAccountUpgradeReceiver.class.getSimpleName();
@@ -43,17 +40,16 @@ public class FxAccountUpgradeReceiver ex
    * @return list of Runnable instances.
    */
   protected List<Runnable> onUpgradeRunnables(Context context) {
     List<Runnable> runnables = new LinkedList<Runnable>();
     runnables.add(new MaybeUnpickleRunnable(context));
     // Recovering accounts that are in the Doghouse should happen *after* we
     // unpickle any accounts saved to disk.
     runnables.add(new AdvanceFromDoghouseRunnable(context));
-    runnables.add(new MaybeInitializeReadingListAuthority(context));
     return runnables;
   }
 
   @Override
   public void onReceive(final Context context, Intent intent) {
     Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG);
     Logger.info(LOG_TAG, "Upgrade broadcast received.");
 
@@ -129,73 +125,9 @@ public class FxAccountUpgradeReceiver ex
           fxAccount.setState(state.makeSeparatedState());
         } catch (Exception e) {
           Logger.warn(LOG_TAG, "Got exception trying to advance account named like " + Utils.obfuscateEmail(account.name) +
               " from Doghouse to Separated state; ignoring.", e);
         }
       }
     }
   }
-
-  /**
-   * A Runnable that initializes the Reading List authority (specifically, set
-   * the sync automatically flag) for existing Firefox Accounts that have not
-   * yet seen the authority. That is, if a new authority (Reading List) is added
-   * to the set of defaults, existing Firefox Accounts won't be syncing it
-   * automatically. This tries to set the sync automatically flag for such
-   * existing accounts.
-   *
-   * Public for testing only.
-   */
-  public static class MaybeInitializeReadingListAuthority implements Runnable {
-    protected final Context context;
-
-    public MaybeInitializeReadingListAuthority(Context context) {
-      this.context = context;
-    }
-
-    @Override
-    public void run() {
-      final String authority = BrowserContract.READING_LIST_AUTHORITY;
-      Boolean enabledByDefault = AndroidFxAccount.DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.get(authority);
-      if (enabledByDefault == null || !enabledByDefault.booleanValue()) {
-        Logger.info(LOG_TAG, "Reading List authority is not enabled by default; not trying to initialize Reading List authority for any accounts.");
-      }
-
-      final AccountManager accountManager = AccountManager.get(context);
-      final Account[] accounts = FirefoxAccounts.getFirefoxAccounts(context);
-      Logger.info(LOG_TAG, "Trying to initialize Reading List authority for " + accounts.length + " existing Firefox Accounts (if necessary).");
-
-      for (Account account : accounts) {
-        try {
-          final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
-          // For great debugging.
-          if (FxAccountUtils.LOG_PERSONAL_INFORMATION) {
-            fxAccount.dump();
-          }
-
-          final boolean readingListAuthorityInitialized =
-              "1".equals(accountManager.getUserData(account, AndroidFxAccount.ACCOUNT_KEY_READING_LIST_AUTHORITY_INITIALIZED));
-          if (readingListAuthorityInitialized) {
-            Logger.debug(LOG_TAG, "Reading List authority has already been initialized.");
-            continue;
-          }
-
-          // The Reading List authority has not been seen. This happens when an
-          // authority is added after the Firefox Account has been added (and
-          // the package last upgraded). If Firefox Sync is not syncing
-          // automatically, Reading List should not start syncing
-          // automatically: the user has elected not to upload data to Mozilla
-          // servers; we shouldn't opt them in.
-          final boolean syncAutomatically = ContentResolver.getSyncAutomatically(account, BrowserContract.AUTHORITY);
-            Logger.debug(LOG_TAG, "Setting Reading List authority " +
-                (syncAutomatically ? " to " : " to not ") + "sync automatically.");
-            ContentResolver.setSyncAutomatically(account, BrowserContract.READING_LIST_AUTHORITY, syncAutomatically);
-          // Update the account record.
-          accountManager.setUserData(account, AndroidFxAccount.ACCOUNT_KEY_READING_LIST_AUTHORITY_INITIALIZED, "1");
-        } catch (Exception e) {
-          Logger.warn(LOG_TAG, "Got exception trying to set authoritities to sync automatically for account named like " +
-              Utils.obfuscateEmail(account.name) + "; ignoring.", e);
-        }
-      }
-    }
-  }
 }
--- a/mobile/android/base/resources/xml/fxaccount_status_prefscreen.xml
+++ b/mobile/android/base/resources/xml/fxaccount_status_prefscreen.xml
@@ -74,20 +74,16 @@
         <CheckBoxPreference
             android:key="tabs"
             android:persistent="false"
             android:title="@string/fxaccount_status_tabs" />
         <CheckBoxPreference
             android:key="passwords"
             android:persistent="false"
             android:title="@string/fxaccount_status_passwords" />
-        <CheckBoxPreference
-            android:key="reading_list"
-            android:persistent="false"
-            android:title="@string/fxaccount_status_reading_list" />
 
         <EditTextPreference
             android:singleLine="true"
             android:key="device_name"
             android:persistent="false"
             android:title="@string/fxaccount_status_device_name" />
 
         <Preference
@@ -122,17 +118,16 @@
         </Preference>
     </PreferenceCategory>
     <PreferenceCategory
         android:key="debug_category" >
         <Preference android:key="debug_refresh" />
         <Preference android:key="debug_dump" />
         <Preference android:key="debug_force_sync" />
         <Preference android:key="debug_invalidate_certificate" />
-        <Preference android:key="debug_forget_reading_list_oauth_token" />
         <Preference android:key="debug_forget_certificate" />
         <Preference android:key="debug_require_password" />
         <Preference android:key="debug_require_upgrade" />
         <Preference android:key="debug_migrated_from_sync11" />
         <Preference android:key="debug_make_account_stage" />
         <Preference android:key="debug_make_account_default" />
 	</PreferenceCategory>
 
--- a/mobile/android/services/manifests/FxAccountAndroidManifest_services.xml.in
+++ b/mobile/android/services/manifests/FxAccountAndroidManifest_services.xml.in
@@ -21,24 +21,9 @@
             android:name="org.mozilla.gecko.fxa.sync.FxAccountSyncService" >
             <intent-filter >
                 <action android:name="android.content.SyncAdapter" />
             </intent-filter>
 
             <meta-data
                 android:name="android.content.SyncAdapter"
                 android:resource="@xml/fxaccount_syncadapter" />
-        </service>
-
-        <!-- Reading List. -->
-#ifdef MOZ_ANDROID_READING_LIST_SERVICE
-        <service
-            android:exported="false"
-            android:name="org.mozilla.gecko.reading.ReadingListSyncService" >
-            <intent-filter >
-                <action android:name="android.content.SyncAdapter" />
-            </intent-filter>
-
-            <meta-data
-                android:name="android.content.SyncAdapter"
-                android:resource="@xml/readinglist_syncadapter" />
-        </service>
-#endif
+        </service>
\ No newline at end of file