Loading tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java +6 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.Network; import android.net.Uri; Loading Loading @@ -275,6 +276,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 Loading @@ -306,6 +309,8 @@ public class ContextFixture implements TestFixture<Context> { return Context.KEYGUARD_SERVICE; } else if (serviceClass == VcnManager.class) { return Context.VCN_MANAGEMENT_SERVICE; } else if (serviceClass == LocationManager.class) { return Context.LOCATION_SERVICE; } return super.getSystemServiceName(serviceClass); } Loading Loading @@ -654,6 +659,7 @@ public class ContextFixture implements TestFixture<Context> { private final PowerWhitelistManager mPowerWhitelistManager = mock(PowerWhitelistManager.class); private final KeyguardManager mKeyguardManager = mock(KeyguardManager.class); private final VcnManager mVcnManager = mock(VcnManager.class); private final LocationManager mLocationManager = mock(LocationManager.class); private final ContentProvider mContentProvider = spy(new FakeContentProvider()); Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +62 −1 Original line number Diff line number Diff line Loading @@ -27,16 +27,24 @@ import static android.telephony.TelephonyManager.RADIO_POWER_UNAVAILABLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; 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 @@ -63,6 +71,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 @@ -83,6 +92,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private int mSrvccState = -1; private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private List<PhysicalChannelConfig> mPhysicalChannelConfigs; private CellLocation mCellLocation; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -149,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 @@ -194,6 +205,11 @@ public class TelephonyRegistryTest extends TelephonyTest { public void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs) { mPhysicalChannelConfigs = configs; } @Override public void onCellLocationChanged(CellLocation location) { mCellLocation = location; } } private void addTelephonyRegistryService() { Loading Loading @@ -585,6 +601,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 @@ -320,6 +321,8 @@ public abstract class TelephonyTest { protected ImsStats mImsStats; @Mock protected PinStorage mPinStorage; @Mock protected LocationManager mLocationManager; protected ActivityManager mActivityManager; protected ImsCallProfile mImsCallProfile; Loading Loading @@ -478,6 +481,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 +6 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.Network; import android.net.Uri; Loading Loading @@ -275,6 +276,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 Loading @@ -306,6 +309,8 @@ public class ContextFixture implements TestFixture<Context> { return Context.KEYGUARD_SERVICE; } else if (serviceClass == VcnManager.class) { return Context.VCN_MANAGEMENT_SERVICE; } else if (serviceClass == LocationManager.class) { return Context.LOCATION_SERVICE; } return super.getSystemServiceName(serviceClass); } Loading Loading @@ -654,6 +659,7 @@ public class ContextFixture implements TestFixture<Context> { private final PowerWhitelistManager mPowerWhitelistManager = mock(PowerWhitelistManager.class); private final KeyguardManager mKeyguardManager = mock(KeyguardManager.class); private final VcnManager mVcnManager = mock(VcnManager.class); private final LocationManager mLocationManager = mock(LocationManager.class); private final ContentProvider mContentProvider = spy(new FakeContentProvider()); Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +62 −1 Original line number Diff line number Diff line Loading @@ -27,16 +27,24 @@ import static android.telephony.TelephonyManager.RADIO_POWER_UNAVAILABLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; 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 @@ -63,6 +71,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 @@ -83,6 +92,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private int mSrvccState = -1; private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private List<PhysicalChannelConfig> mPhysicalChannelConfigs; private CellLocation mCellLocation; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -149,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 @@ -194,6 +205,11 @@ public class TelephonyRegistryTest extends TelephonyTest { public void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs) { mPhysicalChannelConfigs = configs; } @Override public void onCellLocationChanged(CellLocation location) { mCellLocation = location; } } private void addTelephonyRegistryService() { Loading Loading @@ -585,6 +601,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 @@ -320,6 +321,8 @@ public abstract class TelephonyTest { protected ImsStats mImsStats; @Mock protected PinStorage mPinStorage; @Mock protected LocationManager mLocationManager; protected ActivityManager mActivityManager; protected ImsCallProfile mImsCallProfile; Loading Loading @@ -478,6 +481,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