Loading src/com/android/server/telecom/TelecomServiceImpl.java +27 −6 Original line number Original line Diff line number Diff line Loading @@ -284,7 +284,7 @@ public class TelecomServiceImpl { public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { //TODO: Deprecate this in S //TODO: Deprecate this in S try { try { enforceCallingPackage(packageName); enforceCallingPackage(packageName, "getPhoneAccountsForPackage"); } catch (SecurityException se1) { } catch (SecurityException se1) { EventLog.writeEvent(0x534e4554, "153995334", Binder.getCallingUid(), EventLog.writeEvent(0x534e4554, "153995334", Binder.getCallingUid(), "getPhoneAccountsForPackage: invalid calling package"); "getPhoneAccountsForPackage: invalid calling package"); Loading Loading @@ -319,6 +319,13 @@ public class TelecomServiceImpl { @Override @Override public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle, public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle, String callingPackage) { String callingPackage) { try { enforceCallingPackage(callingPackage, "getPhoneAccount"); } catch (SecurityException se) { EventLog.writeEvent(0x534e4554, "196406138", Binder.getCallingUid(), "getPhoneAccount: invalid calling package"); throw se; } synchronized (mLock) { synchronized (mLock) { final UserHandle callingUserHandle = Binder.getCallingUserHandle(); final UserHandle callingUserHandle = Binder.getCallingUserHandle(); if (CompatChanges.isChangeEnabled( if (CompatChanges.isChangeEnabled( Loading Loading @@ -852,7 +859,7 @@ public class TelecomServiceImpl { public boolean hasManageOngoingCallsPermission(String callingPackage) { public boolean hasManageOngoingCallsPermission(String callingPackage) { try { try { Log.startSession("TSI.hMOCP"); Log.startSession("TSI.hMOCP"); enforceCallingPackage(callingPackage); enforceCallingPackage(callingPackage, "hasManageOngoingCallsPermission"); return PermissionChecker.checkPermissionForDataDeliveryFromDataSource( return PermissionChecker.checkPermissionForDataDeliveryFromDataSource( mContext, Manifest.permission.MANAGE_ONGOING_CALLS, mContext, Manifest.permission.MANAGE_ONGOING_CALLS, Binder.getCallingPid(), Binder.getCallingPid(), Loading Loading @@ -1464,7 +1471,7 @@ public class TelecomServiceImpl { String callingFeatureId) { String callingFeatureId) { try { try { Log.startSession("TSI.pC"); Log.startSession("TSI.pC"); enforceCallingPackage(callingPackage); enforceCallingPackage(callingPackage, "placeCall"); PhoneAccountHandle phoneAccountHandle = null; PhoneAccountHandle phoneAccountHandle = null; boolean clearPhoneAccountHandleExtra = false; boolean clearPhoneAccountHandleExtra = false; Loading Loading @@ -2229,7 +2236,7 @@ public class TelecomServiceImpl { // feature is enabled ... // feature is enabled ... enforceConnectionServiceFeature(); enforceConnectionServiceFeature(); // ... and the PhoneAccounts they refer to are for their own package. // ... and the PhoneAccounts they refer to are for their own package. enforceCallingPackage(packageName); enforceCallingPackage(packageName, "enforcePhoneAccountModificationForPackage"); } } } } Loading @@ -2245,8 +2252,22 @@ public class TelecomServiceImpl { } } } } private void enforceCallingPackage(String packageName) { private void enforceCallingPackage(String packageName, String message) { mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName); int packageUid = -1; int callingUid = Binder.getCallingUid(); PackageManager pm = mContext.createContextAsUser( UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); if (pm != null) { try { packageUid = pm.getPackageUid(packageName, 0); } catch (PackageManager.NameNotFoundException e) { // packageUid is -1 } } if (packageUid != callingUid && callingUid != Process.ROOT_UID) { throw new SecurityException(message + ": Package " + packageName + " does not belong to " + callingUid); } } } private void enforceConnectionServiceFeature() { private void enforceConnectionServiceFeature() { Loading tests/src/com/android/server/telecom/tests/BasicCallTests.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isNull; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; Loading @@ -35,10 +36,13 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.Context; import android.content.IContentProvider; import android.content.IContentProvider; import android.content.pm.PackageManager; import android.media.AudioManager; import android.media.AudioManager; import android.net.Uri; import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Bundle; import android.os.Process; import android.os.Process; import android.os.UserHandle; import android.provider.BlockedNumberContract; import android.provider.BlockedNumberContract; import android.telecom.Call; import android.telecom.Call; import android.telecom.CallAudioState; import android.telecom.CallAudioState; Loading Loading @@ -85,10 +89,15 @@ public class BasicCallTests extends TelecomSystemTest { private static final String TEST_BUNDLE_KEY = "android.telecom.extra.TEST"; private static final String TEST_BUNDLE_KEY = "android.telecom.extra.TEST"; private static final String TEST_EVENT = "android.telecom.event.TEST"; private static final String TEST_EVENT = "android.telecom.event.TEST"; private PackageManager mPackageManager; @Override @Override @Before @Before public void setUp() throws Exception { public void setUp() throws Exception { super.setUp(); super.setUp(); doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt()); mPackageManager = mContext.getPackageManager(); when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid()); } } @Override @Override Loading tests/src/com/android/server/telecom/tests/MissedInformationTest.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,9 @@ import static android.provider.CallLog.Calls.USER_MISSED_CALL_SCREENING_SERVICE_ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout; Loading @@ -36,8 +39,11 @@ import android.content.ContentResolver; import android.content.ContentValues; import android.content.ContentValues; import android.content.IContentProvider; import android.content.IContentProvider; import android.content.Intent; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Bundle; import android.os.UserHandle; import android.provider.CallLog; import android.provider.CallLog; import android.telecom.DisconnectCause; import android.telecom.DisconnectCause; import android.telecom.TelecomManager; import android.telecom.TelecomManager; Loading Loading @@ -73,6 +79,7 @@ public class MissedInformationTest extends TelecomSystemTest { @Mock Call mIncomingCall; @Mock Call mIncomingCall; private CallsManager mCallsManager; private CallsManager mCallsManager; private CallIntentProcessor.AdapterImpl mAdapter; private CallIntentProcessor.AdapterImpl mAdapter; private PackageManager mPackageManager; @Override @Override @Before @Before Loading @@ -85,6 +92,9 @@ public class MissedInformationTest extends TelecomSystemTest { when(mContentProvider.call(any(String.class), any(String.class), when(mContentProvider.call(any(String.class), any(String.class), any(String.class), any(Bundle.class))).thenReturn(new Bundle()); any(String.class), any(Bundle.class))).thenReturn(new Bundle()); doReturn(mContentResolver).when(mSpyContext).getContentResolver(); doReturn(mContentResolver).when(mSpyContext).getContentResolver(); doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt()); mPackageManager = mContext.getPackageManager(); when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid()); } } @Override @Override Loading tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java +18 −7 Original line number Original line Diff line number Diff line Loading @@ -102,6 +102,7 @@ import static org.mockito.Mockito.when; public class TelecomServiceImplTest extends TelecomTestCase { public class TelecomServiceImplTest extends TelecomTestCase { public static final String TEST_PACKAGE = "com.test"; public static final String TEST_PACKAGE = "com.test"; public static final String PACKAGE_NAME = "test"; public static class CallIntentProcessAdapterFake implements CallIntentProcessor.Adapter { public static class CallIntentProcessAdapterFake implements CallIntentProcessor.Adapter { @Override @Override Loading Loading @@ -180,15 +181,17 @@ public class TelecomServiceImplTest extends TelecomTestCase { private static final UserHandle USER_HANDLE_16 = new UserHandle(16); private static final UserHandle USER_HANDLE_16 = new UserHandle(16); private static final UserHandle USER_HANDLE_17 = new UserHandle(17); private static final UserHandle USER_HANDLE_17 = new UserHandle(17); private static final PhoneAccountHandle TEL_PA_HANDLE_16 = new PhoneAccountHandle( private static final PhoneAccountHandle TEL_PA_HANDLE_16 = new PhoneAccountHandle( new ComponentName("test", "telComponentName"), "0", USER_HANDLE_16); new ComponentName(PACKAGE_NAME, "telComponentName"), "0", USER_HANDLE_16); private static final PhoneAccountHandle SIP_PA_HANDLE_17 = new PhoneAccountHandle( private static final PhoneAccountHandle SIP_PA_HANDLE_17 = new PhoneAccountHandle( new ComponentName("test", "sipComponentName"), "1", USER_HANDLE_17); new ComponentName(PACKAGE_NAME, "sipComponentName"), "1", USER_HANDLE_17); private static final PhoneAccountHandle TEL_PA_HANDLE_CURRENT = new PhoneAccountHandle( private static final PhoneAccountHandle TEL_PA_HANDLE_CURRENT = new PhoneAccountHandle( new ComponentName("test", "telComponentName"), "2", Binder.getCallingUserHandle()); new ComponentName(PACKAGE_NAME, "telComponentName"), "2", Binder.getCallingUserHandle()); private static final PhoneAccountHandle SIP_PA_HANDLE_CURRENT = new PhoneAccountHandle( private static final PhoneAccountHandle SIP_PA_HANDLE_CURRENT = new PhoneAccountHandle( new ComponentName("test", "sipComponentName"), "3", Binder.getCallingUserHandle()); new ComponentName(PACKAGE_NAME, "sipComponentName"), "3", private static final ComponentName THIRD_PARTY_CALL_SCREENING = new ComponentName("com.android" + Binder.getCallingUserHandle()); ".thirdparty", "com.android.thirdparty.callscreeningserviceimpl"); private static final ComponentName THIRD_PARTY_CALL_SCREENING = new ComponentName( "com.android.thirdparty", "com.android.thirdparty.callscreeningserviceimpl"); @Override @Override @Before @Before Loading @@ -201,6 +204,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { when(mockTelephonyManager.isVoiceCapable()).thenReturn(true); when(mockTelephonyManager.isVoiceCapable()).thenReturn(true); doReturn(mContext).when(mContext).getApplicationContext(); doReturn(mContext).when(mContext).getApplicationContext(); doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt()); doNothing().when(mContext).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), doNothing().when(mContext).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), anyString()); anyString()); doAnswer(invocation -> { doAnswer(invocation -> { Loading Loading @@ -237,6 +241,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { .thenReturn(true); .thenReturn(true); mPackageManager = mContext.getPackageManager(); mPackageManager = mContext.getPackageManager(); when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid()); } } @Override @Override Loading Loading @@ -458,12 +463,18 @@ public class TelecomServiceImplTest extends TelecomTestCase { @SmallTest @SmallTest @Test @Test public void testGetPhoneAccount() throws RemoteException { public void testGetPhoneAccount() throws Exception { makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); assertEquals(TEL_PA_HANDLE_16, mTSIBinder.getPhoneAccount(TEL_PA_HANDLE_16, assertEquals(TEL_PA_HANDLE_16, mTSIBinder.getPhoneAccount(TEL_PA_HANDLE_16, mContext.getPackageName()).getAccountHandle()); mContext.getPackageName()).getAccountHandle()); assertEquals(SIP_PA_HANDLE_17, mTSIBinder.getPhoneAccount(SIP_PA_HANDLE_17, assertEquals(SIP_PA_HANDLE_17, mTSIBinder.getPhoneAccount(SIP_PA_HANDLE_17, mContext.getPackageName()).getAccountHandle()); mContext.getPackageName()).getAccountHandle()); try { // Try to call the method without using the caller's package name mTSIBinder.getPhoneAccount(TEL_PA_HANDLE_16, null); fail("Should have thrown a SecurityException"); } catch (SecurityException expected) { } } } @SmallTest @SmallTest Loading Loading
src/com/android/server/telecom/TelecomServiceImpl.java +27 −6 Original line number Original line Diff line number Diff line Loading @@ -284,7 +284,7 @@ public class TelecomServiceImpl { public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { //TODO: Deprecate this in S //TODO: Deprecate this in S try { try { enforceCallingPackage(packageName); enforceCallingPackage(packageName, "getPhoneAccountsForPackage"); } catch (SecurityException se1) { } catch (SecurityException se1) { EventLog.writeEvent(0x534e4554, "153995334", Binder.getCallingUid(), EventLog.writeEvent(0x534e4554, "153995334", Binder.getCallingUid(), "getPhoneAccountsForPackage: invalid calling package"); "getPhoneAccountsForPackage: invalid calling package"); Loading Loading @@ -319,6 +319,13 @@ public class TelecomServiceImpl { @Override @Override public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle, public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle, String callingPackage) { String callingPackage) { try { enforceCallingPackage(callingPackage, "getPhoneAccount"); } catch (SecurityException se) { EventLog.writeEvent(0x534e4554, "196406138", Binder.getCallingUid(), "getPhoneAccount: invalid calling package"); throw se; } synchronized (mLock) { synchronized (mLock) { final UserHandle callingUserHandle = Binder.getCallingUserHandle(); final UserHandle callingUserHandle = Binder.getCallingUserHandle(); if (CompatChanges.isChangeEnabled( if (CompatChanges.isChangeEnabled( Loading Loading @@ -852,7 +859,7 @@ public class TelecomServiceImpl { public boolean hasManageOngoingCallsPermission(String callingPackage) { public boolean hasManageOngoingCallsPermission(String callingPackage) { try { try { Log.startSession("TSI.hMOCP"); Log.startSession("TSI.hMOCP"); enforceCallingPackage(callingPackage); enforceCallingPackage(callingPackage, "hasManageOngoingCallsPermission"); return PermissionChecker.checkPermissionForDataDeliveryFromDataSource( return PermissionChecker.checkPermissionForDataDeliveryFromDataSource( mContext, Manifest.permission.MANAGE_ONGOING_CALLS, mContext, Manifest.permission.MANAGE_ONGOING_CALLS, Binder.getCallingPid(), Binder.getCallingPid(), Loading Loading @@ -1464,7 +1471,7 @@ public class TelecomServiceImpl { String callingFeatureId) { String callingFeatureId) { try { try { Log.startSession("TSI.pC"); Log.startSession("TSI.pC"); enforceCallingPackage(callingPackage); enforceCallingPackage(callingPackage, "placeCall"); PhoneAccountHandle phoneAccountHandle = null; PhoneAccountHandle phoneAccountHandle = null; boolean clearPhoneAccountHandleExtra = false; boolean clearPhoneAccountHandleExtra = false; Loading Loading @@ -2229,7 +2236,7 @@ public class TelecomServiceImpl { // feature is enabled ... // feature is enabled ... enforceConnectionServiceFeature(); enforceConnectionServiceFeature(); // ... and the PhoneAccounts they refer to are for their own package. // ... and the PhoneAccounts they refer to are for their own package. enforceCallingPackage(packageName); enforceCallingPackage(packageName, "enforcePhoneAccountModificationForPackage"); } } } } Loading @@ -2245,8 +2252,22 @@ public class TelecomServiceImpl { } } } } private void enforceCallingPackage(String packageName) { private void enforceCallingPackage(String packageName, String message) { mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName); int packageUid = -1; int callingUid = Binder.getCallingUid(); PackageManager pm = mContext.createContextAsUser( UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); if (pm != null) { try { packageUid = pm.getPackageUid(packageName, 0); } catch (PackageManager.NameNotFoundException e) { // packageUid is -1 } } if (packageUid != callingUid && callingUid != Process.ROOT_UID) { throw new SecurityException(message + ": Package " + packageName + " does not belong to " + callingUid); } } } private void enforceConnectionServiceFeature() { private void enforceConnectionServiceFeature() { Loading
tests/src/com/android/server/telecom/tests/BasicCallTests.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isNull; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; Loading @@ -35,10 +36,13 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.Context; import android.content.IContentProvider; import android.content.IContentProvider; import android.content.pm.PackageManager; import android.media.AudioManager; import android.media.AudioManager; import android.net.Uri; import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Bundle; import android.os.Process; import android.os.Process; import android.os.UserHandle; import android.provider.BlockedNumberContract; import android.provider.BlockedNumberContract; import android.telecom.Call; import android.telecom.Call; import android.telecom.CallAudioState; import android.telecom.CallAudioState; Loading Loading @@ -85,10 +89,15 @@ public class BasicCallTests extends TelecomSystemTest { private static final String TEST_BUNDLE_KEY = "android.telecom.extra.TEST"; private static final String TEST_BUNDLE_KEY = "android.telecom.extra.TEST"; private static final String TEST_EVENT = "android.telecom.event.TEST"; private static final String TEST_EVENT = "android.telecom.event.TEST"; private PackageManager mPackageManager; @Override @Override @Before @Before public void setUp() throws Exception { public void setUp() throws Exception { super.setUp(); super.setUp(); doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt()); mPackageManager = mContext.getPackageManager(); when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid()); } } @Override @Override Loading
tests/src/com/android/server/telecom/tests/MissedInformationTest.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,9 @@ import static android.provider.CallLog.Calls.USER_MISSED_CALL_SCREENING_SERVICE_ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout; Loading @@ -36,8 +39,11 @@ import android.content.ContentResolver; import android.content.ContentValues; import android.content.ContentValues; import android.content.IContentProvider; import android.content.IContentProvider; import android.content.Intent; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Bundle; import android.os.UserHandle; import android.provider.CallLog; import android.provider.CallLog; import android.telecom.DisconnectCause; import android.telecom.DisconnectCause; import android.telecom.TelecomManager; import android.telecom.TelecomManager; Loading Loading @@ -73,6 +79,7 @@ public class MissedInformationTest extends TelecomSystemTest { @Mock Call mIncomingCall; @Mock Call mIncomingCall; private CallsManager mCallsManager; private CallsManager mCallsManager; private CallIntentProcessor.AdapterImpl mAdapter; private CallIntentProcessor.AdapterImpl mAdapter; private PackageManager mPackageManager; @Override @Override @Before @Before Loading @@ -85,6 +92,9 @@ public class MissedInformationTest extends TelecomSystemTest { when(mContentProvider.call(any(String.class), any(String.class), when(mContentProvider.call(any(String.class), any(String.class), any(String.class), any(Bundle.class))).thenReturn(new Bundle()); any(String.class), any(Bundle.class))).thenReturn(new Bundle()); doReturn(mContentResolver).when(mSpyContext).getContentResolver(); doReturn(mContentResolver).when(mSpyContext).getContentResolver(); doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt()); mPackageManager = mContext.getPackageManager(); when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid()); } } @Override @Override Loading
tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java +18 −7 Original line number Original line Diff line number Diff line Loading @@ -102,6 +102,7 @@ import static org.mockito.Mockito.when; public class TelecomServiceImplTest extends TelecomTestCase { public class TelecomServiceImplTest extends TelecomTestCase { public static final String TEST_PACKAGE = "com.test"; public static final String TEST_PACKAGE = "com.test"; public static final String PACKAGE_NAME = "test"; public static class CallIntentProcessAdapterFake implements CallIntentProcessor.Adapter { public static class CallIntentProcessAdapterFake implements CallIntentProcessor.Adapter { @Override @Override Loading Loading @@ -180,15 +181,17 @@ public class TelecomServiceImplTest extends TelecomTestCase { private static final UserHandle USER_HANDLE_16 = new UserHandle(16); private static final UserHandle USER_HANDLE_16 = new UserHandle(16); private static final UserHandle USER_HANDLE_17 = new UserHandle(17); private static final UserHandle USER_HANDLE_17 = new UserHandle(17); private static final PhoneAccountHandle TEL_PA_HANDLE_16 = new PhoneAccountHandle( private static final PhoneAccountHandle TEL_PA_HANDLE_16 = new PhoneAccountHandle( new ComponentName("test", "telComponentName"), "0", USER_HANDLE_16); new ComponentName(PACKAGE_NAME, "telComponentName"), "0", USER_HANDLE_16); private static final PhoneAccountHandle SIP_PA_HANDLE_17 = new PhoneAccountHandle( private static final PhoneAccountHandle SIP_PA_HANDLE_17 = new PhoneAccountHandle( new ComponentName("test", "sipComponentName"), "1", USER_HANDLE_17); new ComponentName(PACKAGE_NAME, "sipComponentName"), "1", USER_HANDLE_17); private static final PhoneAccountHandle TEL_PA_HANDLE_CURRENT = new PhoneAccountHandle( private static final PhoneAccountHandle TEL_PA_HANDLE_CURRENT = new PhoneAccountHandle( new ComponentName("test", "telComponentName"), "2", Binder.getCallingUserHandle()); new ComponentName(PACKAGE_NAME, "telComponentName"), "2", Binder.getCallingUserHandle()); private static final PhoneAccountHandle SIP_PA_HANDLE_CURRENT = new PhoneAccountHandle( private static final PhoneAccountHandle SIP_PA_HANDLE_CURRENT = new PhoneAccountHandle( new ComponentName("test", "sipComponentName"), "3", Binder.getCallingUserHandle()); new ComponentName(PACKAGE_NAME, "sipComponentName"), "3", private static final ComponentName THIRD_PARTY_CALL_SCREENING = new ComponentName("com.android" + Binder.getCallingUserHandle()); ".thirdparty", "com.android.thirdparty.callscreeningserviceimpl"); private static final ComponentName THIRD_PARTY_CALL_SCREENING = new ComponentName( "com.android.thirdparty", "com.android.thirdparty.callscreeningserviceimpl"); @Override @Override @Before @Before Loading @@ -201,6 +204,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { when(mockTelephonyManager.isVoiceCapable()).thenReturn(true); when(mockTelephonyManager.isVoiceCapable()).thenReturn(true); doReturn(mContext).when(mContext).getApplicationContext(); doReturn(mContext).when(mContext).getApplicationContext(); doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt()); doNothing().when(mContext).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), doNothing().when(mContext).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), anyString()); anyString()); doAnswer(invocation -> { doAnswer(invocation -> { Loading Loading @@ -237,6 +241,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { .thenReturn(true); .thenReturn(true); mPackageManager = mContext.getPackageManager(); mPackageManager = mContext.getPackageManager(); when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid()); } } @Override @Override Loading Loading @@ -458,12 +463,18 @@ public class TelecomServiceImplTest extends TelecomTestCase { @SmallTest @SmallTest @Test @Test public void testGetPhoneAccount() throws RemoteException { public void testGetPhoneAccount() throws Exception { makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); assertEquals(TEL_PA_HANDLE_16, mTSIBinder.getPhoneAccount(TEL_PA_HANDLE_16, assertEquals(TEL_PA_HANDLE_16, mTSIBinder.getPhoneAccount(TEL_PA_HANDLE_16, mContext.getPackageName()).getAccountHandle()); mContext.getPackageName()).getAccountHandle()); assertEquals(SIP_PA_HANDLE_17, mTSIBinder.getPhoneAccount(SIP_PA_HANDLE_17, assertEquals(SIP_PA_HANDLE_17, mTSIBinder.getPhoneAccount(SIP_PA_HANDLE_17, mContext.getPackageName()).getAccountHandle()); mContext.getPackageName()).getAccountHandle()); try { // Try to call the method without using the caller's package name mTSIBinder.getPhoneAccount(TEL_PA_HANDLE_16, null); fail("Should have thrown a SecurityException"); } catch (SecurityException expected) { } } } @SmallTest @SmallTest Loading