Loading tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java +2 −0 Original line number Diff line number Diff line Loading @@ -279,6 +279,8 @@ public class ContextFixture implements TestFixture<Context> { return TestApplication.getAppContext().getSystemService(name); case Context.POWER_WHITELIST_MANAGER: return mPowerWhitelistManager; case Context.LOCATION_SERVICE: return mLocationManager; default: return null; } Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +61 −2 Original line number Diff line number Diff line Loading @@ -35,10 +35,16 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.content.Intent; import android.content.pm.UserInfo; import android.net.LinkProperties; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.telephony.AccessNetworkConstants; import android.telephony.Annotation; import android.telephony.CellIdentity; import android.telephony.CellIdentityGsm; import android.telephony.CellLocation; import android.telephony.LinkCapacityEstimate; import android.telephony.PhoneCapability; import android.telephony.PhysicalChannelConfig; Loading @@ -64,6 +70,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; Loading @@ -85,6 +92,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private List<PhysicalChannelConfig> mPhysicalChannelConfigs; private TelephonyRegistry.ConfigurationProvider mMockConfigurationProvider; private CellLocation mCellLocation; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -151,7 +159,8 @@ public class TelephonyRegistryTest extends TelephonyTest { TelephonyCallback.PreciseDataConnectionStateListener, TelephonyCallback.DisplayInfoListener, TelephonyCallback.LinkCapacityEstimateChangedListener, TelephonyCallback.PhysicalChannelConfigListener { TelephonyCallback.PhysicalChannelConfigListener, TelephonyCallback.CellLocationListener { // 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 Loading @@ -192,6 +201,11 @@ public class TelephonyRegistryTest extends TelephonyTest { mLinkCapacityEstimateList = linkCapacityEstimateList; } @Override public void onCellLocationChanged(CellLocation location) { mCellLocation = location; } @Override public void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs) { mPhysicalChannelConfigs = configs; Loading Loading @@ -610,6 +624,51 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(displayInfo, mTelephonyDisplayInfo); } @Test public void testNotifyCellLocationForSubscriberByUserSwitched() throws RemoteException { final int phoneId = 0; final int subId = 1; // Return a slotIndex / phoneId of 0 for subId 1. doReturn(new int[] {subId}).when(mSubscriptionController).getSubId(phoneId); doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(subId); doReturn(phoneId).when(mMockSubInfo).getSimSlotIndex(); mServiceManagerMockedServices.put("isub", mSubscriptionController); doReturn(mSubscriptionController).when(mSubscriptionController) .queryLocalInterface(anyString()); UserInfo userInfo = new UserInfo(UserHandle.myUserId(), "" /* name */, 0 /* flags */); doReturn(userInfo).when(mIActivityManager).getCurrentUser(); doReturn(true).when(mLocationManager).isLocationEnabledForUser(any(UserHandle.class)); CellIdentity cellIdentity = new CellIdentityGsm(-1, -1, -1, -1, null, null, null, null, Collections.emptyList()); mTelephonyRegistry.notifyCellLocationForSubscriber(subId, cellIdentity); processAllMessages(); // Listen to EVENT_CELL_LOCATION_CHANGED for the current user Id. int[] events = {TelephonyCallback.EVENT_CELL_LOCATION_CHANGED}; mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); // Broadcast ACTION_USER_SWITCHED for USER_SYSTEM. Callback should be triggered. mCellLocation = null; mContext.sendBroadcast(new Intent(Intent.ACTION_USER_SWITCHED)); processAllMessages(); assertEquals(cellIdentity.asCellLocation(), mCellLocation); // Broadcast ACTION_USER_SWITCHED for the current user Id + 1. Callback shouldn't be // triggered. userInfo.id++; mCellLocation = null; mContext.sendBroadcast(new Intent(Intent.ACTION_USER_SWITCHED)); processAllMessages(); assertEquals(null, mCellLocation); } private void assertSecurityExceptionThrown(int[] event) { try { mTelephonyRegistry.listenWithEventList( Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkCapabilities; import android.net.vcn.VcnManager; Loading Loading @@ -326,6 +327,8 @@ public abstract class TelephonyTest { protected LinkBandwidthEstimator mLinkBandwidthEstimator; @Mock protected PinStorage mPinStorage; @Mock protected LocationManager mLocationManager; protected ActivityManager mActivityManager; protected ImsCallProfile mImsCallProfile; Loading Loading @@ -484,6 +487,7 @@ public abstract class TelephonyTest { mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); mVcnManager = mContext.getSystemService(VcnManager.class); mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); //mTelephonyComponentFactory doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory).inject(anyString()); Loading Loading
tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java +2 −0 Original line number Diff line number Diff line Loading @@ -279,6 +279,8 @@ public class ContextFixture implements TestFixture<Context> { return TestApplication.getAppContext().getSystemService(name); case Context.POWER_WHITELIST_MANAGER: return mPowerWhitelistManager; case Context.LOCATION_SERVICE: return mLocationManager; default: return null; } Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +61 −2 Original line number Diff line number Diff line Loading @@ -35,10 +35,16 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.content.Intent; import android.content.pm.UserInfo; import android.net.LinkProperties; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.telephony.AccessNetworkConstants; import android.telephony.Annotation; import android.telephony.CellIdentity; import android.telephony.CellIdentityGsm; import android.telephony.CellLocation; import android.telephony.LinkCapacityEstimate; import android.telephony.PhoneCapability; import android.telephony.PhysicalChannelConfig; Loading @@ -64,6 +70,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; Loading @@ -85,6 +92,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private List<PhysicalChannelConfig> mPhysicalChannelConfigs; private TelephonyRegistry.ConfigurationProvider mMockConfigurationProvider; private CellLocation mCellLocation; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -151,7 +159,8 @@ public class TelephonyRegistryTest extends TelephonyTest { TelephonyCallback.PreciseDataConnectionStateListener, TelephonyCallback.DisplayInfoListener, TelephonyCallback.LinkCapacityEstimateChangedListener, TelephonyCallback.PhysicalChannelConfigListener { TelephonyCallback.PhysicalChannelConfigListener, TelephonyCallback.CellLocationListener { // 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 Loading @@ -192,6 +201,11 @@ public class TelephonyRegistryTest extends TelephonyTest { mLinkCapacityEstimateList = linkCapacityEstimateList; } @Override public void onCellLocationChanged(CellLocation location) { mCellLocation = location; } @Override public void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs) { mPhysicalChannelConfigs = configs; Loading Loading @@ -610,6 +624,51 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(displayInfo, mTelephonyDisplayInfo); } @Test public void testNotifyCellLocationForSubscriberByUserSwitched() throws RemoteException { final int phoneId = 0; final int subId = 1; // Return a slotIndex / phoneId of 0 for subId 1. doReturn(new int[] {subId}).when(mSubscriptionController).getSubId(phoneId); doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(subId); doReturn(phoneId).when(mMockSubInfo).getSimSlotIndex(); mServiceManagerMockedServices.put("isub", mSubscriptionController); doReturn(mSubscriptionController).when(mSubscriptionController) .queryLocalInterface(anyString()); UserInfo userInfo = new UserInfo(UserHandle.myUserId(), "" /* name */, 0 /* flags */); doReturn(userInfo).when(mIActivityManager).getCurrentUser(); doReturn(true).when(mLocationManager).isLocationEnabledForUser(any(UserHandle.class)); CellIdentity cellIdentity = new CellIdentityGsm(-1, -1, -1, -1, null, null, null, null, Collections.emptyList()); mTelephonyRegistry.notifyCellLocationForSubscriber(subId, cellIdentity); processAllMessages(); // Listen to EVENT_CELL_LOCATION_CHANGED for the current user Id. int[] events = {TelephonyCallback.EVENT_CELL_LOCATION_CHANGED}; mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); // Broadcast ACTION_USER_SWITCHED for USER_SYSTEM. Callback should be triggered. mCellLocation = null; mContext.sendBroadcast(new Intent(Intent.ACTION_USER_SWITCHED)); processAllMessages(); assertEquals(cellIdentity.asCellLocation(), mCellLocation); // Broadcast ACTION_USER_SWITCHED for the current user Id + 1. Callback shouldn't be // triggered. userInfo.id++; mCellLocation = null; mContext.sendBroadcast(new Intent(Intent.ACTION_USER_SWITCHED)); processAllMessages(); assertEquals(null, mCellLocation); } private void assertSecurityExceptionThrown(int[] event) { try { mTelephonyRegistry.listenWithEventList( Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkCapabilities; import android.net.vcn.VcnManager; Loading Loading @@ -326,6 +327,8 @@ public abstract class TelephonyTest { protected LinkBandwidthEstimator mLinkBandwidthEstimator; @Mock protected PinStorage mPinStorage; @Mock protected LocationManager mLocationManager; protected ActivityManager mActivityManager; protected ImsCallProfile mImsCallProfile; Loading Loading @@ -484,6 +487,7 @@ public abstract class TelephonyTest { mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); mVcnManager = mContext.getSystemService(VcnManager.class); mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); //mTelephonyComponentFactory doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory).inject(anyString()); Loading