Loading src/java/com/android/internal/telephony/NetworkScanRequestTracker.java +9 −4 Original line number Diff line number Diff line Loading @@ -259,11 +259,13 @@ public final class NetworkScanRequestTracker { private final int mScanId; private final int mUid; private final int mPid; private boolean mRenounceFineLocationAccess; private final String mCallingPackage; private boolean mIsBinderDead; NetworkScanRequestInfo(NetworkScanRequest r, Messenger m, IBinder b, int id, Phone phone, int callingUid, int callingPid, String callingPackage) { int callingUid, int callingPid, String callingPackage, boolean renounceFineLocationAccess) { super(); mRequest = r; mMessenger = m; Loading @@ -274,6 +276,7 @@ public final class NetworkScanRequestTracker { mPid = callingPid; mCallingPackage = callingPackage; mIsBinderDead = false; mRenounceFineLocationAccess = renounceFineLocationAccess; try { mBinder.linkToDeath(this, 0); Loading Loading @@ -453,7 +456,8 @@ public final class NetworkScanRequestTracker { .build(); if (ar.exception == null && ar.result != null) { NetworkScanResult nsr = (NetworkScanResult) ar.result; boolean isLocationAccessAllowed = LocationAccessPolicy.checkLocationPermission( boolean isLocationAccessAllowed = !nsri.mRenounceFineLocationAccess && LocationAccessPolicy.checkLocationPermission( nsri.mPhone.getContext(), locationQuery) == LocationAccessPolicy.LocationPermissionResult.ALLOWED; int notifyMsg = isLocationAccessAllowed Loading Loading @@ -628,12 +632,13 @@ public final class NetworkScanRequestTracker { * returned to the user, no matter how this scan will be actually handled. */ public int startNetworkScan( NetworkScanRequest request, Messenger messenger, IBinder binder, Phone phone, boolean renounceFineLocationAccess, NetworkScanRequest request, Messenger messenger, IBinder binder, Phone phone, int callingUid, int callingPid, String callingPackage) { int scanId = mNextNetworkScanRequestId.getAndIncrement(); NetworkScanRequestInfo nsri = new NetworkScanRequestInfo(request, messenger, binder, scanId, phone, callingUid, callingPid, callingPackage); callingUid, callingPid, callingPackage, renounceFineLocationAccess); // nsri will be stored as Message.obj mHandler.obtainMessage(CMD_START_NETWORK_SCAN, nsri).sendToTarget(); return scanId; Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +118 −26 Original line number Diff line number Diff line Loading @@ -47,9 +47,11 @@ import android.telephony.CellIdentity; import android.telephony.CellIdentityGsm; import android.telephony.CellLocation; import android.telephony.LinkCapacityEstimate; import android.telephony.NetworkRegistrationInfo; import android.telephony.PhoneCapability; import android.telephony.PhysicalChannelConfig; import android.telephony.PreciseDataConnectionState; import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyCallback; Loading @@ -59,6 +61,7 @@ import android.telephony.data.ApnSetting; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.text.TextUtils; import androidx.annotation.NonNull; Loading Loading @@ -90,6 +93,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private int mActiveSubId; private TelephonyDisplayInfo mTelephonyDisplayInfo; private int mSrvccState = -1; private ServiceState mServiceState = null; private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private int mDataConnectionState = TelephonyManager.DATA_UNKNOWN; private int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN; Loading Loading @@ -161,7 +165,8 @@ public class TelephonyRegistryTest extends TelephonyTest { TelephonyCallback.DisplayInfoListener, TelephonyCallback.LinkCapacityEstimateChangedListener, TelephonyCallback.PhysicalChannelConfigListener, TelephonyCallback.CellLocationListener { TelephonyCallback.CellLocationListener, TelephonyCallback.ServiceStateListener { // This class isn't mockable to get invocation counts because the IBinder is null and // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative. public AtomicInteger invocationCount = new AtomicInteger(0); Loading @@ -172,6 +177,12 @@ public class TelephonyRegistryTest extends TelephonyTest { mSrvccState = srvccState; } @Override public void onServiceStateChanged(ServiceState serviceState) { invocationCount.incrementAndGet(); mServiceState = serviceState; } @Override public void onPhoneCapabilityChanged(PhoneCapability capability) { invocationCount.incrementAndGet(); Loading Loading @@ -271,7 +282,7 @@ public class TelephonyRegistryTest extends TelephonyTest { PhoneCapability phoneCapability = new PhoneCapability(1, 2, null, false, new int[0]); int[] events = {TelephonyCallback.EVENT_PHONE_CAPABILITY_CHANGED}; mTelephonyRegistry.notifyPhoneCapabilityChanged(phoneCapability); mTelephonyRegistry.listenWithEventList(0, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 0, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(phoneCapability, mPhoneCapability); Loading @@ -291,8 +302,9 @@ public class TelephonyRegistryTest extends TelephonyTest { when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(activeSubs); int activeSubId = 0; mTelephonyRegistry.notifyActiveDataSubIdChanged(activeSubId); mTelephonyRegistry.listenWithEventList(activeSubId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.listenWithEventList(false, false, activeSubId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(activeSubId, mActiveSubId); Loading @@ -318,10 +330,69 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); // Should receive callback when listen is called that contains the latest notify result. mTelephonyRegistry.listenWithEventList(1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.listenWithEventList(false, false, 1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(srvccState, mSrvccState); // trigger callback srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); processAllMessages(); assertEquals(srvccState, mSrvccState); } /** * Test that we first receive a callback when listen(...) is called that contains the latest * notify(...) response and then that the callback is called correctly when notify(...) is * called. */ @Test @SmallTest public void testSrvccStateChangedWithRenouncedLocationAccess() throws Exception { // Return a slotIndex / phoneId of 0 for all sub ids given. doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex(); int srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_STARTED; int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); // Should receive callback when listen is called that contains the latest notify result. mTelephonyRegistry.listenWithEventList(true, true, 1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(srvccState, mSrvccState); assertServiceStateForLocationAccessSanitization(mServiceState); // trigger callback srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); processAllMessages(); assertEquals(srvccState, mSrvccState); } /** * Test that we first receive a callback when listen(...) is called that contains the latest * notify(...) response and then that the callback is called correctly when notify(...) is * called. */ @Test @SmallTest public void testSrvccStateChangedWithRenouncedFineLocationAccess() throws Exception { // Return a slotIndex / phoneId of 0 for all sub ids given. doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex(); int srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_STARTED; int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); // Should receive callback when listen is called that contains the latest notify result. mTelephonyRegistry.listenWithEventList(false, true, 1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(srvccState, mSrvccState); assertServiceStateForFineAccessSanitization(mServiceState); // trigger callback srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED; Loading @@ -330,6 +401,24 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(srvccState, mSrvccState); } private void assertServiceStateForFineAccessSanitization(ServiceState state) { if (state == null) return; if (state.getNetworkRegistrationInfoList() != null) { for (NetworkRegistrationInfo nrs : state.getNetworkRegistrationInfoList()) { assertEquals(nrs.getCellIdentity(), null); } } } private void assertServiceStateForLocationAccessSanitization(ServiceState state) { if (state == null) return; assertServiceStateForFineAccessSanitization(state); assertEquals(TextUtils.isEmpty(state.getOperatorAlphaLong()), true); assertEquals(TextUtils.isEmpty(state.getOperatorAlphaShort()), true); assertEquals(TextUtils.isEmpty(state.getOperatorNumeric()), true); } /** * Test that a SecurityException is thrown when we try to listen to a SRVCC state change without * READ_PRIVILEGED_PHONE_STATE. Loading @@ -343,8 +432,9 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(0 /*subId*/, srvccState); try { mTelephonyRegistry.listenWithEventList(0 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.listenWithEventList(false, false, 0 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); fail(); } catch (SecurityException e) { // pass test! Loading @@ -357,7 +447,7 @@ public class TelephonyRegistryTest extends TelephonyTest { @Test public void testMultiSimConfigChange() { int[] events = {TelephonyCallback.EVENT_RADIO_POWER_STATE_CHANGED}; mTelephonyRegistry.listenWithEventList(1, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 1, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(RADIO_POWER_UNAVAILABLE, mRadioPowerState); Loading Loading @@ -410,7 +500,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .setLinkProperties(new LinkProperties()) .setFailCause(0) .build()); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); assertEquals(TelephonyManager.DATA_CONNECTED, mDataConnectionState); Loading Loading @@ -469,7 +559,7 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(TelephonyManager.DATA_UNKNOWN, mDataConnectionState); assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, mNetworkType); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.notifyDataConnectionForSubscriber( Loading Loading @@ -686,7 +776,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .setLinkProperties(new LinkProperties()) .setFailCause(0) .build()); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); // Verify that the PDCS is reported for the only APN Loading @@ -713,12 +803,12 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(mTelephonyCallback.invocationCount.get(), 2); // Unregister the listener mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, new int[0], true); processAllMessages(); // Re-register the listener and ensure that both APN types are reported mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(4, mTelephonyCallback.invocationCount.get()); Loading Loading @@ -763,7 +853,7 @@ public class TelephonyRegistryTest extends TelephonyTest { configs.add(config); mTelephonyRegistry.notifyPhysicalChannelConfigForSubscriber(0, subId, configs); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); Loading Loading @@ -902,7 +992,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); processAllMessages(); int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( anyString(), any())).thenReturn(true); Loading @@ -928,7 +1018,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); processAllMessages(); int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( anyString(), any())).thenReturn(false); Loading Loading @@ -976,9 +1066,9 @@ public class TelephonyRegistryTest extends TelephonyTest { } }; telephonyCallback2.init(mSimpleExecutor2); mTelephonyRegistry.listenWithEventList(2, "pkg1", mTelephonyRegistry.listenWithEventList(false, false, 2, "pkg1", mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); mTelephonyRegistry.listenWithEventList(2, "pkg2", mTelephonyRegistry.listenWithEventList(false, false, 2, "pkg2", mContext.getAttributionTag(), telephonyCallback2.callback, events, false); when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( eq("pkg1"), any())).thenReturn(false); Loading Loading @@ -1022,7 +1112,7 @@ public class TelephonyRegistryTest extends TelephonyTest { // Listen to EVENT_CELL_LOCATION_CHANGED for the current user Id. int[] events = {TelephonyCallback.EVENT_CELL_LOCATION_CHANGED}; mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); // Broadcast ACTION_USER_SWITCHED for USER_SYSTEM. Callback should be triggered. Loading @@ -1046,8 +1136,9 @@ public class TelephonyRegistryTest extends TelephonyTest { private void assertSecurityExceptionThrown(int[] event) { try { mTelephonyRegistry.listenWithEventList( SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); false, false, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); fail("SecurityException should throw without permission"); } catch (SecurityException expected) { } Loading @@ -1056,8 +1147,9 @@ public class TelephonyRegistryTest extends TelephonyTest { private void assertSecurityExceptionNotThrown(int[] event) { try { mTelephonyRegistry.listenWithEventList( SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); false, false, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); } catch (SecurityException unexpected) { fail("SecurityException thrown with permission"); } Loading @@ -1070,7 +1162,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); processAllMessages(); int[] events = {TelephonyCallback.EVENT_LINK_CAPACITY_ESTIMATE_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); Loading Loading @@ -1109,7 +1201,7 @@ public class TelephonyRegistryTest extends TelephonyTest { doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(1).when(mMockSubInfo).getSimSlotIndex(); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); Loading Loading
src/java/com/android/internal/telephony/NetworkScanRequestTracker.java +9 −4 Original line number Diff line number Diff line Loading @@ -259,11 +259,13 @@ public final class NetworkScanRequestTracker { private final int mScanId; private final int mUid; private final int mPid; private boolean mRenounceFineLocationAccess; private final String mCallingPackage; private boolean mIsBinderDead; NetworkScanRequestInfo(NetworkScanRequest r, Messenger m, IBinder b, int id, Phone phone, int callingUid, int callingPid, String callingPackage) { int callingUid, int callingPid, String callingPackage, boolean renounceFineLocationAccess) { super(); mRequest = r; mMessenger = m; Loading @@ -274,6 +276,7 @@ public final class NetworkScanRequestTracker { mPid = callingPid; mCallingPackage = callingPackage; mIsBinderDead = false; mRenounceFineLocationAccess = renounceFineLocationAccess; try { mBinder.linkToDeath(this, 0); Loading Loading @@ -453,7 +456,8 @@ public final class NetworkScanRequestTracker { .build(); if (ar.exception == null && ar.result != null) { NetworkScanResult nsr = (NetworkScanResult) ar.result; boolean isLocationAccessAllowed = LocationAccessPolicy.checkLocationPermission( boolean isLocationAccessAllowed = !nsri.mRenounceFineLocationAccess && LocationAccessPolicy.checkLocationPermission( nsri.mPhone.getContext(), locationQuery) == LocationAccessPolicy.LocationPermissionResult.ALLOWED; int notifyMsg = isLocationAccessAllowed Loading Loading @@ -628,12 +632,13 @@ public final class NetworkScanRequestTracker { * returned to the user, no matter how this scan will be actually handled. */ public int startNetworkScan( NetworkScanRequest request, Messenger messenger, IBinder binder, Phone phone, boolean renounceFineLocationAccess, NetworkScanRequest request, Messenger messenger, IBinder binder, Phone phone, int callingUid, int callingPid, String callingPackage) { int scanId = mNextNetworkScanRequestId.getAndIncrement(); NetworkScanRequestInfo nsri = new NetworkScanRequestInfo(request, messenger, binder, scanId, phone, callingUid, callingPid, callingPackage); callingUid, callingPid, callingPackage, renounceFineLocationAccess); // nsri will be stored as Message.obj mHandler.obtainMessage(CMD_START_NETWORK_SCAN, nsri).sendToTarget(); return scanId; Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +118 −26 Original line number Diff line number Diff line Loading @@ -47,9 +47,11 @@ import android.telephony.CellIdentity; import android.telephony.CellIdentityGsm; import android.telephony.CellLocation; import android.telephony.LinkCapacityEstimate; import android.telephony.NetworkRegistrationInfo; import android.telephony.PhoneCapability; import android.telephony.PhysicalChannelConfig; import android.telephony.PreciseDataConnectionState; import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyCallback; Loading @@ -59,6 +61,7 @@ import android.telephony.data.ApnSetting; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.text.TextUtils; import androidx.annotation.NonNull; Loading Loading @@ -90,6 +93,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private int mActiveSubId; private TelephonyDisplayInfo mTelephonyDisplayInfo; private int mSrvccState = -1; private ServiceState mServiceState = null; private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private int mDataConnectionState = TelephonyManager.DATA_UNKNOWN; private int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN; Loading Loading @@ -161,7 +165,8 @@ public class TelephonyRegistryTest extends TelephonyTest { TelephonyCallback.DisplayInfoListener, TelephonyCallback.LinkCapacityEstimateChangedListener, TelephonyCallback.PhysicalChannelConfigListener, TelephonyCallback.CellLocationListener { TelephonyCallback.CellLocationListener, TelephonyCallback.ServiceStateListener { // This class isn't mockable to get invocation counts because the IBinder is null and // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative. public AtomicInteger invocationCount = new AtomicInteger(0); Loading @@ -172,6 +177,12 @@ public class TelephonyRegistryTest extends TelephonyTest { mSrvccState = srvccState; } @Override public void onServiceStateChanged(ServiceState serviceState) { invocationCount.incrementAndGet(); mServiceState = serviceState; } @Override public void onPhoneCapabilityChanged(PhoneCapability capability) { invocationCount.incrementAndGet(); Loading Loading @@ -271,7 +282,7 @@ public class TelephonyRegistryTest extends TelephonyTest { PhoneCapability phoneCapability = new PhoneCapability(1, 2, null, false, new int[0]); int[] events = {TelephonyCallback.EVENT_PHONE_CAPABILITY_CHANGED}; mTelephonyRegistry.notifyPhoneCapabilityChanged(phoneCapability); mTelephonyRegistry.listenWithEventList(0, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 0, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(phoneCapability, mPhoneCapability); Loading @@ -291,8 +302,9 @@ public class TelephonyRegistryTest extends TelephonyTest { when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(activeSubs); int activeSubId = 0; mTelephonyRegistry.notifyActiveDataSubIdChanged(activeSubId); mTelephonyRegistry.listenWithEventList(activeSubId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.listenWithEventList(false, false, activeSubId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(activeSubId, mActiveSubId); Loading @@ -318,10 +330,69 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); // Should receive callback when listen is called that contains the latest notify result. mTelephonyRegistry.listenWithEventList(1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.listenWithEventList(false, false, 1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(srvccState, mSrvccState); // trigger callback srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); processAllMessages(); assertEquals(srvccState, mSrvccState); } /** * Test that we first receive a callback when listen(...) is called that contains the latest * notify(...) response and then that the callback is called correctly when notify(...) is * called. */ @Test @SmallTest public void testSrvccStateChangedWithRenouncedLocationAccess() throws Exception { // Return a slotIndex / phoneId of 0 for all sub ids given. doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex(); int srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_STARTED; int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); // Should receive callback when listen is called that contains the latest notify result. mTelephonyRegistry.listenWithEventList(true, true, 1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(srvccState, mSrvccState); assertServiceStateForLocationAccessSanitization(mServiceState); // trigger callback srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); processAllMessages(); assertEquals(srvccState, mSrvccState); } /** * Test that we first receive a callback when listen(...) is called that contains the latest * notify(...) response and then that the callback is called correctly when notify(...) is * called. */ @Test @SmallTest public void testSrvccStateChangedWithRenouncedFineLocationAccess() throws Exception { // Return a slotIndex / phoneId of 0 for all sub ids given. doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex(); int srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_STARTED; int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(1 /*subId*/, srvccState); // Should receive callback when listen is called that contains the latest notify result. mTelephonyRegistry.listenWithEventList(false, true, 1 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(srvccState, mSrvccState); assertServiceStateForFineAccessSanitization(mServiceState); // trigger callback srvccState = TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED; Loading @@ -330,6 +401,24 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(srvccState, mSrvccState); } private void assertServiceStateForFineAccessSanitization(ServiceState state) { if (state == null) return; if (state.getNetworkRegistrationInfoList() != null) { for (NetworkRegistrationInfo nrs : state.getNetworkRegistrationInfoList()) { assertEquals(nrs.getCellIdentity(), null); } } } private void assertServiceStateForLocationAccessSanitization(ServiceState state) { if (state == null) return; assertServiceStateForFineAccessSanitization(state); assertEquals(TextUtils.isEmpty(state.getOperatorAlphaLong()), true); assertEquals(TextUtils.isEmpty(state.getOperatorAlphaShort()), true); assertEquals(TextUtils.isEmpty(state.getOperatorNumeric()), true); } /** * Test that a SecurityException is thrown when we try to listen to a SRVCC state change without * READ_PRIVILEGED_PHONE_STATE. Loading @@ -343,8 +432,9 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_SRVCC_STATE_CHANGED}; mTelephonyRegistry.notifySrvccStateChanged(0 /*subId*/, srvccState); try { mTelephonyRegistry.listenWithEventList(0 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.listenWithEventList(false, false, 0 /*subId*/, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); fail(); } catch (SecurityException e) { // pass test! Loading @@ -357,7 +447,7 @@ public class TelephonyRegistryTest extends TelephonyTest { @Test public void testMultiSimConfigChange() { int[] events = {TelephonyCallback.EVENT_RADIO_POWER_STATE_CHANGED}; mTelephonyRegistry.listenWithEventList(1, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 1, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(RADIO_POWER_UNAVAILABLE, mRadioPowerState); Loading Loading @@ -410,7 +500,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .setLinkProperties(new LinkProperties()) .setFailCause(0) .build()); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); assertEquals(TelephonyManager.DATA_CONNECTED, mDataConnectionState); Loading Loading @@ -469,7 +559,7 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(TelephonyManager.DATA_UNKNOWN, mDataConnectionState); assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, mNetworkType); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); mTelephonyRegistry.notifyDataConnectionForSubscriber( Loading Loading @@ -686,7 +776,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .setLinkProperties(new LinkProperties()) .setFailCause(0) .build()); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); // Verify that the PDCS is reported for the only APN Loading @@ -713,12 +803,12 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(mTelephonyCallback.invocationCount.get(), 2); // Unregister the listener mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, new int[0], true); processAllMessages(); // Re-register the listener and ensure that both APN types are reported mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertEquals(4, mTelephonyCallback.invocationCount.get()); Loading Loading @@ -763,7 +853,7 @@ public class TelephonyRegistryTest extends TelephonyTest { configs.add(config); mTelephonyRegistry.notifyPhysicalChannelConfigForSubscriber(0, subId, configs); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); Loading Loading @@ -902,7 +992,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); processAllMessages(); int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( anyString(), any())).thenReturn(true); Loading @@ -928,7 +1018,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); processAllMessages(); int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( anyString(), any())).thenReturn(false); Loading Loading @@ -976,9 +1066,9 @@ public class TelephonyRegistryTest extends TelephonyTest { } }; telephonyCallback2.init(mSimpleExecutor2); mTelephonyRegistry.listenWithEventList(2, "pkg1", mTelephonyRegistry.listenWithEventList(false, false, 2, "pkg1", mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); mTelephonyRegistry.listenWithEventList(2, "pkg2", mTelephonyRegistry.listenWithEventList(false, false, 2, "pkg2", mContext.getAttributionTag(), telephonyCallback2.callback, events, false); when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( eq("pkg1"), any())).thenReturn(false); Loading Loading @@ -1022,7 +1112,7 @@ public class TelephonyRegistryTest extends TelephonyTest { // Listen to EVENT_CELL_LOCATION_CHANGED for the current user Id. int[] events = {TelephonyCallback.EVENT_CELL_LOCATION_CHANGED}; mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); // Broadcast ACTION_USER_SWITCHED for USER_SYSTEM. Callback should be triggered. Loading @@ -1046,8 +1136,9 @@ public class TelephonyRegistryTest extends TelephonyTest { private void assertSecurityExceptionThrown(int[] event) { try { mTelephonyRegistry.listenWithEventList( SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); false, false, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); fail("SecurityException should throw without permission"); } catch (SecurityException expected) { } Loading @@ -1056,8 +1147,9 @@ public class TelephonyRegistryTest extends TelephonyTest { private void assertSecurityExceptionNotThrown(int[] event) { try { mTelephonyRegistry.listenWithEventList( SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); false, false, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, event, true); } catch (SecurityException unexpected) { fail("SecurityException thrown with permission"); } Loading @@ -1070,7 +1162,7 @@ public class TelephonyRegistryTest extends TelephonyTest { .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); processAllMessages(); int[] events = {TelephonyCallback.EVENT_LINK_CAPACITY_ESTIMATE_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, 2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); Loading Loading @@ -1109,7 +1201,7 @@ public class TelephonyRegistryTest extends TelephonyTest { doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(1).when(mMockSubInfo).getSimSlotIndex(); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); Loading