Merge "Rename setDestroy() to destroy()" into lmp-dev
diff --git a/res/xml/phone_account_preferences.xml b/res/xml/phone_account_preferences.xml
index 7f12306..716afb2 100644
--- a/res/xml/phone_account_preferences.xml
+++ b/res/xml/phone_account_preferences.xml
@@ -14,7 +14,7 @@
      limitations under the License.
 -->
 
-<!-- Settings screen for selecting which PhoneAccount to use by default
+<!-- Settings screen for selecting which PhoneAccountHandle to use by default
      for making outgoing phone calls -->
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
      android:title="@string/phone_account_preferences_title">
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 0eeb21e..9cd5d6f 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -26,7 +26,7 @@
 import android.telecomm.CallState;
 import android.telecomm.ConnectionRequest;
 import android.telecomm.GatewayInfo;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.Response;
 import android.telecomm.StatusHints;
 import android.telephony.DisconnectCause;
@@ -175,7 +175,7 @@
      * service. */
     private final GatewayInfo mGatewayInfo;
 
-    private PhoneAccount mPhoneAccount;
+    private PhoneAccountHandle mPhoneAccountHandle;
 
     private final Handler mHandler = new Handler();
 
@@ -269,21 +269,21 @@
      *
      * @param handle The handle to dial.
      * @param gatewayInfo Gateway information to use for the call.
-     * @param account Account information to use for the call.
+     * @param accountHandle Account information to use for the call.
      * @param isIncoming True if this is an incoming call.
      */
     Call(
             ConnectionServiceRepository repository,
             Uri handle,
             GatewayInfo gatewayInfo,
-            PhoneAccount account,
+            PhoneAccountHandle accountHandle,
             boolean isIncoming,
             boolean isConference) {
         mState = isConference ? CallState.ACTIVE : CallState.NEW;
         mRepository = repository;
         setHandle(handle, CallPropertyPresentation.ALLOWED);
         mGatewayInfo = gatewayInfo;
-        mPhoneAccount = account;
+        mPhoneAccountHandle = accountHandle;
         mIsIncoming = isIncoming;
         mIsConference = isConference;
         maybeLoadCannedSmsResponses();
@@ -438,13 +438,13 @@
         return mGatewayInfo;
     }
 
-    PhoneAccount getPhoneAccount() {
-        return mPhoneAccount;
+    PhoneAccountHandle getPhoneAccount() {
+        return mPhoneAccountHandle;
     }
 
-    void setPhoneAccount(PhoneAccount account) {
-        if (!Objects.equals(mPhoneAccount, account)) {
-            mPhoneAccount = account;
+    void setPhoneAccount(PhoneAccountHandle accountHandle) {
+        if (!Objects.equals(mPhoneAccountHandle, accountHandle)) {
+            mPhoneAccountHandle = accountHandle;
             for (Listener l : mListeners) {
                 l.onPhoneAccountChanged(this);
             }
@@ -569,7 +569,7 @@
     @Override
     public void handleCreateConnectionSuccessful(ConnectionRequest request) {
         mCreateConnectionProcessor = null;
-        mPhoneAccount = request.getAccount();
+        mPhoneAccountHandle = request.getAccountHandle();
 
         if (mIsIncoming) {
             // We do not handle incoming calls immediately when they are verified by the connection
diff --git a/src/com/android/telecomm/CallActivity.java b/src/com/android/telecomm/CallActivity.java
index 04a9ff1..6e83173 100644
--- a/src/com/android/telecomm/CallActivity.java
+++ b/src/com/android/telecomm/CallActivity.java
@@ -20,7 +20,7 @@
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.os.Bundle;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
 
 /**
@@ -96,19 +96,19 @@
     }
 
     /**
-     * Processes INCOMING_CALL intents. Grabs the connection service informations from the intent
+     * Processes INCOMING_CALL intents. Grabs the connection service information from the intent
      * extra and forwards that to the CallsManager to start the incoming call flow.
      *
      * @param intent The incoming call intent.
      */
     private void processIncomingCallIntent(Intent intent) {
-        PhoneAccount phoneAccount = intent.getParcelableExtra(
-                TelecommManager.EXTRA_PHONE_ACCOUNT);
-        if (phoneAccount == null) {
+        PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
+                TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE);
+        if (phoneAccountHandle == null) {
             Log.w(this, "Rejecting incoming call due to null phone account");
             return;
         }
-        if (phoneAccount.getComponentName() == null) {
+        if (phoneAccountHandle.getComponentName() == null) {
             Log.w(this, "Rejecting incoming call due to null component name");
             return;
         }
@@ -122,7 +122,7 @@
         }
 
         Log.d(this, "Processing incoming call from connection service [%s]",
-                phoneAccount.getComponentName());
-        mCallsManager.processIncomingCallIntent(phoneAccount, clientExtras);
+                phoneAccountHandle.getComponentName());
+        mCallsManager.processIncomingCallIntent(phoneAccountHandle, clientExtras);
     }
 }
diff --git a/src/com/android/telecomm/CallLogManager.java b/src/com/android/telecomm/CallLogManager.java
index d1e2196..f8cd86f 100644
--- a/src/com/android/telecomm/CallLogManager.java
+++ b/src/com/android/telecomm/CallLogManager.java
@@ -21,7 +21,7 @@
 import android.os.AsyncTask;
 import android.provider.CallLog.Calls;
 import android.telecomm.CallState;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.VideoCallProfile;
 import android.telephony.PhoneNumberUtils;
 
@@ -39,7 +39,7 @@
      */
     private static class AddCallArgs {
         /**
-         * @param contactInfo Caller details.
+         * @param callerInfo Caller details.
          * @param number The phone number to be logged.
          * @param presentation Number presentation of the phone number to be logged.
          * @param callType The type of call (e.g INCOMING_TYPE). @see
@@ -51,7 +51,7 @@
          * @param dataUsage Data usage in bytes, or null if not applicable.
          */
         public AddCallArgs(Context context, CallerInfo callerInfo, String number,
-                int presentation, int callType, int features, PhoneAccount account,
+                int presentation, int callType, int features, PhoneAccountHandle accountHandle,
                 long creationDate, long durationInMillis, Long dataUsage) {
             this.context = context;
             this.callerInfo = callerInfo;
@@ -59,7 +59,7 @@
             this.presentation = presentation;
             this.callType = callType;
             this.features = features;
-            this.mAccount = account;
+            this.accountHandle = accountHandle;
             this.timestamp = creationDate;
             this.durationInSec = (int)(durationInMillis / 1000);
             this.dataUsage = dataUsage;
@@ -72,7 +72,7 @@
         public final int presentation;
         public final int callType;
         public final int features;
-        public final PhoneAccount mAccount;
+        public final PhoneAccountHandle accountHandle;
         public final long timestamp;
         public final int durationInSec;
         public final Long dataUsage;
@@ -119,12 +119,12 @@
         Log.d(TAG, "logNumber set to: %s", Log.pii(logNumber));
 
         final int presentation = getPresentation(call);
-        final PhoneAccount account = call.getPhoneAccount();
+        final PhoneAccountHandle accountHandle = call.getPhoneAccount();
 
         // TODO(vt): Once data usage is available, wire it up here.
         int callFeatures = getCallFeatures(call.getVideoStateHistory());
-        logCall(call.getCallerInfo(), logNumber, presentation, callLogType, callFeatures, account,
-                creationTime, age, null);
+        logCall(call.getCallerInfo(), logNumber, presentation, callLogType, callFeatures,
+                accountHandle, creationTime, age, null);
     }
 
     /**
@@ -145,7 +145,7 @@
             int presentation,
             int callType,
             int features,
-            PhoneAccount account,
+            PhoneAccountHandle accountHandle,
             long start,
             long duration,
             Long dataUsage) {
@@ -165,7 +165,7 @@
                     + Log.pii(number) + "," + presentation + ", " + callType
                     + ", " + start + ", " + duration);
             AddCallArgs args = new AddCallArgs(mContext, callerInfo, number, presentation,
-                    callType, features, account, start, duration, dataUsage);
+                    callType, features, accountHandle, start, duration, dataUsage);
             logCallAsync(args);
         } else {
           Log.d(TAG, "Not adding emergency call to call log.");
@@ -249,7 +249,7 @@
                 try {
                     // May block.
                     result[i] = Calls.addCall(c.callerInfo, c.context, c.number, c.presentation,
-                            c.callType, c.features, c.mAccount, c.timestamp, c.durationInSec,
+                            c.callType, c.features, c.accountHandle, c.timestamp, c.durationInSec,
                             c.dataUsage);
                 } catch (Exception e) {
                     // This is very rare but may happen in legitimate cases.
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 5a53525..e41f331 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -21,7 +21,7 @@
 import android.telecomm.CallAudioState;
 import android.telecomm.CallState;
 import android.telecomm.GatewayInfo;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telephony.DisconnectCause;
 
 import com.google.common.base.Preconditions;
@@ -254,11 +254,11 @@
     /**
      * Starts the process to attach the call to a connection service.
      *
-     * @param phoneAccount The phone account which contains the component name of the connection
+     * @param phoneAccountHandle The phone account which contains the component name of the connection
      *                     serivce to use for this call.
      * @param extras The optional extras Bundle passed with the intent used for the incoming call.
      */
-    void processIncomingCallIntent(PhoneAccount phoneAccount, Bundle extras) {
+    void processIncomingCallIntent(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
         Log.d(this, "processIncomingCallIntent");
         // Create a call with no handle. The handle is eventually set when the call is attached
         // to a connection service.
@@ -266,7 +266,7 @@
                 mConnectionServiceRepository,
                 null /* handle */,
                 null /* gatewayInfo */,
-                phoneAccount,
+                phoneAccountHandle,
                 true /* isIncoming */,
                 false /* isConference */);
 
@@ -285,7 +285,7 @@
      * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
      * @param videoState The desired video state for the outgoing call.
      */
-    void placeOutgoingCall(Uri handle, GatewayInfo gatewayInfo, PhoneAccount account,
+    void placeOutgoingCall(Uri handle, GatewayInfo gatewayInfo, PhoneAccountHandle accountHandle,
             boolean speakerphoneOn, int videoState) {
 
         final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
@@ -301,7 +301,7 @@
                 mConnectionServiceRepository,
                 uriHandle,
                 gatewayInfo,
-                account,
+                accountHandle,
                 false /* isIncoming */,
                 false /* isConference */);
         call.setStartWithSpeakerphoneOn(speakerphoneOn);
@@ -315,11 +315,11 @@
             // Emergency -- CreateConnectionProcessor will choose accounts automatically
             call.setPhoneAccount(null);
             call.startCreateConnection();
-        } else if (account == null) {
-            PhoneAccount defaultAccount = TelecommApp.getInstance().getPhoneAccountRegistrar()
-                    .getDefaultOutgoingPhoneAccount();
-            if (defaultAccount != null) {
-                call.setPhoneAccount(defaultAccount);
+        } else if (accountHandle == null) {
+            PhoneAccountHandle defaultAccountHandle = TelecommApp.getInstance()
+                    .getPhoneAccountRegistrar().getDefaultOutgoingPhoneAccount();
+            if (defaultAccountHandle != null) {
+                call.setPhoneAccount(defaultAccountHandle);
                 call.startCreateConnection();
             } else {
                 call.setState(CallState.PRE_DIAL_WAIT);
@@ -496,7 +496,7 @@
         }
     }
 
-    void phoneAccountSelected(Call call, PhoneAccount account) {
+    void phoneAccountSelected(Call call, PhoneAccountHandle account) {
         if (!mCalls.contains(call)) {
             Log.i(this, "Attemped to add account to unknown call %s", call);
         } else {
diff --git a/src/com/android/telecomm/CreateConnectionProcessor.java b/src/com/android/telecomm/CreateConnectionProcessor.java
index 45008c0..d0af6f0 100644
--- a/src/com/android/telecomm/CreateConnectionProcessor.java
+++ b/src/com/android/telecomm/CreateConnectionProcessor.java
@@ -16,7 +16,7 @@
 
 package com.android.telecomm;
 
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telephony.DisconnectCause;
 import android.telecomm.ConnectionRequest;
 
@@ -34,8 +34,8 @@
 final class CreateConnectionProcessor {
     private final Call mCall;
     private final ConnectionServiceRepository mRepository;
-    private List<PhoneAccount> mPhoneAccounts;
-    private Iterator<PhoneAccount> mPhoneAccountIterator;
+    private List<PhoneAccountHandle> mPhoneAccountHandles;
+    private Iterator<PhoneAccountHandle> mPhoneAccountHandleIterator;
     private CreateConnectionResponse mResponse;
     private int mLastErrorCode = DisconnectCause.ERROR_UNSPECIFIED;
     private String mLastErrorMsg;
@@ -49,12 +49,12 @@
 
     void process() {
         Log.v(this, "process");
-        mPhoneAccounts = new ArrayList<>();
+        mPhoneAccountHandles = new ArrayList<>();
         if (mCall.getPhoneAccount() != null) {
-            mPhoneAccounts.add(mCall.getPhoneAccount());
+            mPhoneAccountHandles.add(mCall.getPhoneAccount());
         }
         adjustPhoneAccountsForEmergency();
-        mPhoneAccountIterator = mPhoneAccounts.iterator();
+        mPhoneAccountHandleIterator = mPhoneAccountHandles.iterator();
         attemptNextPhoneAccount();
     }
 
@@ -79,15 +79,16 @@
     private void attemptNextPhoneAccount() {
         Log.v(this, "attemptNextPhoneAccount");
 
-        if (mResponse != null && mPhoneAccountIterator.hasNext()) {
-            PhoneAccount account = mPhoneAccountIterator.next();
-            Log.i(this, "Trying account %s", account);
-            ConnectionServiceWrapper service = mRepository.getService(account.getComponentName());
+        if (mResponse != null && mPhoneAccountHandleIterator.hasNext()) {
+            PhoneAccountHandle accountHandle = mPhoneAccountHandleIterator.next();
+            Log.i(this, "Trying accountHandle %s", accountHandle);
+            ConnectionServiceWrapper service =
+                    mRepository.getService(accountHandle.getComponentName());
             if (service == null) {
-                Log.i(this, "Found no connection service for account %s", account);
+                Log.i(this, "Found no connection service for accountHandle %s", accountHandle);
                 attemptNextPhoneAccount();
             } else {
-                mCall.setPhoneAccount(account);
+                mCall.setPhoneAccount(accountHandle);
                 mCall.setConnectionService(service);
                 Log.i(this, "Attempting to call from %s", service.getComponentName());
                 service.createConnection(mCall, new Response(service));
@@ -107,13 +108,14 @@
     private void adjustPhoneAccountsForEmergency()  {
         if (TelephonyUtil.shouldProcessAsEmergency(TelecommApp.getInstance(), mCall.getHandle())) {
             Log.i(this, "Emergency number detected");
-            mPhoneAccounts.clear();
-            List<PhoneAccount> allAccounts = TelecommApp.getInstance().getPhoneAccountRegistrar()
-                    .getEnabledPhoneAccounts();
-            for (int i = 0; i < allAccounts.size(); i++) {
-                if (TelephonyUtil.isPstnComponentName(allAccounts.get(i).getComponentName())) {
-                    Log.i(this, "Will try PSTN account %s for emergency", allAccounts.get(i));
-                    mPhoneAccounts.add(allAccounts.get(i));
+            mPhoneAccountHandles.clear();
+            List<PhoneAccountHandle> allAccountHandles = TelecommApp.getInstance()
+                    .getPhoneAccountRegistrar().getEnabledPhoneAccounts();
+            for (int i = 0; i < allAccountHandles.size(); i++) {
+                if (TelephonyUtil.isPstnComponentName(
+                        allAccountHandles.get(i).getComponentName())) {
+                    Log.i(this, "Will try PSTN account %s for emergency", allAccountHandles.get(i));
+                    mPhoneAccountHandles.add(allAccountHandles.get(i));
                 }
             }
         }
diff --git a/src/com/android/telecomm/InCallAdapter.java b/src/com/android/telecomm/InCallAdapter.java
index 0822dc4..31a009e 100644
--- a/src/com/android/telecomm/InCallAdapter.java
+++ b/src/com/android/telecomm/InCallAdapter.java
@@ -18,7 +18,7 @@
 
 import android.os.Handler;
 import android.os.Message;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 
 import com.android.internal.os.SomeArgs;
 import com.android.internal.telecomm.IInCallAdapter;
@@ -144,7 +144,7 @@
                     try {
                         call = mCallIdMapper.getCall(args.arg1);
                         if (call != null) {
-                            mCallsManager.phoneAccountSelected(call, (PhoneAccount) args.arg2);
+                            mCallsManager.phoneAccountSelected(call, (PhoneAccountHandle) args.arg2);
                         } else {
                             Log.w(this, "phoneAccountSelected, unknown call id: %s", args.arg1);
                         }
@@ -266,11 +266,11 @@
     }
 
     @Override
-    public void phoneAccountSelected(String callId, PhoneAccount account) {
+    public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle) {
         mCallIdMapper.checkValidCallId(callId);
         SomeArgs args = SomeArgs.obtain();
         args.arg1 = callId;
-        args.arg2 = account;
+        args.arg2 = accountHandle;
         mHandler.obtainMessage(MSG_PHONE_ACCOUNT_SELECTED, args).sendToTarget();
     }
 
diff --git a/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java b/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java
index 2dee24f..d99d976 100644
--- a/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java
+++ b/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java
@@ -24,7 +24,7 @@
 import android.net.Uri;
 import android.os.UserHandle;
 import android.telecomm.GatewayInfo;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
 import android.telecomm.VideoCallProfile;
 import android.telephony.PhoneNumberUtils;
@@ -116,8 +116,8 @@
             }
 
             GatewayInfo gatewayInfo = getGateWayInfoFromIntent(intent, resultHandleUri);
-            PhoneAccount account = getAccountFromIntent(intent);
-            mCallsManager.placeOutgoingCall(resultHandleUri, gatewayInfo, account,
+            PhoneAccountHandle accountHandle = getAccountHandleFromIntent(intent);
+            mCallsManager.placeOutgoingCall(resultHandleUri, gatewayInfo, accountHandle,
                     mIntent.getBooleanExtra(TelecommManager.EXTRA_START_CALL_WITH_SPEAKERPHONE,
                             false),
                     mIntent.getIntExtra(TelecommManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
@@ -261,9 +261,10 @@
             Log.d(this, "Found and copied gateway provider extras to broadcast intent.");
             return;
         }
-        PhoneAccount extraAccount = src.getParcelableExtra(TelecommManager.EXTRA_PHONE_ACCOUNT);
-        if (extraAccount != null) {
-            dst.putExtra(TelecommManager.EXTRA_PHONE_ACCOUNT, extraAccount);
+        PhoneAccountHandle extraAccountHandle =
+                src.getParcelableExtra(TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE);
+        if (extraAccountHandle != null) {
+            dst.putExtra(TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE, extraAccountHandle);
             Log.d(this, "Found and copied account extra to broadcast intent.");
         }
 
@@ -316,12 +317,12 @@
      * @param intent to extract account information from.
      * @return Account object containing extracted account information
      */
-    public static PhoneAccount getAccountFromIntent(Intent intent) {
+    public static PhoneAccountHandle getAccountHandleFromIntent(Intent intent) {
         if (intent == null) {
             return null;
         }
 
-        return intent.getParcelableExtra(TelecommManager.EXTRA_PHONE_ACCOUNT);
+        return intent.getParcelableExtra(TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE);
     }
 
     private void launchSystemDialer(Context context, Uri handle) {
diff --git a/src/com/android/telecomm/PhoneAccountPreferencesActivity.java b/src/com/android/telecomm/PhoneAccountPreferencesActivity.java
index 2988a9c..ae01497 100644
--- a/src/com/android/telecomm/PhoneAccountPreferencesActivity.java
+++ b/src/com/android/telecomm/PhoneAccountPreferencesActivity.java
@@ -21,7 +21,7 @@
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 
 import java.util.HashMap;
 import java.util.List;
@@ -42,7 +42,7 @@
             implements ListPreference.OnPreferenceChangeListener {
         private ListPreference mDefaultOutgoingAccount;
         private PhoneAccountRegistrar mRegistrar;
-        private Map<String, PhoneAccount> mAccountByValue = new HashMap<>();
+        private Map<String, PhoneAccountHandle> mAccountByValue = new HashMap<>();
 
         @Override
         public void onCreate(Bundle savedInstanceState) {
@@ -52,23 +52,23 @@
             mDefaultOutgoingAccount = (ListPreference) findPreference(KEY_DEFAULT_OUTGOING_ACCOUNT);
 
             mRegistrar = TelecommApp.getInstance().getPhoneAccountRegistrar();
-            List<PhoneAccount> accounts = mRegistrar.getEnabledPhoneAccounts();
-            PhoneAccount currentDefault = mRegistrar.getDefaultOutgoingPhoneAccount();
+            List<PhoneAccountHandle> accountHandles = mRegistrar.getEnabledPhoneAccounts();
+            PhoneAccountHandle currentDefault = mRegistrar.getDefaultOutgoingPhoneAccount();
 
-            String[] entryValues = new String[accounts.size() + 1];
-            String[] entries = new String[accounts.size() + 1];
+            String[] entryValues = new String[accountHandles.size() + 1];
+            String[] entries = new String[accountHandles.size() + 1];
 
-            int selectedIndex = accounts.size();  // Points to "ask every time" by default
+            int selectedIndex = accountHandles.size();  // Points to "ask every time" by default
             int i = 0;
-            for ( ; i < accounts.size(); i++) {
+            for ( ; i < accountHandles.size(); i++) {
                 entryValues[i] = Integer.toString(i);
                 entries[i] = mRegistrar
-                        .getPhoneAccountMetadata(accounts.get(i))
+                        .getPhoneAccount(accountHandles.get(i))
                         .getLabel();
-                if (Objects.equals(currentDefault, accounts.get(i))) {
+                if (Objects.equals(currentDefault, accountHandles.get(i))) {
                     selectedIndex = i;
                 }
-                mAccountByValue.put(entryValues[i], accounts.get(i));
+                mAccountByValue.put(entryValues[i], accountHandles.get(i));
             }
             entryValues[i] = Integer.toString(i);
             entries[i] = getString(R.string.account_ask_every_time);
diff --git a/src/com/android/telecomm/PhoneAccountRegistrar.java b/src/com/android/telecomm/PhoneAccountRegistrar.java
index 2deb557..7fd000a 100644
--- a/src/com/android/telecomm/PhoneAccountRegistrar.java
+++ b/src/com/android/telecomm/PhoneAccountRegistrar.java
@@ -16,6 +16,8 @@
 
 package com.android.telecomm;
 
+import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -26,8 +28,6 @@
 
 import android.content.SharedPreferences;
 import android.net.Uri;
-import android.telecomm.PhoneAccount;
-import android.telecomm.PhoneAccountMetadata;
 import android.telecomm.TelecommManager;
 
 import java.util.ArrayList;
@@ -35,11 +35,11 @@
 import java.util.Objects;
 
 /**
- * Handles writing and reading PhoneAccount registration entries. This is a simple verbatim
+ * Handles writing and reading PhoneAccountHandle registration entries. This is a simple verbatim
  * delegate for all the account handling methods on {@link TelecommManager} as implemented in
  * {@link TelecommServiceImpl}, with the notable exception that {@link TelecommServiceImpl} is
  * responsible for security checking to make sure that the caller has proper authority over
- * the {@code ComponentName}s they are declaring in their {@code PhoneAccount}s.
+ * the {@code ComponentName}s they are declaring in their {@code PhoneAccountHandle}s.
  *
  * TODO(santoscordon): Replace this implementation with a proper database stored in a Telecomm
  * provider.
@@ -54,46 +54,47 @@
         mContext = context;
     }
 
-    public PhoneAccount getDefaultOutgoingPhoneAccount() {
+    public PhoneAccountHandle getDefaultOutgoingPhoneAccount() {
         State s = read();
-        return s.defaultOutgoing;
+        return s.defaultOutgoingHandle;
     }
 
-    public void setDefaultOutgoingPhoneAccount(PhoneAccount account) {
+    public void setDefaultOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
         State s = read();
 
-        if (account == null) {
+        if (accountHandle == null) {
             // Asking to clear the default outgoing is a valid request
-            s.defaultOutgoing = null;
+            s.defaultOutgoingHandle = null;
         } else {
             boolean found = false;
-            for (PhoneAccountMetadata m : s.accounts) {
-                if (Objects.equals(account, m.getAccount())) {
+            for (PhoneAccount m : s.accounts) {
+                if (Objects.equals(accountHandle, m.getAccountHandle())) {
                     found = true;
                     break;
                 }
             }
 
             if (!found) {
-                Log.d(this, "Trying to set nonexistent default outgoing phone account %s", account);
+                Log.w(this, "Trying to set nonexistent default outgoing phone accountHandle %s",
+                        accountHandle);
                 return;
             }
 
-            s.defaultOutgoing = account;
+            s.defaultOutgoingHandle = accountHandle;
         }
 
         write(s);
     }
 
-    public List<PhoneAccount> getEnabledPhoneAccounts() {
+    public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
         State s = read();
-        return accountsOnly(s);
+        return accountHandlesOnly(s);
     }
 
-    public PhoneAccountMetadata getPhoneAccountMetadata(PhoneAccount account) {
+    public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) {
         State s = read();
-        for (PhoneAccountMetadata m : s.accounts) {
-            if (Objects.equals(account, m.getAccount())) {
+        for (PhoneAccount m : s.accounts) {
+            if (Objects.equals(accountHandle, m.getAccountHandle())) {
                 return m;
             }
         }
@@ -102,13 +103,13 @@
 
     // TODO: Should we implement an artificial limit for # of accounts associated with a single
     // ComponentName?
-    public void registerPhoneAccount(PhoneAccountMetadata metadata) {
+    public void registerPhoneAccount(PhoneAccount metadata) {
         State s = read();
 
         s.accounts.add(metadata);
         // Search for duplicates and remove any that are found.
         for (int i = 0; i < s.accounts.size() - 1; i++) {
-            if (Objects.equals(metadata.getAccount(), s.accounts.get(i).getAccount())) {
+            if (Objects.equals(metadata.getAccountHandle(), s.accounts.get(i).getAccountHandle())) {
                 // replace existing entry.
                 s.accounts.remove(i);
                 break;
@@ -118,11 +119,11 @@
         write(s);
     }
 
-    public void unregisterPhoneAccount(PhoneAccount account) {
+    public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
         State s = read();
 
         for (int i = 0; i < s.accounts.size(); i++) {
-            if (Objects.equals(account, s.accounts.get(i).getAccount())) {
+            if (Objects.equals(accountHandle, s.accounts.get(i).getAccountHandle())) {
                 s.accounts.remove(i);
                 break;
             }
@@ -139,7 +140,7 @@
         for (int i = 0; i < s.accounts.size(); i++) {
             if (Objects.equals(
                     packageName,
-                    s.accounts.get(i).getAccount().getComponentName().getPackageName())) {
+                    s.accounts.get(i).getAccountHandle().getComponentName().getPackageName())) {
                 s.accounts.remove(i);
             }
         }
@@ -152,20 +153,20 @@
     private void checkDefaultOutgoing(State s) {
         // Check that, after an operation that removes accounts, the account set up as the "default
         // outgoing" has not been deleted. If it has, then clear out the setting.
-        for (PhoneAccountMetadata m : s.accounts) {
-            if (Objects.equals(s.defaultOutgoing, m.getAccount())) {
+        for (PhoneAccount m : s.accounts) {
+            if (Objects.equals(s.defaultOutgoingHandle, m.getAccountHandle())) {
                 return;
             }
         }
-        s.defaultOutgoing = null;
+        s.defaultOutgoingHandle = null;
     }
 
-    private List<PhoneAccount> accountsOnly(State s) {
-        List<PhoneAccount> result = new ArrayList<>();
-        for (PhoneAccountMetadata m : s.accounts) {
-            result.add(m.getAccount());
+    private List<PhoneAccountHandle> accountHandlesOnly(State s) {
+        List<PhoneAccountHandle> accountHandles = new ArrayList<>();
+        for (PhoneAccount m : s.accounts) {
+            accountHandles.add(m.getAccountHandle());
         }
-        return result;
+        return accountHandles;
     }
 
     private State read() {
@@ -214,8 +215,8 @@
     }
 
     private static class State {
-        public PhoneAccount defaultOutgoing = null;
-        public final List<PhoneAccountMetadata> accounts = new ArrayList<>();
+        public PhoneAccountHandle defaultOutgoingHandle = null;
+        public final List<PhoneAccount> accounts = new ArrayList<>();
     }
 
     //
@@ -235,11 +236,11 @@
         @Override
         public JSONObject toJson(State o) throws JSONException {
             JSONObject json = new JSONObject();
-            if (o.defaultOutgoing != null) {
-                json.put(DEFAULT_OUTGOING, sPhoneAccountJson.toJson(o.defaultOutgoing));
+            if (o.defaultOutgoingHandle != null) {
+                json.put(DEFAULT_OUTGOING, sPhoneAccountJson.toJson(o.defaultOutgoingHandle));
             }
             JSONArray accounts = new JSONArray();
-            for (PhoneAccountMetadata m : o.accounts) {
+            for (PhoneAccount m : o.accounts) {
                 accounts.put(sPhoneAccountMetadataJson.toJson(m));
             }
             json.put(ACCOUNTS, accounts);
@@ -250,7 +251,7 @@
         public State fromJson(JSONObject json) throws JSONException {
             State s = new State();
             if (json.has(DEFAULT_OUTGOING)) {
-                s.defaultOutgoing = sPhoneAccountJson.fromJson(
+                s.defaultOutgoingHandle = sPhoneAccountJson.fromJson(
                         (JSONObject) json.get(DEFAULT_OUTGOING));
             }
             if (json.has(ACCOUNTS)) {
@@ -268,8 +269,8 @@
         }
     };
 
-    private static final Json<PhoneAccountMetadata> sPhoneAccountMetadataJson =
-            new Json<PhoneAccountMetadata>() {
+    private static final Json<PhoneAccount> sPhoneAccountMetadataJson =
+            new Json<PhoneAccount>() {
         private static final String ACCOUNT = "account";
         private static final String HANDLE = "handle";
         private static final String SUBSCRIPTION_NUMBER = "subscription_number";
@@ -280,9 +281,9 @@
         private static final String VIDEO_CALLING_SUPPORTED = "video_calling_supported";
 
         @Override
-        public JSONObject toJson(PhoneAccountMetadata o) throws JSONException {
+        public JSONObject toJson(PhoneAccount o) throws JSONException {
             return new JSONObject()
-                    .put(ACCOUNT, sPhoneAccountJson.toJson(o.getAccount()))
+                    .put(ACCOUNT, sPhoneAccountJson.toJson(o.getAccountHandle()))
                     .put(HANDLE, o.getHandle().toString())
                     .put(SUBSCRIPTION_NUMBER, o.getSubscriptionNumber())
                     .put(CAPABILITIES, o.getCapabilities())
@@ -293,8 +294,8 @@
         }
 
         @Override
-        public PhoneAccountMetadata fromJson(JSONObject json) throws JSONException {
-            return new PhoneAccountMetadata(
+        public PhoneAccount fromJson(JSONObject json) throws JSONException {
+            return new PhoneAccount(
                     sPhoneAccountJson.fromJson((JSONObject) json.get(ACCOUNT)),
                     Uri.parse((String) json.get(HANDLE)),
                     (String) json.get(SUBSCRIPTION_NUMBER),
@@ -306,21 +307,21 @@
         }
     };
 
-    private static final Json<PhoneAccount> sPhoneAccountJson =
-            new Json<PhoneAccount>() {
+    private static final Json<PhoneAccountHandle> sPhoneAccountJson =
+            new Json<PhoneAccountHandle>() {
         private static final String COMPONENT_NAME = "component_name";
         private static final String ID = "id";
 
         @Override
-        public JSONObject toJson(PhoneAccount o) throws JSONException {
+        public JSONObject toJson(PhoneAccountHandle o) throws JSONException {
             return new JSONObject()
                     .put(COMPONENT_NAME, o.getComponentName().flattenToString())
                     .put(ID, o.getId());
         }
 
         @Override
-        public PhoneAccount fromJson(JSONObject json) throws JSONException {
-            return new PhoneAccount(
+        public PhoneAccountHandle fromJson(JSONObject json) throws JSONException {
+            return new PhoneAccountHandle(
                     ComponentName.unflattenFromString((String) json.get(COMPONENT_NAME)),
                     (String) json.get(ID));
         }
diff --git a/src/com/android/telecomm/Ringer.java b/src/com/android/telecomm/Ringer.java
index 965c673..69d3a6a 100644
--- a/src/com/android/telecomm/Ringer.java
+++ b/src/com/android/telecomm/Ringer.java
@@ -39,7 +39,7 @@
 
     private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
             .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
-            .setUsage(AudioAttributes.USAGE_NOTIFICATION_TELEPHONY_RINGTONE)
+            .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
             .build();
 
     /** Indicate that we want the pattern to repeat at the step which turns on vibration. */
diff --git a/src/com/android/telecomm/TelecommApp.java b/src/com/android/telecomm/TelecommApp.java
index 15e489a..cf7b8df 100644
--- a/src/com/android/telecomm/TelecommApp.java
+++ b/src/com/android/telecomm/TelecommApp.java
@@ -21,8 +21,7 @@
 import android.net.Uri;
 import android.os.UserHandle;
 import android.telecomm.PhoneAccount;
-import android.telecomm.PhoneAccountMetadata;
-import android.telephony.PhoneNumberUtils;
+import android.telecomm.PhoneAccountHandle;
 
 /**
  * Top-level Application class for Telecomm.
@@ -39,7 +38,7 @@
     private MissedCallNotifier mMissedCallNotifier;
 
     /**
-     * Maintains the list of registered {@link android.telecomm.PhoneAccount}s.
+     * Maintains the list of registered {@link android.telecomm.PhoneAccountHandle}s.
      */
     private PhoneAccountRegistrar mPhoneAccountRegistrar;
 
@@ -74,24 +73,24 @@
     }
 
     private void addHangoutsAccount() {
-        // TODO: STOPSHIP. We are adding a hacked PhoneAccount to ensure that Wi-Fi calling in
+        // TODO: STOPSHIP. We are adding a hacked PhoneAccountHandle to ensure that Wi-Fi calling in
         // Hangouts continues to work. This needs to be replaced with proper Wi-Fi calling wiring
         // to the appropriate Connection Services.
-        PhoneAccountMetadata hangouts = new PhoneAccountMetadata(
-                new PhoneAccount(
+        PhoneAccount hangouts = new PhoneAccount(
+                new PhoneAccountHandle(
                         new ComponentName(
                                 "com.google.android.talk",
                                 "com.google.android.apps.babel.telephony.TeleConnectionService"),
                         "null_id"),
                 Uri.fromParts("tel", "null_uri", null),
                 "650-253-0000",
-                PhoneAccountMetadata.CAPABILITY_CALL_PROVIDER,
+                PhoneAccount.CAPABILITY_CALL_PROVIDER,
                 R.drawable.stat_sys_phone_call,
                 "Wi-Fi calling",
                 "Wi-Fi calling by Google Hangouts",
                 false);
         mPhoneAccountRegistrar.clearAccounts(
-                hangouts.getAccount().getComponentName().getPackageName());
+                hangouts.getAccountHandle().getComponentName().getPackageName());
         mPhoneAccountRegistrar.registerPhoneAccount(hangouts);
     }
 }
diff --git a/src/com/android/telecomm/TelecommServiceImpl.java b/src/com/android/telecomm/TelecommServiceImpl.java
index a9bbf8e..e08571a 100644
--- a/src/com/android/telecomm/TelecommServiceImpl.java
+++ b/src/com/android/telecomm/TelecommServiceImpl.java
@@ -19,16 +19,20 @@
 import android.app.AppOpsManager;
 import android.content.ComponentName;
 import android.content.Context;
+
+import android.content.Intent;
 import android.content.res.Resources;
 import android.os.Binder;
+import android.os.Bundle;
 import android.os.Handler;
+import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
 import android.os.ServiceManager;
 import android.phone.PhoneManager;
 import android.telecomm.CallState;
 import android.telecomm.PhoneAccount;
-import android.telecomm.PhoneAccountMetadata;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
 import android.telephony.TelephonyManager;
 
@@ -40,7 +44,13 @@
  * Implementation of the ITelecomm interface.
  */
 public class TelecommServiceImpl extends ITelecommService.Stub {
-    /**
+    /** ${inheritDoc} */
+    @Override
+    public IBinder asBinder() {
+        return super.asBinder();
+    }
+
+ /**
      * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
      * request after sending. The main thread will notify the request when it is complete.
      */
@@ -147,7 +157,7 @@
     //
 
     @Override
-    public PhoneAccount getDefaultOutgoingPhoneAccount() {
+    public PhoneAccountHandle getDefaultOutgoingPhoneAccount() {
         try {
             return mPhoneAccountRegistrar.getDefaultOutgoingPhoneAccount();
         } catch (Exception e) {
@@ -157,7 +167,7 @@
     }
 
     @Override
-    public List<PhoneAccount> getEnabledPhoneAccounts() {
+    public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
         try {
             return mPhoneAccountRegistrar.getEnabledPhoneAccounts();
         } catch (Exception e) {
@@ -167,34 +177,35 @@
     }
 
     @Override
-    public PhoneAccountMetadata getPhoneAccountMetadata(PhoneAccount account) {
+    public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) {
         try {
-            return mPhoneAccountRegistrar.getPhoneAccountMetadata(account);
+            return mPhoneAccountRegistrar.getPhoneAccount(accountHandle);
         } catch (Exception e) {
-            Log.e(this, e, "getPhoneAccountMetadata %s", account);
+            Log.e(this, e, "getPhoneAccount %s", accountHandle);
             throw e;
         }
     }
 
     @Override
-    public void registerPhoneAccount(PhoneAccountMetadata metadata) {
+    public void registerPhoneAccount(PhoneAccount account) {
         try {
             enforceModifyPermissionOrCallingPackage(
-                    metadata.getAccount().getComponentName().getPackageName());
-            mPhoneAccountRegistrar.registerPhoneAccount(metadata);
+                    account.getAccountHandle().getComponentName().getPackageName());
+            mPhoneAccountRegistrar.registerPhoneAccount(account);
         } catch (Exception e) {
-            Log.e(this, e, "registerPhoneAccount %s", metadata);
+            Log.e(this, e, "registerPhoneAccount %s", account);
             throw e;
         }
     }
 
     @Override
-    public void unregisterPhoneAccount(PhoneAccount account) {
+    public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
         try {
-            enforceModifyPermissionOrCallingPackage(account.getComponentName().getPackageName());
-            mPhoneAccountRegistrar.unregisterPhoneAccount(account);
+            enforceModifyPermissionOrCallingPackage(
+                    accountHandle.getComponentName().getPackageName());
+            mPhoneAccountRegistrar.unregisterPhoneAccount(accountHandle);
         } catch (Exception e) {
-            Log.e(this, e, "unregisterPhoneAccount %s", account);
+            Log.e(this, e, "unregisterPhoneAccount %s", accountHandle);
             throw e;
         }
     }
@@ -320,6 +331,28 @@
         return (int) sendRequest(MSG_GET_CURRENT_TTY_MODE);
     }
 
+    /**
+     * @see TelecommManager#addNewIncomingCall
+     */
+    @Override
+    public void addNewIncomingCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
+        if (phoneAccountHandle != null && phoneAccountHandle.getComponentName() != null) {
+            mAppOpsManager.checkPackage(
+                    Binder.getCallingUid(), phoneAccountHandle.getComponentName().getPackageName());
+
+            Intent intent = new Intent(TelecommManager.ACTION_INCOMING_CALL);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            intent.putExtra(TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
+            if (extras != null) {
+                intent.putExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS, extras);
+            }
+
+            long token = Binder.clearCallingIdentity();
+            TelecommApp.getInstance().startActivity(intent);
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
     //
     // Supporting methods for the ITelecommService interface implementation.
     //
diff --git a/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java b/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
index 1472444..a8e3195 100644
--- a/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
+++ b/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
@@ -21,7 +21,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
 
 /**
@@ -68,24 +68,15 @@
      * @param isVideoCall {@code True} if this is a video call.
      */
     private void sendIncomingCallIntent(Context context, boolean isVideoCall) {
-        // Create intent for adding an incoming call.
-        Intent intent = new Intent(TelecommManager.ACTION_INCOMING_CALL);
-        // TODO(santoscordon): Use a private @hide permission to make sure this only goes to
-        // Telecomm instead of setting the package explicitly.
-        intent.setPackage("com.android.telecomm");
-
-        PhoneAccount phoneAccount = new PhoneAccount(
+        PhoneAccountHandle phoneAccount = new PhoneAccountHandle(
                 new ComponentName(context, TestConnectionService.class),
-                null /* id */);
-        intent.putExtra(TelecommManager.EXTRA_PHONE_ACCOUNT, phoneAccount);
+                CallServiceNotifier.PHONE_ACCOUNT_ID);
 
         // For the purposes of testing, indicate whether the incoming call is a video call by
         // stashing an indicator in the EXTRA_INCOMING_CALL_EXTRAS.
         Bundle extras = new Bundle();
         extras.putBoolean(TestConnectionService.IS_VIDEO_CALL, isVideoCall);
 
-        intent.putExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS, extras);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        context.startActivity(intent);
+        TelecommManager.from(context).addNewIncomingCall(phoneAccount, extras);
     }
 }
diff --git a/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java b/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
index 7b48f1f..dfce7c7 100644
--- a/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
+++ b/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
@@ -24,7 +24,7 @@
 import android.content.Intent;
 import android.net.Uri;
 import android.telecomm.PhoneAccount;
-import android.telecomm.PhoneAccountMetadata;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
 import android.util.Log;
 import android.widget.Toast;
@@ -38,6 +38,8 @@
 public class CallServiceNotifier {
     private static final CallServiceNotifier INSTANCE = new CallServiceNotifier();
 
+    static final String PHONE_ACCOUNT_ID = "testapps_TestConnectionService_Account_ID";
+
     /**
      * Static notification IDs.
      */
@@ -86,20 +88,20 @@
      * Registers a phone account with telecomm.
      */
     public void registerPhoneAccount(Context context) {
-        PhoneAccountMetadata metadata = new PhoneAccountMetadata(
-                new PhoneAccount(
+        PhoneAccount account = new PhoneAccount(
+                new PhoneAccountHandle(
                         new ComponentName(context, TestConnectionService.class),
-                        "testapps_TestConnectionService_Account_ID"),
+                        PHONE_ACCOUNT_ID),
                 Uri.parse("tel:555-TEST"),
                 "555-TEST",
-                PhoneAccountMetadata.CAPABILITY_CALL_PROVIDER,
+                PhoneAccount.CAPABILITY_CALL_PROVIDER,
                 0,  // iconResId
-                "a label",
-                "a short description",
+                "Dummy Service",
+                "a short description for the dummy service",
                 false);
         TelecommManager telecommManager =
                 (TelecommManager) context.getSystemService(Context.TELECOMM_SERVICE);
-        telecommManager.registerPhoneAccount(metadata);
+        telecommManager.registerPhoneAccount(account);
     }
 
     /**
@@ -108,7 +110,7 @@
     public void showAllPhoneAccounts(Context context) {
         TelecommManager telecommManager =
                 (TelecommManager) context.getSystemService(Context.TELECOMM_SERVICE);
-        List<PhoneAccount> accounts = telecommManager.getEnabledPhoneAccounts();
+        List<PhoneAccountHandle> accounts = telecommManager.getEnabledPhoneAccounts();
 
         Toast.makeText(context, accounts.toString(), Toast.LENGTH_LONG).show();
     }
diff --git a/tests/src/com/android/telecomm/testapps/TestConnectionService.java b/tests/src/com/android/telecomm/testapps/TestConnectionService.java
index c27a3de..8f02b9f 100644
--- a/tests/src/com/android/telecomm/testapps/TestConnectionService.java
+++ b/tests/src/com/android/telecomm/testapps/TestConnectionService.java
@@ -27,7 +27,7 @@
 import android.telecomm.Connection;
 import android.telecomm.ConnectionRequest;
 import android.telecomm.ConnectionService;
-import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountHandle;
 import android.telecomm.RemoteConnection;
 import android.telecomm.SimpleResponse;
 import android.telecomm.StatusHints;
@@ -251,13 +251,13 @@
     }
 
     private class CallAttempter implements CreateConnectionResponse<RemoteConnection> {
-        private final Iterator<PhoneAccount> mAccountIterator;
+        private final Iterator<PhoneAccountHandle> mAccountIterator;
         private final CreateConnectionResponse<Connection> mCallback;
         private final ConnectionRequest mOriginalRequest;
         private final boolean mIsIncoming;
 
         CallAttempter(
-                Iterator<PhoneAccount> iterator,
+                Iterator<PhoneAccountHandle> iterator,
                 CreateConnectionResponse<Connection> callback,
                 ConnectionRequest originalRequest,
                 boolean isIncoming) {
@@ -276,7 +276,7 @@
                 mCalls.add(connection);
 
                 ConnectionRequest remoteRequest = new ConnectionRequest(
-                        request.getAccount(),
+                        request.getAccountHandle(),
                         mOriginalRequest.getCallId(),
                         request.getHandle(),
                         request.getHandlePresentation(),
@@ -396,7 +396,7 @@
             // Normally we would use the original request as is, but for testing purposes, we are
             // adding ".." to the end of the number to follow its path more easily through the logs.
             final ConnectionRequest request = new ConnectionRequest(
-                    originalRequest.getAccount(),
+                    originalRequest.getAccountHandle(),
                     originalRequest.getCallId(),
                     Uri.fromParts(handle.getScheme(),
                     handle.getSchemeSpecificPart() + "..", ""),
@@ -411,12 +411,13 @@
             connection.startOutgoing();
         } else {
             log("looking up accounts");
-            lookupRemoteAccounts(handle, new SimpleResponse<Uri, List<PhoneAccount>>() {
+            lookupRemoteAccounts(handle, new SimpleResponse<Uri, List<PhoneAccountHandle>>() {
                 @Override
-                public void onResult(Uri handle, List<PhoneAccount> accounts) {
-                    log("starting the call attempter with accounts: " + accounts);
+                public void onResult(Uri handle, List<PhoneAccountHandle> accountHandles) {
+                    log("starting the call attempter with accountHandles: " + accountHandles);
                     new CallAttempter(
-                            accounts.iterator(), callback, originalRequest, false).tryNextAccount();
+                            accountHandles.iterator(), callback, originalRequest, false)
+                            .tryNextAccount();
                 }
 
                 @Override
@@ -432,9 +433,9 @@
     @Override
     public void onCreateIncomingConnection(
             final ConnectionRequest request, final CreateConnectionResponse<Connection> response) {
-        PhoneAccount account = request.getAccount();
+        PhoneAccountHandle accountHandle = request.getAccountHandle();
         ComponentName componentName = new ComponentName(this, TestConnectionService.class);
-        if (account != null && componentName.equals(account.getComponentName())) {
+        if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) {
             // Get the stashed intent extra that determines if this is a video call or audio call.
             Bundle extras = request.getExtras();
             boolean isVideoCall = extras.getBoolean(IS_VIDEO_CALL);
@@ -452,7 +453,7 @@
             mCalls.add(connection);
 
             ConnectionRequest newRequest = new ConnectionRequest(
-                    request.getAccount(),
+                    request.getAccountHandle(),
                     request.getCallId(),
                     handle,
                     request.getHandlePresentation(),
@@ -461,18 +462,21 @@
             response.onSuccess(newRequest, connection);
             connection.setVideoState(videoState);
         } else {
-            SimpleResponse<Uri, List<PhoneAccount>> accountResponse =
-                    new SimpleResponse<Uri, List<PhoneAccount>>() {
+            SimpleResponse<Uri, List<PhoneAccountHandle>> accountResponse =
+                    new SimpleResponse<Uri, List<PhoneAccountHandle>>() {
                             @Override
-                            public void onResult(Uri handle, List<PhoneAccount> accounts) {
-                                log("attaching to incoming call with accounts: " + accounts);
-                                new CallAttempter(accounts.iterator(), response, request, true)
+                            public void onResult(
+                                    Uri handle, List<PhoneAccountHandle> accountHandles) {
+                                log("attaching to incoming call with accountHandles: "
+                                        + accountHandles);
+                                new CallAttempter(accountHandles.iterator(), response, request,
+                                        true /* isIncoming */)
                                         .tryNextAccount();
                             }
 
                             @Override
                             public void onError(Uri handle) {
-                                log("remote account lookup failed.");
+                                log("remote accountHandle lookup failed.");
                                 response.onFailure(request, 0, null);
                             }
             };