Use ID 12 for other user ID in and query current user in TelecomServiceImplTest.
The content URI of a different user was using User ID 10 in TelecomServiceImplTest. This was causing some of the tests to fail on HSUM devices since on those devices there is an actual user with user ID 10. This CL uses user ID 12 instead to prevent confliction with the actual user 10 on HSUM devices. The same test case was also hard coding in user ID 0 as the current user id. This CL also updates the test to query the calling user ID and generate a URI with that user ID in case the device is HSUM and thus the calling user can be user 10.
Test: TelecomServiceImplTest#testRegisterPhoneAccountImageIconCrossUser
Fixes: 383078188
Flag: TEST_ONLY
Change-Id: I7a4c885c0eb210c00c6b056167c876043ca71ec4
diff --git a/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java b/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java
index 7d01a44..d002739 100644
--- a/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java
+++ b/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java
@@ -1096,9 +1096,10 @@
@Test
public void testRegisterPhoneAccountImageIconCrossUser() throws RemoteException {
String packageNameToUse = "com.android.officialpackage";
+ String callingUserId = String.valueOf(Binder.getCallingUserHandle().getIdentifier());
PhoneAccountHandle phHandle = new PhoneAccountHandle(new ComponentName(
packageNameToUse, "cs"), "test", Binder.getCallingUserHandle());
- Icon icon = Icon.createWithContentUri("content://10@media/external/images/media/");
+ Icon icon = Icon.createWithContentUri("content://12@media/external/images/media/");
PhoneAccount phoneAccount = makePhoneAccount(phHandle).setIcon(icon).build();
doReturn(PackageManager.PERMISSION_GRANTED)
.when(mContext).checkCallingOrSelfPermission(MODIFY_PHONE_STATE);
@@ -1108,19 +1109,21 @@
icon = Icon.createWithContentUri(
new Uri.Builder().scheme("content")
- .encodedAuthority("10%40media")
+ .encodedAuthority("12%40media")
.path("external/images/media/${mediaId.text}".trim())
.build());
phoneAccount = makePhoneAccount(phHandle).setIcon(icon).build();
// This should fail; security exception will be thrown
registerPhoneAccountTestHelper(phoneAccount, false);
- icon = Icon.createWithContentUri( Uri.parse("content://10%40play.ground"));
+ icon = Icon.createWithContentUri( Uri.parse("content://12%40play.ground"));
phoneAccount = makePhoneAccount(phHandle).setIcon(icon).build();
// This should fail; security exception will be thrown
registerPhoneAccountTestHelper(phoneAccount, false);
- icon = Icon.createWithContentUri("content://0@media/external/images/media/");
+ // Generate a URI referencing the calling/current user ID:
+ String currentUserUri = "content://" + callingUserId + "@media/external/images/media/";
+ icon = Icon.createWithContentUri(currentUserUri);
phoneAccount = makePhoneAccount(phHandle).setIcon(icon).build();
// This should succeed.
registerPhoneAccountTestHelper(phoneAccount, true);