Bug 962644 - Part 0: extract firefoxAccountsExist and friends. r=nalexander
authorRichard Newman <rnewman@mozilla.com>
Fri, 31 Jan 2014 16:02:42 -0800
changeset 182420 314d798aaa5d7545d9e11a8270be2cc10fad07c8
parent 182419 2a311162943f01c3bad5f6ee581f81a1ba298789
child 182421 b201ec3ca8e1a4427116df92cbd5ccfc24ed0a09
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs962644
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 962644 - Part 0: extract firefoxAccountsExist and friends. r=nalexander
mobile/android/base/android-services.mozbuild
mobile/android/base/fxa/FirefoxAccounts.java
mobile/android/base/fxa/activities/FxAccountAbstractActivity.java
mobile/android/base/fxa/activities/FxAccountGetStartedActivity.java
mobile/android/base/fxa/authenticator/FxAccountAuthenticator.java
--- a/mobile/android/base/android-services.mozbuild
+++ b/mobile/android/base/android-services.mozbuild
@@ -558,16 +558,17 @@ sync_java_files = [
     'fxa/activities/FxAccountStatusActivity.java',
     'fxa/activities/FxAccountUpdateCredentialsActivity.java',
     'fxa/activities/FxAccountVerifiedAccountActivity.java',
     'fxa/authenticator/AndroidFxAccount.java',
     'fxa/authenticator/FxAccountAuthenticator.java',
     'fxa/authenticator/FxAccountAuthenticatorService.java',
     'fxa/authenticator/FxAccountLoginDelegate.java',
     'fxa/authenticator/FxAccountLoginException.java',
+    'fxa/FirefoxAccounts.java',
     'fxa/login/BaseRequestDelegate.java',
     'fxa/login/Cohabiting.java',
     'fxa/login/Doghouse.java',
     'fxa/login/Engaged.java',
     'fxa/login/FxAccountLoginStateMachine.java',
     'fxa/login/FxAccountLoginTransition.java',
     'fxa/login/Married.java',
     'fxa/login/Separated.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/fxa/FirefoxAccounts.java
@@ -0,0 +1,46 @@
+/* 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.fxa;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.Context;
+
+/**
+ * Simple public accessors for Firefox account objects.
+ */
+public class FirefoxAccounts {
+  /**
+   * Return true if at least one Firefox account exists.
+   *
+   * @param context Android context.
+   * @return true if at least one Firefox account exists.
+   */
+  public static boolean firefoxAccountsExist(final Context context) {
+    return getFirefoxAccounts(context).length > 0;
+  }
+
+  /**
+   * Return Firefox accounts.
+   *
+   * @param context Android context.
+   * @return Firefox account objects.
+   */
+  public static Account[] getFirefoxAccounts(final Context context) {
+    return AccountManager.get(context).getAccountsByType(FxAccountConstants.ACCOUNT_TYPE);
+  }
+
+  /**
+   * @param context Android context.
+   * @return the configured Firefox account if one exists, or null otherwise.
+   */
+  public static Account getFirefoxAccount(final Context context) {
+    Account[] accounts = getFirefoxAccounts(context);
+    if (accounts.length > 0) {
+      return accounts[0];
+    }
+    return null;
+  }
+}
\ No newline at end of file
--- a/mobile/android/base/fxa/activities/FxAccountAbstractActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountAbstractActivity.java
@@ -1,18 +1,18 @@
 /* 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.fxa.activities;
 
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountAgeLockoutHelper;
+import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
-import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
 import org.mozilla.gecko.sync.setup.activities.ActivityUtils;
 
 import android.accounts.Account;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.SystemClock;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -40,22 +40,22 @@ public abstract class FxAccountAbstractA
   /**
    * Many Firefox Accounts activities shouldn't display if an account already
    * exists or if account creation is locked out due to an age verification
    * check failing (getting started, create account, sign in). This function
    * redirects as appropriate.
    */
   protected void redirectIfAppropriate() {
     if (cannotResumeWhenAccountsExist || cannotResumeWhenNoAccountsExist) {
-      Account accounts[] = FxAccountAuthenticator.getFirefoxAccounts(this);
-      if (cannotResumeWhenAccountsExist && accounts.length > 0) {
+      final Account account = FirefoxAccounts.getFirefoxAccount(this);
+      if (cannotResumeWhenAccountsExist && account != null) {
         redirectToActivity(FxAccountStatusActivity.class);
         return;
       }
-      if (cannotResumeWhenNoAccountsExist && accounts.length < 1) {
+      if (cannotResumeWhenNoAccountsExist && account == null) {
         redirectToActivity(FxAccountGetStartedActivity.class);
         return;
       }
     }
     if (cannotResumeWhenLockedOut) {
       if (FxAccountAgeLockoutHelper.isLockedOut(SystemClock.elapsedRealtime())) {
         this.setResult(RESULT_CANCELED);
         redirectToActivity(FxAccountCreateAccountNotAllowedActivity.class);
@@ -131,15 +131,15 @@ public abstract class FxAccountAbstractA
       }
     });
   }
 
   /**
    * Helper to fetch (unique) Android Firefox Account if one exists, or return null.
    */
   protected AndroidFxAccount getAndroidFxAccount() {
-    Account accounts[] = FxAccountAuthenticator.getFirefoxAccounts(this);
-    if (accounts.length < 1 || accounts[0] == null) {
+    Account account = FirefoxAccounts.getFirefoxAccount(this);
+    if (account == null) {
       return null;
     }
-    return new AndroidFxAccount(this, accounts[0]);
+    return new AndroidFxAccount(this, account);
   }
 }
--- a/mobile/android/base/fxa/activities/FxAccountGetStartedActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountGetStartedActivity.java
@@ -5,18 +5,18 @@
 package org.mozilla.gecko.fxa.activities;
 
 import java.util.Locale;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountAgeLockoutHelper;
+import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
-import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.setup.activities.ActivityUtils;
 
 import android.accounts.AccountAuthenticatorActivity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.SystemClock;
 import android.view.View;
@@ -59,17 +59,17 @@ public class FxAccountGetStartedActivity
 
   @Override
   public void onResume() {
     super.onResume();
 
     Intent intent = null;
     if (FxAccountAgeLockoutHelper.isLockedOut(SystemClock.elapsedRealtime())) {
       intent = new Intent(this, FxAccountCreateAccountNotAllowedActivity.class);
-    } else if (FxAccountAuthenticator.firefoxAccountsExist(this)) {
+    } else if (FirefoxAccounts.firefoxAccountsExist(this)) {
       intent = new Intent(this, FxAccountStatusActivity.class);
     }
     if (intent != null) {
       this.setAccountAuthenticatorResult(null);
       setResult(RESULT_CANCELED);
       // Per http://stackoverflow.com/a/8992365, this triggers a known bug with
       // the soft keyboard not being shown for the started activity. Why, Android, why?
       intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
--- a/mobile/android/base/fxa/authenticator/FxAccountAuthenticator.java
+++ b/mobile/android/base/fxa/authenticator/FxAccountAuthenticator.java
@@ -112,29 +112,9 @@ public class FxAccountAuthenticator exte
   @Override
   public Bundle updateCredentials(AccountAuthenticatorResponse response,
       Account account, String authTokenType, Bundle options)
           throws NetworkErrorException {
     Logger.debug(LOG_TAG, "updateCredentials");
 
     return null;
   }
-
-  /**
-   * Return Firefox Accounts.
-   *
-   * @param context Android context.
-   * @return Firefox Account objects.
-   */
-  public static Account[] getFirefoxAccounts(final Context context) {
-    return AccountManager.get(context).getAccountsByType(FxAccountConstants.ACCOUNT_TYPE);
-  }
-
-  /**
-   * Return true if at least one Firefox Account exists.
-   *
-   * @param context Android context.
-   * @return true if at least one Firefox Account exists.
-   */
-  public static boolean firefoxAccountsExist(final Context context) {
-    return getFirefoxAccounts(context).length > 0;
-  }
 }