Add getSelfManagedPhoneAccounts TelecomManager API.

Adding getSelfManagedPhoneAccounts TelecomManager API; this is consistent
with the getCallCapablePhoneAccounts API which is already present.

Test: CTS
Bug: 34159263
Merged-In: I542ac26f71b680ee61c680a5f4c184a462f2a339
Change-Id: I542ac26f71b680ee61c680a5f4c184a462f2a339
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index ea82d52..af633fb 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -576,6 +576,24 @@
                 uriScheme, null, includeDisabledAccounts, userHandle);
     }
 
+    /**
+     * Retrieves a list of all phone accounts which have
+     * {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
+     * <p>
+     * Returns only the {@link PhoneAccount}s which are enabled as self-managed accounts are
+     * automatically enabled by default (see {@link #registerPhoneAccount(PhoneAccount)}).
+     *
+     * @param userHandle User handle of phone account owner.
+     * @return The phone account handles.
+     */
+    public List<PhoneAccountHandle> getSelfManagedPhoneAccounts(UserHandle userHandle) {
+        return getPhoneAccountHandles(
+                PhoneAccount.CAPABILITY_SELF_MANAGED,
+                PhoneAccount.CAPABILITY_EMERGENCY_CALLS_ONLY /* excludedCapabilities */,
+                null /* uriScheme */, null /* packageName */, false /* includeDisabledAccounts */,
+                userHandle);
+    }
+
     public List<PhoneAccountHandle> getCallCapablePhoneAccountsOfCurrentUser(
             String uriScheme, boolean includeDisabledAccounts) {
         return getCallCapablePhoneAccounts(uriScheme, includeDisabledAccounts, mCurrentUserHandle);
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 1ea0f38..ae80350 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -177,6 +177,31 @@
         }
 
         @Override
+        public List<PhoneAccountHandle> getSelfManagedPhoneAccounts(String callingPackage) {
+            try {
+                Log.startSession("TSI.gSMPA");
+                if (!canReadPhoneState(callingPackage, "Requires READ_PHONE_STATE permission.")) {
+                    throw new SecurityException("Requires READ_PHONE_STATE permission.");
+                }
+                synchronized (mLock) {
+                    final UserHandle callingUserHandle = Binder.getCallingUserHandle();
+                    long token = Binder.clearCallingIdentity();
+                    try {
+                        return mPhoneAccountRegistrar.getSelfManagedPhoneAccounts(
+                                callingUserHandle);
+                    } catch (Exception e) {
+                        Log.e(this, e, "getSelfManagedPhoneAccounts");
+                        throw e;
+                    } finally {
+                        Binder.restoreCallingIdentity(token);
+                    }
+                }
+            } finally {
+                Log.endSession();
+            }
+        }
+
+        @Override
         public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme,
                 String callingPackage) {
             try {