Enhance IMS related shell commands to also specify an optional User
When running IMS related CTS tests, we override the IMS package.
To support HSUM devices, ensure that the user is also specified in
the override.
Flag: com.android.internal.telephony.flags.ims_resolver_user_aware
Bug: 371272669
Test: atest CtsTelephonyTestCases
Change-Id: Ifacc64406a406c792f3bb20bccc58e88b5fdd23b
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index d7f7939..a8ec8a7 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -6640,6 +6640,8 @@
* Sets the ImsService Package Name that Telephony will bind to.
*
* @param slotIndex the slot ID that the ImsService should bind for.
+ * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL}
+ * if there is no preference.
* @param isCarrierService true if the ImsService is the carrier override, false if the
* ImsService is the device default ImsService.
* @param featureTypes An integer array of feature types associated with a packageName.
@@ -6647,7 +6649,7 @@
* with.
* @return true if setting the ImsService to bind to succeeded, false if it did not.
*/
- public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
+ public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService,
int[] featureTypes, String packageName) {
TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
@@ -6659,12 +6661,8 @@
// may happen if the device does not support IMS.
return false;
}
- Map<Integer, String> featureConfig = new HashMap<>();
- for (int featureType : featureTypes) {
- featureConfig.put(featureType, packageName);
- }
- return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
- featureConfig);
+ return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId,
+ isCarrierService, featureTypes);
} finally {
Binder.restoreCallingIdentity(identity);
}
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index 840f961..5ea1304 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -526,11 +526,14 @@
private void onHelpIms() {
PrintWriter pw = getOutPrintWriter();
pw.println("IMS Commands:");
- pw.println(" ims set-ims-service [-s SLOT_ID] (-c | -d | -f) PACKAGE_NAME");
+ pw.println(" ims set-ims-service [-s SLOT_ID] [-u USER_ID] (-c | -d | -f) PACKAGE_NAME");
pw.println(" Sets the ImsService defined in PACKAGE_NAME to to be the bound");
pw.println(" ImsService. Options are:");
pw.println(" -s: the slot ID that the ImsService should be bound for. If no option");
pw.println(" is specified, it will choose the default voice SIM slot.");
+ pw.println(" -u: the user ID that the ImsService should be bound on. If no option");
+ pw.println(" is specified, the SYSTEM user ID will be preferred followed by the");
+ pw.println(" current user ID if they are different");
pw.println(" -c: Override the ImsService defined in the carrier configuration.");
pw.println(" -d: Override the ImsService defined in the device overlay.");
pw.println(" -f: Set the feature that this override if for, if no option is");
@@ -1353,12 +1356,22 @@
private int handleImsSetServiceCommand() {
PrintWriter errPw = getErrPrintWriter();
int slotId = getDefaultSlot();
+ int userId = UserHandle.USER_NULL; // By default, set no userId constraint
Boolean isCarrierService = null;
List<Integer> featuresList = new ArrayList<>();
String opt;
while ((opt = getNextOption()) != null) {
switch (opt) {
+ case "-u": {
+ try {
+ userId = Integer.parseInt(getNextArgRequired());
+ } catch (NumberFormatException e) {
+ errPw.println("ims set-ims-service requires an integer as a USER_ID");
+ return -1;
+ }
+ break;
+ }
case "-s": {
try {
slotId = Integer.parseInt(getNextArgRequired());
@@ -1414,17 +1427,17 @@
for (int i = 0; i < featuresList.size(); i++) {
featureArray[i] = featuresList.get(i);
}
- boolean result = mInterface.setBoundImsServiceOverride(slotId, isCarrierService,
+ boolean result = mInterface.setBoundImsServiceOverride(slotId, userId, isCarrierService,
featureArray, packageName);
if (VDBG) {
- Log.v(LOG_TAG, "ims set-ims-service -s " + slotId + " "
+ Log.v(LOG_TAG, "ims set-ims-service -s " + slotId + " -u " + userId + " "
+ (isCarrierService ? "-c " : "-d ")
+ "-f " + featuresList + " "
+ packageName + ", result=" + result);
}
getOutPrintWriter().println(result);
} catch (RemoteException e) {
- Log.w(LOG_TAG, "ims set-ims-service -s " + slotId + " "
+ Log.w(LOG_TAG, "ims set-ims-service -s " + slotId + " -u " + userId + " "
+ (isCarrierService ? "-c " : "-d ")
+ "-f " + featuresList + " "
+ packageName + ", error" + e.getMessage());