Bug 1220906 - Part 3: Remove references to SyncAccounts and SyncConstants.ACCOUNTTYPE_SYNC outside of *.sync.*. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Mon, 18 Jan 2016 15:36:55 -0800
changeset 323654 b6aea26e42fb3f98797dfeb5b83737a62a992fdf
parent 323653 75423ef3ac7719f7e5557974c3ad5ec725319059
child 323655 b9a94252738efc8c9964366ec14e5f8cdb91f8ad
push id9762
push usermozilla@noorenberghe.ca
push dateWed, 20 Jan 2016 21:31:00 +0000
reviewersrnewman
bugs1220906
milestone46.0a1
Bug 1220906 - Part 3: Remove references to SyncAccounts and SyncConstants.ACCOUNTTYPE_SYNC outside of *.sync.*. r=rnewman
mobile/android/base/java/org/mozilla/gecko/home/RemoteTabsPanel.java
mobile/android/base/java/org/mozilla/gecko/overlays/service/sharemethods/SendTab.java
mobile/android/base/java/org/mozilla/gecko/preferences/SyncPreference.java
mobile/android/base/java/org/mozilla/gecko/widget/ActivityChooserModel.java
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/AccountLoader.java
mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/RemoteTabsPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RemoteTabsPanel.java
@@ -144,20 +144,16 @@ public class RemoteTabsPanel extends Hom
      * @param account
      *            Android Account (Sync or Firefox); may be null.
      */
     private Action getActionNeeded(Account account) {
         if (account == null) {
             return null;
         }
 
-        if (SyncConstants.ACCOUNTTYPE_SYNC.equals(account.type)) {
-            return Action.None;
-        }
-
         if (!FxAccountConstants.ACCOUNT_TYPE.equals(account.type)) {
             Log.wtf(LOGTAG, "Non Sync, non Firefox Android Account returned by AccountLoader; returning null.");
             return null;
         }
 
         final State state = FirefoxAccounts.getFirefoxAccountState(getActivity());
         if (state == null) {
             Log.wtf(LOGTAG, "Firefox Account with null state found; offering needs password.");
--- 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
@@ -9,34 +9,31 @@ import android.accounts.AccountManager;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.os.Parcelable;
 import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
+
 import org.mozilla.gecko.GeckoProfile;
-import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.RemoteClient;
 import org.mozilla.gecko.db.TabsAccessor;
 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.overlays.OverlayConstants;
 import org.mozilla.gecko.overlays.service.ShareData;
 import org.mozilla.gecko.sync.CommandProcessor;
 import org.mozilla.gecko.sync.CommandRunner;
 import org.mozilla.gecko.sync.GlobalSession;
 import org.mozilla.gecko.sync.SyncConfiguration;
-import org.mozilla.gecko.sync.SyncConstants;
-import org.mozilla.gecko.sync.setup.SyncAccounts;
-import org.mozilla.gecko.sync.syncadapter.SyncAdapter;
 
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -163,27 +160,16 @@ public class SendTab extends ShareMethod
 
             updateClientList(tabSender);
 
             Log.i(LOGTAG, "Allowing tab send for Firefox Account.");
             registerDisplayURICommand();
             return;
         }
 
-        final Account[] syncAccounts = accountManager.getAccountsByType(SyncConstants.ACCOUNTTYPE_SYNC);
-        if (syncAccounts.length > 0) {
-            tabSender = new Sync11TabSender(context, syncAccounts[0], accountManager);
-
-            updateClientList(tabSender);
-
-            Log.i(LOGTAG, "Allowing tab send for Sync account.");
-            registerDisplayURICommand();
-            return;
-        }
-
         // Have registered UIs offer to set up a Firefox Account.
         setOverrideIntentAction(FxAccountConstants.ACTION_FXA_GET_STARTED);
     }
 
     /**
      * Load the list of Sync clients that are not this device using the given TabSender.
      */
     private void updateClientList(TabSender tabSender) {
@@ -303,37 +289,9 @@ public class SendTab extends ShareMethod
             }
         }
 
         @Override
         public void sync() {
             fxAccount.requestSync(FirefoxAccounts.FORCE, STAGES_TO_SYNC, null);
         }
     }
-
-    private static class Sync11TabSender implements TabSender {
-        private final Account account;
-        private final AccountManager accountManager;
-        private final Context context;
-
-        private Sync11TabSender(Context aContext, Account syncAccount, AccountManager manager) {
-            context = aContext;
-            account = syncAccount;
-            accountManager = manager;
-        }
-
-        @Override
-        public String getAccountGUID() {
-            try {
-                SharedPreferences prefs = SyncAccounts.blockingPrefsFromDefaultProfileV0(context, accountManager, account);
-                return prefs.getString(SyncConfiguration.PREF_ACCOUNT_GUID, null);
-            } catch (Exception e) {
-                Log.w(LOGTAG, "Could not get Sync account parameters or preferences; aborting.");
-                return null;
-            }
-        }
-
-        @Override
-        public void sync() {
-            SyncAdapter.requestImmediateSync(account, STAGES_TO_SYNC);
-        }
-    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/SyncPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/SyncPreference.java
@@ -1,67 +1,47 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.preferences;
 
-import android.accounts.Account;
 import android.content.Context;
 import android.content.Intent;
 import android.preference.Preference;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.view.View;
-import android.widget.TextView;
 
 import com.squareup.picasso.Picasso;
 import com.squareup.picasso.Target;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
-import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.activities.FxAccountWebFlowActivity;
 import org.mozilla.gecko.fxa.activities.PicassoPreferenceIconTarget;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
-import org.mozilla.gecko.sync.setup.SyncAccounts;
-import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
 import org.mozilla.gecko.util.ThreadUtils;
 
 class SyncPreference extends Preference {
-    private static final boolean DEFAULT_TO_FXA = true;
-
     private final Context mContext;
     private final Target profileAvatarTarget;
 
     public SyncPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
         final float cornerRadius = mContext.getResources().getDimension(R.dimen.fxaccount_profile_image_width) / 2;
         profileAvatarTarget = new PicassoPreferenceIconTarget(mContext.getResources(), this, cornerRadius);
     }
 
-    private void openSync11Settings() {
-        // Show Sync setup if no accounts exist; otherwise, show account settings.
-        if (SyncAccounts.syncAccountsExist(mContext)) {
-            // We don't check for failure here. If you already have Sync set up,
-            // then there's nothing we can do.
-            SyncAccounts.openSyncSettings(mContext);
-            return;
-        }
-        Intent intent = new Intent(mContext, SetupSyncActivity.class);
-        mContext.startActivity(intent);
-    }
-
     private void launchFxASetup() {
         final Intent intent = new Intent(FxAccountConstants.ACTION_FXA_GET_STARTED);
         intent.putExtra(FxAccountWebFlowActivity.EXTRA_ENDPOINT, FxAccountConstants.ENDPOINT_PREFERENCES);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
         mContext.startActivity(intent);
     }
 
@@ -115,29 +95,14 @@ class SyncPreference extends Preference 
                 .resizeDimen(R.dimen.fxaccount_profile_image_width, R.dimen.fxaccount_profile_image_height)
                 .placeholder(R.drawable.sync_avatar_default)
                 .error(R.drawable.sync_avatar_default)
                 .into(profileAvatarTarget);
     }
 
     @Override
     protected void onClick() {
-        // If we're not defaulting to FxA, just do what we've always done.
-        if (!DEFAULT_TO_FXA) {
-            openSync11Settings();
-            return;
-        }
-
-        // If there's a legacy Sync account (or a pickled one on disk),
-        // open the settings page.
-        if (SyncAccounts.syncAccountsExist(mContext)) {
-            if (SyncAccounts.openSyncSettings(mContext) != null) {
-                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, "sync_settings");
-                return;
-            }
-        }
-
-        // Otherwise, launch the FxA "Get started" activity, which will
-        // dispatch to the right location.
+        // Launch the FxA "Get started" activity, which will dispatch to the
+        // right location.
         launchFxASetup();
         Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, "sync_setup");
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/widget/ActivityChooserModel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/ActivityChooserModel.java
@@ -1305,18 +1305,17 @@ public class ActivityChooserModel extend
     }
 
     /**
      * Mozilla: Return whether or not there are other synced clients.
      */
     private boolean hasOtherSyncClients() {
         // ClientsDatabaseAccessor returns stale data (bug 1145896) so we work around this by
         // checking if we have accounts set up - if not, we can't have any clients.
-        if (!FirefoxAccounts.firefoxAccountsExist(mContext) &&
-                !SyncAccounts.syncAccountsExist(mContext))  {
+        if (!FirefoxAccounts.firefoxAccountsExist(mContext)) {
             return false;
         }
 
         final BrowserDB browserDB = GeckoProfile.get(mContext).getDB();
         final TabsAccessor tabsAccessor = browserDB.getTabsAccessor();
         final Cursor remoteClientsCursor = tabsAccessor
                 .getRemoteClientsByRecencyCursor(mContext);
         if (remoteClientsCursor == null) {
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/AccountLoader.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/AccountLoader.java
@@ -35,28 +35,20 @@ import android.support.v4.content.AsyncT
 public class AccountLoader extends AsyncTaskLoader<Account> {
   protected Account account = null;
   protected BroadcastReceiver broadcastReceiver = null;
 
   public AccountLoader(Context context) {
     super(context);
   }
 
-  // Task that performs the asynchronous load **/
+  // Task that performs the asynchronous load.
   @Override
   public Account loadInBackground() {
-    final Context context = getContext();
-    Account foundAccount = FirefoxAccounts.getFirefoxAccount(context);
-    if (foundAccount == null) {
-      final Account[] syncAccounts = SyncAccounts.syncAccounts(context);
-      if (syncAccounts != null && syncAccounts.length > 0) {
-        foundAccount = syncAccounts[0];
-      }
-    }
-    return foundAccount;
+    return FirefoxAccounts.getFirefoxAccount(getContext());
   }
 
   // Deliver the results to the registered listener.
   @Override
   public void deliverResult(Account data) {
     if (isReset()) {
       // The Loader has been reset; ignore the result and invalidate the data.
       releaseResources(data);
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java
+++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java
@@ -11,43 +11,39 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License
  */
 
 package org.mozilla.gecko.background.fxa;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.security.GeneralSecurityException;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.mozilla.gecko.background.sync.AndroidSyncTestCaseWithAccounts;
-import org.mozilla.gecko.background.sync.TestSyncAccounts;
-import org.mozilla.gecko.fxa.AccountLoader;
-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.Separated;
-import org.mozilla.gecko.fxa.login.State;
-import org.mozilla.gecko.sync.SyncConstants;
-import org.mozilla.gecko.sync.setup.SyncAccounts;
-import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
-
 import android.accounts.Account;
 import android.content.Context;
 import android.os.AsyncTask;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
 import android.support.v4.content.Loader;
 import android.support.v4.content.Loader.OnLoadCompleteListener;
 
+import org.mozilla.gecko.background.sync.AndroidSyncTestCaseWithAccounts;
+import org.mozilla.gecko.fxa.AccountLoader;
+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.Separated;
+import org.mozilla.gecko.fxa.login.State;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.security.GeneralSecurityException;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.atomic.AtomicReference;
+
 /**
  * A version of https://android.googlesource.com/platform/frameworks/base/+/c91893511dc1b9e634648406c9ae61b15476e65d/test-runner/src/android/test/LoaderTestCase.java,
  * hacked to work with the v4 support library, and patched to work around
  * https://code.google.com/p/android/issues/detail?id=40987.
  */
 public class TestAccountLoader extends AndroidSyncTestCaseWithAccounts {
   // Test account names must start with TEST_USERNAME in order to be recognized
   // as test accounts and deleted in tearDown.
@@ -140,55 +136,29 @@ public class TestAccountLoader extends A
     // This is tricky. We can't mock the AccountManager easily -- see
     // https://groups.google.com/d/msg/android-mock/VXyzvKTMUGs/Y26wVPrl50sJ --
     // and we don't want to delete any existing accounts on device. So our test
     // needs to be adaptive (and therefore a little race-prone).
 
     final Context context = getApplicationContext();
     final AccountLoader loader = new AccountLoader(context);
 
-    final boolean syncAccountsExist = SyncAccounts.syncAccountsExist(context);
     final boolean firefoxAccountsExist = FirefoxAccounts.firefoxAccountsExist(context);
 
     if (firefoxAccountsExist) {
       assertFirefoxAccount(getLoaderResultSynchronously(loader));
       return;
     }
 
-    if (syncAccountsExist) {
-      assertSyncAccount(getLoaderResultSynchronously(loader));
-      return;
-    }
-
-    // This account will not get cleaned up in tearDown -- it's a Sync account,
-    // not a Firefox account -- so we must be careful.
-    Account syncAccount = null;
-    try {
-      final SyncAccountParameters syncAccountParameters =
-          new SyncAccountParameters(context, null, TEST_USERNAME, TEST_SYNCKEY, TEST_SYNCPASSWORD, null);
-      syncAccount = SyncAccounts.createSyncAccount(syncAccountParameters, false);
-      assertNotNull(syncAccount);
-      assertSyncAccount(getLoaderResultSynchronously(loader));
-    } finally {
-      if (syncAccount != null) {
-        TestSyncAccounts.deleteAccount(this, accountManager, syncAccount);
-      }
-    }
-
     // This account will get cleaned up in tearDown.
     final State state = new Separated(TEST_USERNAME, "uid", false); // State choice is arbitrary.
     final AndroidFxAccount account = AndroidFxAccount.addAndroidAccount(context,
         TEST_USERNAME, TEST_PROFILE, TEST_AUTH_SERVER_URI, TEST_TOKEN_SERVER_URI, TEST_PROFILE_SERVER_URI,
         state, AndroidSyncTestCaseWithAccounts.TEST_SYNC_AUTOMATICALLY_MAP_WITH_ALL_AUTHORITIES_DISABLED);
     assertNotNull(account);
     assertFirefoxAccount(getLoaderResultSynchronously(loader));
   }
 
   protected void assertFirefoxAccount(Account account) {
     assertNotNull(account);
     assertEquals(FxAccountConstants.ACCOUNT_TYPE, account.type);
   }
-
-  protected void assertSyncAccount(Account account) {
-    assertNotNull(account);
-    assertEquals(SyncConstants.ACCOUNTTYPE_SYNC, account.type);
-  }
 }