Add work profile support for registering phone accounts with Telecom

When registering a phone account for a user not associated with the
phone process, we want to grab the user associated with the
phone subscription. Currently, we enable MULTI_USER_CAPABILITY for all
phone accounts; we should disable this when registering another user.
We will also need the INTERACT_ACROSS_USERS permission to perform
actions across users (other than the primary).

Bug: 255342474
Test: PhoneUtilsTest.java
Change-Id: I78c2e879f0890cef09c3e95045bada4c5bbf1a01
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index d0aad4a..5f14387 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -31,6 +31,7 @@
 import android.os.Handler;
 import android.os.Message;
 import android.os.PersistableBundle;
+import android.os.UserHandle;
 import android.os.VibrationEffect;
 import android.os.Vibrator;
 import android.telecom.PhoneAccount;
@@ -701,31 +702,28 @@
         Log.d(LOG_TAG, msg);
     }
 
-    public static PhoneAccountHandle makePstnPhoneAccountHandle(String id) {
-        return makePstnPhoneAccountHandleWithPrefix(id, "", false);
-    }
-
-    public static PhoneAccountHandle makePstnPhoneAccountHandle(int phoneId) {
-        return makePstnPhoneAccountHandle(PhoneFactory.getPhone(phoneId));
-    }
-
     public static PhoneAccountHandle makePstnPhoneAccountHandle(Phone phone) {
-        return makePstnPhoneAccountHandleWithPrefix(phone, "", false);
+        return makePstnPhoneAccountHandleWithPrefix(phone, "",
+                false, phone.getUserHandle());
     }
 
     public static PhoneAccountHandle makePstnPhoneAccountHandleWithPrefix(
-            Phone phone, String prefix, boolean isEmergency) {
+            Phone phone, String prefix, boolean isEmergency, UserHandle userHandle) {
         // TODO: Should use some sort of special hidden flag to decorate this account as
         // an emergency-only account
         String id = isEmergency ? EMERGENCY_ACCOUNT_HANDLE_ID : prefix +
                 String.valueOf(phone.getSubId());
-        return makePstnPhoneAccountHandleWithPrefix(id, prefix, isEmergency);
+        return makePstnPhoneAccountHandleWithPrefix(id, prefix, isEmergency, userHandle);
     }
 
     public static PhoneAccountHandle makePstnPhoneAccountHandleWithPrefix(
-            String id, String prefix, boolean isEmergency) {
+            String id, String prefix, boolean isEmergency, UserHandle userHandle) {
         ComponentName pstnConnectionServiceName = getPstnConnectionServiceName();
-        return new PhoneAccountHandle(pstnConnectionServiceName, id);
+        // If user handle is null, resort to default constructor to use phone process's
+        // user handle
+        return userHandle == null
+                ? new PhoneAccountHandle(pstnConnectionServiceName, id)
+                : new PhoneAccountHandle(pstnConnectionServiceName, id, userHandle);
     }
 
     public static int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {