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: Iccbf3071239407533dd6f19342ddb221fb037546
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index d0aad4a..a4ee836 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;
@@ -702,7 +703,7 @@
}
public static PhoneAccountHandle makePstnPhoneAccountHandle(String id) {
- return makePstnPhoneAccountHandleWithPrefix(id, "", false);
+ return makePstnPhoneAccountHandleWithPrefix(id, "", false, null);
}
public static PhoneAccountHandle makePstnPhoneAccountHandle(int phoneId) {
@@ -710,22 +711,26 @@
}
public static PhoneAccountHandle makePstnPhoneAccountHandle(Phone phone) {
- return makePstnPhoneAccountHandleWithPrefix(phone, "", false);
+ return makePstnPhoneAccountHandleWithPrefix(phone, "", false, null);
}
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) {
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 49e1379..b6aaebe 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -387,7 +387,7 @@
private PhoneAccountHandle getEmergencyPhoneAccount() {
return PhoneUtils.makePstnPhoneAccountHandleWithPrefix(
- (Phone) null, "" /* prefix */, true /* isEmergency */);
+ (Phone) null, "" /* prefix */, true /* isEmergency */, null /* userHandle */);
}
public static Intent buildPhoneAccountConfigureIntent(
diff --git a/src/com/android/services/telephony/PstnIncomingCallNotifier.java b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
index 8615325..453cb55 100644
--- a/src/com/android/services/telephony/PstnIncomingCallNotifier.java
+++ b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
@@ -403,7 +403,7 @@
// receives an MT call while in ECM. Use the Emergency PhoneAccount to receive the account
// if it exists.
PhoneAccountHandle emergencyHandle =
- PhoneUtils.makePstnPhoneAccountHandleWithPrefix(mPhone, "", true);
+ PhoneUtils.makePstnPhoneAccountHandleWithPrefix(mPhone, "", true, null);
if(telecomAccountRegistry.hasAccountEntryForPhoneAccount(emergencyHandle)) {
Log.i(this, "Receiving MT call in ECM. Using Emergency PhoneAccount Instead.");
return emergencyHandle;
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 115c32b..f112d33 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -285,13 +285,19 @@
private PhoneAccount buildPstnPhoneAccount(boolean isEmergency, boolean isTestAccount) {
String testPrefix = isTestAccount ? "Test " : "";
+ // Check if we are registering another user. If we are, ensure that the account
+ // is registered to that user handle.
+ int subId = mPhone.getSubId();
+ UserHandle userToRegister = mSubscriptionManager.isActiveSubscriptionId(subId)
+ ? mSubscriptionManager.getSubscriptionUserHandle(subId)
+ : null;
+
// Build the Phone account handle.
PhoneAccountHandle phoneAccountHandle =
PhoneUtils.makePstnPhoneAccountHandleWithPrefix(
- mPhone, testPrefix, isEmergency);
+ mPhone, testPrefix, isEmergency, userToRegister);
// Populate the phone account data.
- int subId = mPhone.getSubId();
String subscriberId = mPhone.getSubscriberId();
int color = PhoneAccount.NO_HIGHLIGHT_COLOR;
int slotId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
@@ -355,8 +361,12 @@
// By default all SIM phone accounts can place emergency calls.
int capabilities = PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION |
- PhoneAccount.CAPABILITY_CALL_PROVIDER |
- PhoneAccount.CAPABILITY_MULTI_USER;
+ PhoneAccount.CAPABILITY_CALL_PROVIDER;
+
+ // This is enabled by default. To support work profiles, it should not be enabled.
+ if (userToRegister == null) {
+ capabilities |= PhoneAccount.CAPABILITY_MULTI_USER;
+ }
if (mContext.getResources().getBoolean(R.bool.config_pstnCanPlaceEmergencyCalls)) {
capabilities |= PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS;
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index da918ad..5b1f463 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -360,7 +360,8 @@
@Override
public PhoneAccountHandle makePstnPhoneAccountHandleWithPrefix(Phone phone, String prefix,
boolean isEmergency) {
- return PhoneUtils.makePstnPhoneAccountHandleWithPrefix(phone, prefix, isEmergency);
+ return PhoneUtils.makePstnPhoneAccountHandleWithPrefix(
+ phone, prefix, isEmergency, null);
}
};