Implement multi-SIM capabilities (1/6) [DO NOT MERGE]

- Split PhoneAccount into PhoneAccount & PhoneAccountMetadata
- Move PhoneAccount methods from TelephonyManager to TelecommManager

Bug:16292368
Change-Id: Ib440368d6bd0572b63c942360450fde5c27d84b9
(cherry picked from commit 936b3552b4a3569be9904c826b95b632886fb45d)
diff --git a/api/current.txt b/api/current.txt
index 58dd2bc..7cea546 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -28110,18 +28110,27 @@
     method protected abstract void updateCall(android.telecomm.InCallCall);
   }
 
-  public final class PhoneAccount implements android.os.Parcelable {
-    ctor public PhoneAccount(android.content.ComponentName, java.lang.String, android.net.Uri, java.lang.String, java.lang.String, boolean, boolean);
+  public class PhoneAccount implements android.os.Parcelable {
+    ctor public PhoneAccount(android.content.ComponentName, java.lang.String, android.net.Uri, int);
     method public int describeContents();
+    method public int getCapabilities();
     method public android.content.ComponentName getComponentName();
     method public android.net.Uri getHandle();
-    method public android.graphics.drawable.Drawable getIcon(android.content.Context);
-    method public android.graphics.drawable.Drawable getIcon(android.content.Context, int);
     method public java.lang.String getId();
-    method public java.lang.String getLabel(android.content.Context);
-    method public java.lang.String getShortDescription(android.content.Context);
-    method public boolean isEnabled();
-    method public boolean isSystemDefault();
+    method public void writeToParcel(android.os.Parcel, int);
+    field public static final int CAPABILITY_CALL_PROVIDER = 2; // 0x2
+    field public static final int CAPABILITY_SIM_CALL_MANAGER = 1; // 0x1
+    field public static final int CAPABILITY_SIM_SUBSCRIPTION = 4; // 0x4
+    field public static final android.os.Parcelable.Creator CREATOR;
+  }
+
+  public class PhoneAccountMetadata implements android.os.Parcelable {
+    ctor public PhoneAccountMetadata(android.telecomm.PhoneAccount, int, java.lang.String, java.lang.String);
+    method public int describeContents();
+    method public android.telecomm.PhoneAccount getAccount();
+    method public android.graphics.drawable.Drawable getIcon(android.content.Context);
+    method public java.lang.String getLabel();
+    method public java.lang.String getShortDescription();
     method public void writeToParcel(android.os.Parcel, int);
     field public static final android.os.Parcelable.Creator CREATOR;
   }
@@ -28662,7 +28671,6 @@
   }
 
   public class TelephonyManager {
-    method public java.util.List<android.telecomm.PhoneAccount> getAccounts();
     method public java.util.List<android.telephony.CellInfo> getAllCellInfo();
     method public int getCallState();
     method public android.telephony.CellLocation getCellLocation();
@@ -28711,7 +28719,6 @@
     field public static final int DATA_CONNECTING = 1; // 0x1
     field public static final int DATA_DISCONNECTED = 0; // 0x0
     field public static final int DATA_SUSPENDED = 3; // 0x3
-    field public static final java.lang.String EXTRA_ACCOUNT = "account";
     field public static final java.lang.String EXTRA_INCOMING_NUMBER = "incoming_number";
     field public static final java.lang.String EXTRA_STATE = "state";
     field public static final java.lang.String EXTRA_STATE_IDLE;
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index bbfb05e..395c1b9 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -558,9 +558,7 @@
 
         registerService(TELECOMM_SERVICE, new ServiceFetcher() {
                 public Object createService(ContextImpl ctx) {
-                    IBinder b = ServiceManager.getService(TELECOMM_SERVICE);
-                    return new TelecommManager(ctx.getOuterContext(),
-                            ITelecommService.Stub.asInterface(b));
+                    return new TelecommManager(ctx.getOuterContext());
                 }});
 
         registerService(PHONE_SERVICE, new ServiceFetcher() {
diff --git a/telecomm/java/android/telecomm/PhoneAccount.java b/telecomm/java/android/telecomm/PhoneAccount.java
index 4e440d8..c1eec83 100644
--- a/telecomm/java/android/telecomm/PhoneAccount.java
+++ b/telecomm/java/android/telecomm/PhoneAccount.java
@@ -17,52 +17,64 @@
 package android.telecomm;
 
 import android.content.ComponentName;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.telephony.Rlog;
-import android.util.DisplayMetrics;
-import android.util.Log;
 
-import java.util.MissingResourceException;
 import java.util.Objects;
 
 /**
  * Represents a distinct account, line of service or call placement method that
  * the system can use to place phone calls.
  */
-public final class PhoneAccount implements Parcelable {
+public class PhoneAccount implements Parcelable {
 
-    private static final int NO_DENSITY = -1;
 
-    private static final String LOG_TAG = "Account";
+    /**
+     * Flag indicating that this {@code PhoneAccount} can act as a call manager for traditional
+     * SIM-based telephony calls. The {@link ConnectionService} associated with this phone-account
+     * will be allowed to manage SIM-based phone calls including using its own proprietary
+     * phone-call implementation (like VoIP calling) to make calls instead of the telephony stack.
+     * When a user opts to place a call using the SIM-based telephony stack, the connection-service
+     * associated with this phone-account will be attempted first if the user has explicitly
+     * selected it to be used as the default call-manager.
+     * <p>
+     * See {@link #getCapabilities}
+     */
+    public static final int CAPABILITY_SIM_CALL_MANAGER = 0x1;
 
-    private final ComponentName mComponentName;
-    private final String mId;
-    private final Uri mHandle;
-    private final String mLabel;
-    private final String mShortDescription;
-    private final boolean mIsEnabled;
-    private final boolean mIsSystemDefault;
+    /**
+     * Flag indicating that this {@code PhoneAccount} can make phone calls in place of traditional
+     * SIM-based telephony calls. This account will be treated as a distinct method for placing
+     * calls alongside the traditional SIM-based telephony stack. This flag is distinct from
+     * {@link #CAPABILITY_SIM_CALL_MANAGER} in that it is not allowed to manage calls from or use
+     * the built-in telephony stack to place its calls.
+     * <p>
+     * See {@link #getCapabilities}
+     */
+    public static final int CAPABILITY_CALL_PROVIDER = 0x2;
+
+    /**
+     * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM subscription.
+     * <p>
+     * Only the android framework can set this capability on a phone-account.
+     */
+    public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
+
+    private ComponentName mComponentName;
+    private String mId;
+    private Uri mHandle;
+    private int mCapabilities;
 
     public PhoneAccount(
             ComponentName componentName,
             String id,
             Uri handle,
-            String label,
-            String shortDescription,
-            boolean isEnabled,
-            boolean isSystemDefault) {
+            int capabilities) {
         mComponentName = componentName;
         mId = id;
         mHandle = handle;
-        mLabel = label;
-        mShortDescription = shortDescription;
-        mIsSystemDefault = isSystemDefault;
-        mIsEnabled = isEnabled;
+        mCapabilities = capabilities;
     }
 
     /**
@@ -87,8 +99,8 @@
 
     /**
      * The handle (e.g., a phone number) associated with this {@code PhoneAccount}. This represents
-     * the destination from which outgoing calls using this {@code PhoneAccount} will appear to come
-     * from, if applicable, and the destination to which incoming calls using this
+     * the destination from which outgoing calls using this {@code PhoneAccount} will appear to
+     * come, if applicable, and the destination to which incoming calls using this
      * {@code PhoneAccount} may be addressed.
      *
      * @return A handle expressed as a {@code Uri}, for example, a phone number.
@@ -98,76 +110,23 @@
     }
 
     /**
-     * A short string label describing this {@code PhoneAccount}.
+     * The capabilities of this {@code PhoneAccount}.
      *
-     * @param context The invoking {@code Context}, used for retrieving resources.
-     *
-     * TODO(ihab): If don't need context, remove param
-     *
-     * @return A label for this {@code PhoneAccount}.
+     * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
      */
-    public String getLabel(Context context) {
-        return mLabel;
+    public int getCapabilities() {
+        return mCapabilities;
     }
 
-    /**
-     * A short paragraph describing this {@code PhoneAccount}.
-     *
-     * @param context The invoking {@code Context}, used for retrieving resources.
-     *
-     * TODO(ihab): If don't need context, remove param
-     *
-     * @return A description for this {@code PhoneAccount}.
-     */
-    public String getShortDescription(Context context) {
-        return mShortDescription;
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(mComponentName) + Objects.hashCode(mId) +
+                Objects.hashCode(mHandle) + mCapabilities;
     }
 
-    // TODO(ihab): Representation of the icons
     //
-    // Refactor to pass a Bitmap (scale it at runtime), but if they don't pass one, fall
-    // back to the android:icon attr in the manifest (<service /> first, <application /> second)
-
-    /**
-     * An icon to represent this {@code PhoneAccount} in a user interface.
-     *
-     * @param context The invoking {@code Context}, used for retrieving resources.
-     *
-     * @return An icon for this {@code PhoneAccount}.
-     */
-    public Drawable getIcon(Context context) {
-        return null;  // TODO(ihab): See above
-    }
-
-    /**
-     * An icon to represent this {@code PhoneAccount} in a user interface.
-     *
-     * @param context The invoking {@code Context}, used for retrieving resources.
-     * @param density A display density from {@link DisplayMetrics}.
-     *
-     * @return An icon for this {@code PhoneAccount}.
-     */
-    public Drawable getIcon(Context context, int density) {
-        return null;  // TODO(ihab): See above
-    }
-
-    /**
-     * Whether this {@code PhoneAccount} is enabled for use.
-     *
-     * @return {@code true} if this {@code PhoneAccount} is enabled.
-     */
-    public boolean isEnabled() {
-        return mIsEnabled;
-    }
-
-    /**
-     * Whether this {@code PhoneAccount} is the system default.
-     *
-     * @return {@code true} if this {@code PhoneAccount} is the system default.
-     */
-    public boolean isSystemDefault() {
-        return mIsSystemDefault;
-    }
+    // Parcelable implementation.
+    //
 
     @Override
     public int describeContents() {
@@ -179,18 +138,16 @@
         out.writeParcelable(mComponentName, flags);
         out.writeString(mId);
         out.writeString(mHandle != null ? mHandle.toString() : "");
-        out.writeString(mLabel);
-        out.writeString(mShortDescription);
-        out.writeInt(mIsEnabled ? 1 : 0);
-        out.writeInt(mIsSystemDefault ? 1 : 0);
+        out.writeInt(mCapabilities);
     }
 
-    public static final Creator<PhoneAccount> CREATOR
-            = new Creator<PhoneAccount>() {
+    public static final Creator<PhoneAccount> CREATOR = new Creator<PhoneAccount>() {
+        @Override
         public PhoneAccount createFromParcel(Parcel in) {
             return new PhoneAccount(in);
         }
 
+        @Override
         public PhoneAccount[] newArray(int size) {
             return new PhoneAccount[size];
         }
@@ -201,22 +158,6 @@
         mId = in.readString();
         String uriString = in.readString();
         mHandle = uriString.length() > 0 ? Uri.parse(uriString) : null;
-        mLabel = in.readString();
-        mShortDescription = in.readString();
-        mIsEnabled = in.readInt() == 1;
-        mIsSystemDefault = in.readInt() == 1;
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        return
-                other instanceof PhoneAccount &&
-                Objects.equals(mComponentName, ((PhoneAccount) other).mComponentName) &&
-                Objects.equals(mId, ((PhoneAccount) other).mId);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hashCode(mComponentName) + Objects.hashCode(mId);
+        mCapabilities = in.readInt();
     }
 }
diff --git a/telecomm/java/android/telecomm/PhoneAccountMetadata.aidl b/telecomm/java/android/telecomm/PhoneAccountMetadata.aidl
new file mode 100644
index 0000000..55b8900
--- /dev/null
+++ b/telecomm/java/android/telecomm/PhoneAccountMetadata.aidl
@@ -0,0 +1,22 @@
+/*
+ * 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 android.telecomm;
+
+/**
+ * {@hide}
+  */
+parcelable PhoneAccountMetadata;
diff --git a/telecomm/java/android/telecomm/PhoneAccountMetadata.java b/telecomm/java/android/telecomm/PhoneAccountMetadata.java
new file mode 100644
index 0000000..20a4d47
--- /dev/null
+++ b/telecomm/java/android/telecomm/PhoneAccountMetadata.java
@@ -0,0 +1,140 @@
+/*
+ * 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 android.telecomm;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.io.IOException;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.util.MissingResourceException;
+
+/**
+ * Provides user interface description information for a {@code PhoneAccount}.
+ */
+public class PhoneAccountMetadata implements Parcelable {
+    private PhoneAccount mAccount;
+    private int mIconResId;
+    private String mLabel;
+    private String mShortDescription;
+
+    public PhoneAccountMetadata(
+            PhoneAccount account,
+            int iconResId,
+            String label,
+            String shortDescription) {
+        mAccount = account;
+        mIconResId = iconResId;
+        mLabel = label;
+        mShortDescription = shortDescription;
+    }
+
+    /**
+     * The {@code PhoneAccount} to which this metadata pertains.
+     *
+     * @return A {@code PhoneAccount}.
+     */
+    public PhoneAccount getAccount() {
+        return mAccount;
+    }
+
+    /**
+     * A short string label describing a {@code PhoneAccount}.
+     *
+     * @return A label for this {@code PhoneAccount}.
+     */
+    public String getLabel() {
+        return mLabel;
+    }
+
+    /**
+     * A short paragraph describing a {@code PhoneAccount}.
+     *
+     * @return A description for this {@code PhoneAccount}.
+     */
+    public String getShortDescription() {
+        return mShortDescription;
+    }
+
+    /**
+     * An icon to represent this {@code PhoneAccount} in a user interface.
+     *
+     * @return An icon for this {@code PhoneAccount}.
+     */
+    public Drawable getIcon(Context context) {
+        return getIcon(context, mIconResId);
+    }
+
+    private Drawable getIcon(Context context, int resId) {
+        Context packageContext;
+        try {
+            packageContext = context.createPackageContext(
+                    mAccount.getComponentName().getPackageName(), 0);
+        } catch (PackageManager.NameNotFoundException e) {
+            Log.w(this, "Cannot find package %s", mAccount.getComponentName().getPackageName());
+            return null;
+        }
+        try {
+            return packageContext.getResources().getDrawable(resId);
+        } catch (MissingResourceException e) {
+            Log.e(this, e, "Cannot find icon %d in package %s",
+                    resId, mAccount.getComponentName().getPackageName());
+            return null;
+        }
+    }
+
+    //
+    // Parcelable implementation
+    //
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel out, int flags) {
+        out.writeParcelable(mAccount, 0);
+        out.writeInt(mIconResId);
+        out.writeString(mLabel);
+        out.writeString(mShortDescription);
+    }
+
+    public static final Creator<PhoneAccountMetadata> CREATOR
+            = new Creator<PhoneAccountMetadata>() {
+        @Override
+        public PhoneAccountMetadata createFromParcel(Parcel in) {
+            return new PhoneAccountMetadata(in);
+        }
+
+        @Override
+        public PhoneAccountMetadata[] newArray(int size) {
+            return new PhoneAccountMetadata[size];
+        }
+    };
+
+    private PhoneAccountMetadata(Parcel in) {
+        mAccount = in.readParcelable(getClass().getClassLoader());
+        mIconResId = in.readInt();
+        mLabel = in.readString();
+        mShortDescription = in.readString();
+    }
+}
diff --git a/telecomm/java/android/telecomm/RemoteConnectionService.java b/telecomm/java/android/telecomm/RemoteConnectionService.java
index a436af2..430133c 100644
--- a/telecomm/java/android/telecomm/RemoteConnectionService.java
+++ b/telecomm/java/android/telecomm/RemoteConnectionService.java
@@ -266,10 +266,7 @@
                 mComponentName,
                 null /* id */,
                 null /* handle */,
-                "" /* label */,
-                "" /* shortDescription */,
-                true /* isEnabled */,
-                false /* isSystemDefault */));
+                0 /* capabilities */));
         return accounts;
     }
 
diff --git a/telecomm/java/android/telecomm/TelecommManager.java b/telecomm/java/android/telecomm/TelecommManager.java
index 1bb18f2..fcd2eba 100644
--- a/telecomm/java/android/telecomm/TelecommManager.java
+++ b/telecomm/java/android/telecomm/TelecommManager.java
@@ -23,31 +23,30 @@
 
 import com.android.internal.telecomm.ITelecommService;
 
+import java.util.List;
+
 /**
  * Provides access to Telecomm-related functionality.
  * TODO(santoscordon): Move this all into PhoneManager.
  * @hide
  */
 public class TelecommManager {
+
+    /**
+     * The extra used with an {@link android.content.Intent#ACTION_CALL} or
+     * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a {@link PhoneAccount}
+     * to use when making the call.
+     *
+     * <p class="note">
+     * Retrieve with
+     * {@link android.content.Intent#getParcelableExtra(String)}.
+     */
+    public static final String EXTRA_PHONE_ACCOUNT = "account";
+
     private static final String TAG = "TelecommManager";
     private static final String TELECOMM_SERVICE_NAME = "telecomm";
 
     private final Context mContext;
-    private final ITelecommService mService;
-
-    /**
-     * @hide
-     */
-    public TelecommManager(Context context, ITelecommService service) {
-        Context appContext = context.getApplicationContext();
-        if (appContext != null) {
-            mContext = appContext;
-        } else {
-            mContext = context;
-        }
-
-        mService = service;
-    }
 
     /**
      * @hide
@@ -59,6 +58,103 @@
     /**
      * @hide
      */
+    public TelecommManager(Context context) {
+        Context appContext = context.getApplicationContext();
+        if (appContext != null) {
+            mContext = appContext;
+        } else {
+            mContext = context;
+        }
+    }
+
+    /**
+     * Return a list of {@link PhoneAccount}s which can be used to make and receive phone calls.
+     *
+     * @see #EXTRA_PHONE_ACCOUNT
+     * @return A list of {@code PhoneAccount} objects.
+     */
+    public List<PhoneAccount> getEnabledPhoneAccounts() {
+        try {
+            if (isServiceConnected()) {
+                return getTelecommService().getEnabledPhoneAccounts();
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelecommService#getEnabledPhoneAccounts", e);
+        }
+        return null;
+    }
+
+    /**
+     * Return the metadata for a specified {@link PhoneAccount}. Metadata includes resources which
+     * can be used in a user interface.
+     *
+     * @param account The {@link PhoneAccount}.
+     *
+     * @return The metadata for the account.
+     */
+    public PhoneAccountMetadata getPhoneAccountMetadata(PhoneAccount account) {
+        try {
+            if (isServiceConnected()) {
+                return getTelecommService().getPhoneAccountMetadata(account);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelecommService#getPhoneAccountMetadata", e);
+        }
+        return null;
+    }
+
+    /**
+     * Register a {@link PhoneAccount} for use by the system.
+     *
+     * @param account The {@link PhoneAccount}.
+     * @param metadata The metadata for the account.
+     */
+    public void registerPhoneAccount(PhoneAccount account, PhoneAccountMetadata metadata) {
+        try {
+            if (isServiceConnected()) {
+                getTelecommService().registerPhoneAccount(account, metadata);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelecommService#registerPhoneAccount", e);
+        }
+    }
+
+    /**
+     * Remove a {@link PhoneAccount} registration from the system.
+     *
+     * @param account An Account.
+     */
+    public void unregisterPhoneAccount(PhoneAccount account) {
+        try {
+            if (isServiceConnected()) {
+                getTelecommService().unregisterPhoneAccount(account);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelecommService#unregisterPhoneAccount", e);
+        }
+    }
+
+    /**
+     * Remove all Accounts for a given package from the system.
+     *
+     * @param packageName A package name that may have registered Accounts.
+     *
+     * @hide
+     */
+    @SystemApi
+    public void clearAccounts(String packageName) {
+        try {
+            if (isServiceConnected()) {
+                getTelecommService().clearAccounts(packageName);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelecommService#clearAccounts", e);
+        }
+    }
+
+    /**
+     * @hide
+     */
     @SystemApi
     public ComponentName getDefaultPhoneApp() {
         try {
@@ -108,7 +204,7 @@
 
     /**
      * Ends an ongoing call. TODO(santoscordon): L-release - need to convert all invocations of
-     * ITelephony#endCall to use this method (clockwork & gearhead).
+     * ITelecommService#endCall to use this method (clockwork & gearhead).
      *
      * @hide
      */
@@ -127,7 +223,7 @@
     /**
      * If there is a ringing incoming call, this method accepts the call on behalf of the user.
      * TODO(santoscordon): L-release - need to convert all invocation of
-     * ITelephony#answerRingingCall to use this method (clockwork & gearhead).
+     * ITelecommService#answerRingingCall to use this method (clockwork & gearhead).
      *
      * @hide
      */
diff --git a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl
index 30e4bdc..3334385 100644
--- a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl
+++ b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl
@@ -18,6 +18,7 @@
 
 import android.content.ComponentName;
 import android.telecomm.PhoneAccount;
+import android.telecomm.PhoneAccountMetadata;
 
 /**
  * Interface used to interact with Telecomm. Mostly this is used by TelephonyManager for passing
@@ -33,22 +34,32 @@
     void showCallScreen(boolean showDialpad);
 
     /**
-     * Gets a list of accounts.
+     * @see TelecommManager#getEnabledPhoneAccounts
      */
-    List<PhoneAccount> getAccounts();
+    List<PhoneAccount> getEnabledPhoneAccounts();
 
     /**
-     * Sets the enabled state of a given account.
+     * @see TelecommManager#getPhoneAccountMetadata
      */
-    void setEnabled(in PhoneAccount account, boolean enabled);
+    PhoneAccountMetadata getPhoneAccountMetadata(in PhoneAccount account);
 
     /**
-     * Sets a given account as the system default.
+     * @see TelecommManager#registerPhoneAccount
      */
-    void setSystemDefault(in PhoneAccount account);
+    void registerPhoneAccount(in PhoneAccount account, in PhoneAccountMetadata metadata);
 
     /**
-     * Returns the component name of the default phone application.
+     * @see TelecommManager#unregisterPhoneAccount
+     */
+    void unregisterPhoneAccount(in PhoneAccount account);
+
+    /**
+     * @see TelecommManager#clearAccounts
+     */
+    void clearAccounts(String packageName);
+
+    /**
+     * @see TelecommManager#getDefaultPhoneApp
      */
     ComponentName getDefaultPhoneApp();
 
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 91ce73a..c1eb843 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -298,17 +298,6 @@
     public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
 
     /**
-     * The lookup key used with an {@link android.content.Intent#ACTION_CALL} or
-     * {@link android.content.Intent#ACTION_DIAL} {@code Intent} for a {@link PhoneAccount}
-     * object indicating a preference when making a phone connection.
-     *
-     * <p class="note">
-     * Retrieve with
-     * {@link android.content.Intent#getParcelableExtra(String)}.
-     */
-    public static final String EXTRA_ACCOUNT = "account";
-
-    /**
      * Broadcast intent action indicating that a precise call state
      * (cellular) on the device has changed.
      *
@@ -3207,42 +3196,6 @@
     }
 
     /**
-     * Return a list of Accounts that can be used to indicate a preference when making
-     * a phone call.
-     *
-     * @see #EXTRA_ACCOUNT
-     * @return A list of {@code Accouint} objects.
-     */
-    public List<PhoneAccount> getAccounts() {
-        try {
-            return getTelecommService().getAccounts();
-        } catch (RemoteException e) {
-            Log.e(TAG, "Error calling ITelephony#getAccounts", e);
-        }
-        return null;
-    }
-
-    /** @hide */
-    @SystemApi
-    public void setEnabled(PhoneAccount account, boolean enabled) {
-        try {
-            getTelecommService().setEnabled(account, enabled);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Error calling ITelephony#setEnabled", e);
-        }
-    }
-
-    /** @hide */
-    @SystemApi
-    public void setSystemDefault(PhoneAccount account) {
-        try {
-            getTelecommService().setSystemDefault(account);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Error calling ITelephony#setSystemDefault", e);
-        }
-    }
-
-    /**
      * Set whether Android should display a simplified Mobile Network Settings UI.
      * The setting won't be persisted during power cycle.
      * <p>