Rename Telecomm "Subscription" to "Account" (2/7)

Change-Id: I73cd3d1a2e7ae12f2e8d94f0a093c6d91bf7c912
diff --git a/src/com/android/contacts/common/CallUtil.java b/src/com/android/contacts/common/CallUtil.java
index 0d86bbe..87440e9 100644
--- a/src/com/android/contacts/common/CallUtil.java
+++ b/src/com/android/contacts/common/CallUtil.java
@@ -18,9 +18,8 @@
 
 import android.content.Intent;
 import android.net.Uri;
-import android.telecomm.Subscription;
+import android.telecomm.PhoneAccount;
 import android.telephony.TelephonyManager;
-import android.util.Log;
 
 import com.android.contacts.common.util.PhoneNumberHelper;
 import com.android.phone.common.PhoneConstants;
@@ -61,40 +60,40 @@
     }
 
     /**
-     * A variant of {@link #getCallIntent(String)} but also include {@code Subscription}.
+     * A variant of {@link #getCallIntent(String)} but also include {@code Account}.
      */
-    public static Intent getCallIntent(String number, Subscription subscription) {
-        return getCallIntent(number, null, subscription);
+    public static Intent getCallIntent(String number, PhoneAccount account) {
+        return getCallIntent(number, null, account);
     }
 
     /**
-     * A variant of {@link #getCallIntent(android.net.Uri)} but also include {@code Subscription}.
+     * A variant of {@link #getCallIntent(android.net.Uri)} but also include {@code Account}.
      */
-    public static Intent getCallIntent(Uri uri, Subscription subscription) {
-        return getCallIntent(uri, null, subscription);
+    public static Intent getCallIntent(Uri uri, PhoneAccount account) {
+        return getCallIntent(uri, null, account);
     }
 
     /**
-     * A variant of {@link #getCallIntent(String, String)} but also include {@code Subscription}.
+     * A variant of {@link #getCallIntent(String, String)} but also include {@code Account}.
      */
     public static Intent getCallIntent(String number, String callOrigin,
-            Subscription subscription) {
-        return getCallIntent(getCallUri(number), callOrigin, subscription);
+            PhoneAccount account) {
+        return getCallIntent(getCallUri(number), callOrigin, account);
     }
 
     /**
      * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call
-     * origin and {@code Subscription}.
+     * origin and {@code Account}.
      * For more information about call origin, see comments in Phone package (PhoneApp).
      */
-    public static Intent getCallIntent(Uri uri, String callOrigin, Subscription subscription) {
+    public static Intent getCallIntent(Uri uri, String callOrigin, PhoneAccount account) {
         final Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, uri);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         if (callOrigin != null) {
             intent.putExtra(PhoneConstants.EXTRA_CALL_ORIGIN, callOrigin);
         }
-        if (subscription != null) {
-            intent.putExtra(TelephonyManager.EXTRA_SUBSCRIPTION, subscription);
+        if (account != null) {
+            intent.putExtra(TelephonyManager.EXTRA_ACCOUNT, account);
         }
 
         return intent;
diff --git a/src/com/android/contacts/common/PhoneAccountManager.java b/src/com/android/contacts/common/PhoneAccountManager.java
new file mode 100644
index 0000000..c3d399f
--- /dev/null
+++ b/src/com/android/contacts/common/PhoneAccountManager.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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 com.android.contacts.common;
+
+import android.telecomm.PhoneAccount;
+import android.telephony.TelephonyManager;
+
+import java.util.List;
+
+/**
+ * To pass current account information between activities/fragments.
+ */
+public class PhoneAccountManager {
+    private PhoneAccount mCurrentAccount = null;
+    private TelephonyManager mTelephonyManager;
+
+    public PhoneAccountManager(TelephonyManager telephonyManager, PhoneAccount account) {
+        mTelephonyManager = telephonyManager;
+        mCurrentAccount = account;
+    }
+
+    public PhoneAccountManager(TelephonyManager telephonyManager) {
+        mTelephonyManager = telephonyManager;
+    }
+
+    public PhoneAccount getCurrentAccount() {
+        return mCurrentAccount;
+    }
+
+    public void setCurrentAccount(PhoneAccount account) {
+        mCurrentAccount = account;
+    }
+
+    public List<PhoneAccount> getAccounts() {
+        return mTelephonyManager.getAccounts();
+    }
+}
diff --git a/src/com/android/contacts/common/SubscriptionManager.java b/src/com/android/contacts/common/SubscriptionManager.java
deleted file mode 100644
index 95c0e0d..0000000
--- a/src/com/android/contacts/common/SubscriptionManager.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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 com.android.contacts.common;
-
-import android.telecomm.Subscription;
-import android.telephony.TelephonyManager;
-
-import java.util.List;
-
-/**
- * To pass current subscription information between activities/fragments.
- */
-public class SubscriptionManager {
-    private Subscription mCurrentSubscription = null;
-    private TelephonyManager mTelephonyManager;
-
-    public SubscriptionManager(TelephonyManager telephonyManager, Subscription subscription) {
-        mTelephonyManager = telephonyManager;
-        mCurrentSubscription = subscription;
-    }
-
-    public SubscriptionManager(TelephonyManager telephonyManager) {
-        mTelephonyManager = telephonyManager;
-    }
-
-    public Subscription getCurrentSubscription() {
-        return mCurrentSubscription;
-    }
-
-    public void setCurrentSubscription(Subscription subscription) {
-        mCurrentSubscription = subscription;
-    }
-
-    public List<Subscription> getSubscriptions() {
-        return mTelephonyManager.getSubscriptions();
-    }
-}
diff --git a/src/com/android/contacts/common/dialog/SelectSubscriptionDialogFragment.java b/src/com/android/contacts/common/dialog/SelectAccountDialogFragment.java
similarity index 62%
rename from src/com/android/contacts/common/dialog/SelectSubscriptionDialogFragment.java
rename to src/com/android/contacts/common/dialog/SelectAccountDialogFragment.java
index d7ecb03..5fdeba2 100644
--- a/src/com/android/contacts/common/dialog/SelectSubscriptionDialogFragment.java
+++ b/src/com/android/contacts/common/dialog/SelectAccountDialogFragment.java
@@ -23,10 +23,10 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.os.Bundle;
-import android.telecomm.Subscription;
+import android.telecomm.PhoneAccount;
 
+import com.android.contacts.common.PhoneAccountManager;
 import com.android.contacts.common.R;
-import com.android.contacts.common.SubscriptionManager;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -35,23 +35,23 @@
 /**
  * Dialog that allows the user to switch between default SIM cards
  */
-public class SelectSubscriptionDialogFragment extends DialogFragment {
-    private SubscriptionManager mSubscriptionManager;
+public class SelectAccountDialogFragment extends DialogFragment {
+    private PhoneAccountManager mAccountManager;
     private int mSelection;
-    private List<Subscription> mSubscriptions;
+    private List<PhoneAccount> mAccounts;
     private static final int NO_SELECTION = -1;
 
     /* Preferred way to show this dialog */
     public static void show(FragmentManager fragmentManager,
-            SubscriptionManager subscriptionManager) {
-        SelectSubscriptionDialogFragment fragment = new SelectSubscriptionDialogFragment();
-        fragment.mSubscriptionManager = subscriptionManager;
-        fragment.show(fragmentManager, "selectSubscription");
+            PhoneAccountManager accountManager) {
+        SelectAccountDialogFragment fragment = new SelectAccountDialogFragment();
+        fragment.mAccountManager = accountManager;
+        fragment.show(fragmentManager, "selectAccount");
     }
 
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
-        mSubscriptions = mSubscriptionManager.getSubscriptions();
+        mAccounts = mAccountManager.getAccounts();
         mSelection = NO_SELECTION;
 
         final DialogInterface.OnClickListener selectionListener =
@@ -66,49 +66,49 @@
             @Override
             public void onClick(DialogInterface dialog, int id) {
                 if (mSelection != NO_SELECTION) {
-                    // No need to update the current subscription if it has not been changed
-                    mSubscriptionManager.setCurrentSubscription(mSubscriptions.get(mSelection));
+                    // No need to update the current account if it has not been changed
+                    mAccountManager.setCurrentAccount(mAccounts.get(mSelection));
                 }
             }
         };
 
-        CharSequence[] names = getSubscriptionNames();
+        CharSequence[] names = getAccountNames();
         return new AlertDialog.Builder(getActivity())
                 .setTitle(R.string.menu_select_sim)
-                .setSingleChoiceItems(names, getSelectedSubscriptionIndex(names), selectionListener)
+                .setSingleChoiceItems(names, getSelectedAccountIndex(names), selectionListener)
                 .setPositiveButton(android.R.string.ok, okListener)
                 .setNegativeButton(android.R.string.cancel, null)
                 .create();
     }
 
     /**
-     * Helper function to extract the index of the currently selected subscription.
+     * Helper function to extract the index of the currently selected account.
      * Used in the dialog as the initially selected radio button.
      *
      * @param activeSubs String list of the labels referring to each of possible
-     *         active subscriptions to choose from
-     * @return the index of the selected subscription in the array of subscriptions
+     *         active accounts to choose from
+     * @return the index of the selected account in the array of accounts
      */
-    private int getSelectedSubscriptionIndex(CharSequence[] activeSubs) {
-        Subscription initialSubscription = mSubscriptionManager.getCurrentSubscription();
-        if (initialSubscription == null) {
+    private int getSelectedAccountIndex(CharSequence[] activeSubs) {
+        PhoneAccount initialAccount = mAccountManager.getCurrentAccount();
+        if (initialAccount == null) {
             return -1;
         }
         else {
-            return Arrays.asList(activeSubs).indexOf(initialSubscription.getLabel(getActivity()));
+            return Arrays.asList(activeSubs).indexOf(initialAccount.getLabel(getActivity()));
         }
     }
 
     /**
-     * Extracts the label names from each of the subscriptions and returns as a list of strings
+     * Extracts the label names from each of the accounts and returns as a list of strings
      *
      * @return a list of strings to display in the dialog
      */
-    private CharSequence[] getSubscriptionNames() {
+    private CharSequence[] getAccountNames() {
         Context context = getActivity();
         List<String> strings = new ArrayList<String>();
-        for (int i = 0; i < mSubscriptions.size(); i++) {
-            strings.add(mSubscriptions.get(i).getLabel(context));
+        for (int i = 0; i < mAccounts.size(); i++) {
+            strings.add(mAccounts.get(i).getLabel(context));
         }
         return strings.toArray(new CharSequence[strings.size()]);
     }
diff --git a/src/com/android/contacts/common/model/AccountTypeManager.java b/src/com/android/contacts/common/model/AccountTypeManager.java
index 7287880..8da0912 100644
--- a/src/com/android/contacts/common/model/AccountTypeManager.java
+++ b/src/com/android/contacts/common/model/AccountTypeManager.java
@@ -17,7 +17,7 @@
 package com.android.contacts.common.model;
 
 import android.accounts.Account;
-import android.accounts.AccountManager;
+import android.accounts.PhoneAccountManager;
 import android.accounts.AuthenticatorDescription;
 import android.accounts.OnAccountsUpdateListener;
 import android.content.BroadcastReceiver;
@@ -35,7 +35,6 @@
 import android.os.HandlerThread;
 import android.os.Looper;
 import android.os.Message;
-import android.os.RemoteException;
 import android.os.SystemClock;
 import android.provider.ContactsContract;
 import android.text.TextUtils;
@@ -192,7 +191,7 @@
             1, "xxx");
 
     private Context mContext;
-    private AccountManager mAccountManager;
+    private PhoneAccountManager mPhoneAccountManager;
 
     private AccountType mFallbackAccountType;
 
@@ -290,7 +289,7 @@
         mContext = context;
         mFallbackAccountType = new FallbackAccountType(context);
 
-        mAccountManager = AccountManager.get(mContext);
+        mPhoneAccountManager = PhoneAccountManager.get(mContext);
 
         mListenerThread = new HandlerThread("AccountChangeListener");
         mListenerThread.start();
@@ -326,7 +325,7 @@
         filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
         mContext.registerReceiver(mBroadcastReceiver, filter);
 
-        mAccountManager.addOnAccountsUpdatedListener(this, mListenerHandler, false);
+        mPhoneAccountManager.addOnAccountsUpdatedListener(this, mListenerHandler, false);
 
         ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this);
 
@@ -393,7 +392,7 @@
         final List<AccountWithDataSet> groupWritableAccounts = Lists.newArrayList();
         final Set<String> extensionPackages = Sets.newHashSet();
 
-        final AccountManager am = mAccountManager;
+        final PhoneAccountManager am = mPhoneAccountManager;
 
         final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
         final AuthenticatorDescription[] auths = am.getAuthenticatorTypes();
@@ -476,7 +475,7 @@
         timings.addSplit("Loaded account types");
 
         // Map in accounts to associate the account names with each account type entry.
-        Account[] accounts = mAccountManager.getAccounts();
+        Account[] accounts = mPhoneAccountManager.getAccounts();
         for (Account account : accounts) {
             boolean syncable =
                 ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0;
diff --git a/src/com/android/contacts/common/util/LocalizedNameResolver.java b/src/com/android/contacts/common/util/LocalizedNameResolver.java
index 3c21946..7187f39 100644
--- a/src/com/android/contacts/common/util/LocalizedNameResolver.java
+++ b/src/com/android/contacts/common/util/LocalizedNameResolver.java
@@ -16,7 +16,7 @@
 
 package com.android.contacts.common.util;
 
-import android.accounts.AccountManager;
+import android.accounts.PhoneAccountManager;
 import android.accounts.AuthenticatorDescription;
 import android.content.Context;
 import android.content.pm.PackageInfo;
@@ -66,7 +66,7 @@
      * Finds "All Contacts"-Name for the specified account type.
      */
     private static String resolveAllContactsName(Context context, String accountType) {
-        final AccountManager am = AccountManager.get(context);
+        final PhoneAccountManager am = PhoneAccountManager.get(context);
 
         for (AuthenticatorDescription auth : am.getAuthenticatorTypes()) {
             if (accountType.equals(auth.type)) {
diff --git a/tests/src/com/android/contacts/common/tests/testauth/TestAuthenticator.java b/tests/src/com/android/contacts/common/tests/testauth/TestAuthenticator.java
index 2f676c7..e6a47cd 100644
--- a/tests/src/com/android/contacts/common/tests/testauth/TestAuthenticator.java
+++ b/tests/src/com/android/contacts/common/tests/testauth/TestAuthenticator.java
@@ -19,7 +19,7 @@
 import android.accounts.AbstractAccountAuthenticator;
 import android.accounts.Account;
 import android.accounts.AccountAuthenticatorResponse;
-import android.accounts.AccountManager;
+import android.accounts.PhoneAccountManager;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Bundle;
@@ -67,11 +67,11 @@
         final Account account = new Account(newUniqueUserName(), accountType);
 
         // Create an account.
-        AccountManager.get(mContext).addAccountExplicitly(account, PASSWORD, null);
+        PhoneAccountManager.get(mContext).addAccountExplicitly(account, PASSWORD, null);
 
         // And return it.
-        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
-        bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
+        bundle.putString(PhoneAccountManager.KEY_ACCOUNT_NAME, account.name);
+        bundle.putString(PhoneAccountManager.KEY_ACCOUNT_TYPE, account.type);
         return bundle;
     }
 
@@ -83,9 +83,9 @@
             String authTokenType, Bundle loginOptions) {
         Log.v(TestauthConstants.LOG_TAG, "getAuthToken() account=" + account);
         final Bundle bundle = new Bundle();
-        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
-        bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
-        bundle.putString(AccountManager.KEY_AUTHTOKEN, account.name);
+        bundle.putString(PhoneAccountManager.KEY_ACCOUNT_NAME, account.name);
+        bundle.putString(PhoneAccountManager.KEY_ACCOUNT_TYPE, account.type);
+        bundle.putString(PhoneAccountManager.KEY_AUTHTOKEN, account.name);
 
         return bundle;
     }
@@ -118,7 +118,7 @@
         // return false (no) for any queries.
         Log.v(TestauthConstants.LOG_TAG, "hasFeatures()");
         final Bundle result = new Bundle();
-        result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
+        result.putBoolean(PhoneAccountManager.KEY_BOOLEAN_RESULT, false);
         return result;
     }
 
diff --git a/tests/src/com/android/contacts/common/tests/testauth/TestSyncAdapter.java b/tests/src/com/android/contacts/common/tests/testauth/TestSyncAdapter.java
index a7c0f83..f0186d9 100644
--- a/tests/src/com/android/contacts/common/tests/testauth/TestSyncAdapter.java
+++ b/tests/src/com/android/contacts/common/tests/testauth/TestSyncAdapter.java
@@ -16,7 +16,7 @@
 package com.android.contacts.common.tests.testauth;
 
 import android.accounts.Account;
-import android.accounts.AccountManager;
+import android.accounts.PhoneAccountManager;
 import android.content.AbstractThreadedSyncAdapter;
 import android.content.ContentProviderClient;
 import android.content.ContentResolver;
@@ -32,14 +32,14 @@
  *
  */
 public class TestSyncAdapter extends AbstractThreadedSyncAdapter {
-    private final AccountManager mAccountManager;
+    private final PhoneAccountManager mPhoneAccountManager;
 
     private final Context mContext;
 
     public TestSyncAdapter(Context context, boolean autoInitialize) {
         super(context, autoInitialize);
         mContext = context.getApplicationContext();
-        mAccountManager = AccountManager.get(mContext);
+        mPhoneAccountManager = PhoneAccountManager.get(mContext);
     }
 
     /**