use of com.android.internal.telephony.test.SimulatedCommands in project android_frameworks_opt_telephony by LineageOS.
the class PhoneSwitcherTest method testPrioritization.
/**
* Test a multi-sim case with limited active phones:
* - lose default via default sub change
* - lose default via sub->phone change
* - gain default via sub->phone change
* - gain default via default sub change
* - lose default network request
* - gain subscription-specific request
* - lose via sub->phone change
* - gain via sub->phone change
* - lose subscription-specific request
* - tear down low priority phone when new request comes in
* - tear down low priority phone when sub change causes split
* - bring up low priority phone when sub change causes join
* - don't switch phones when in emergency mode
*/
@SmallTest
public void testPrioritization() throws Exception {
mTestName = "testPrioritization";
final int numPhones = 2;
final int maxActivePhones = 1;
final HandlerThread handlerThread = new HandlerThread("PhoneSwitcherTestThread");
handlerThread.start();
final ContextFixture contextFixture = new ContextFixture();
String[] networkConfigString = getContext().getResources().getStringArray(com.android.internal.R.array.networkAttributes);
contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes, networkConfigString);
final Context contextMock = contextFixture.getTestDouble();
final ConnectivityServiceMock connectivityServiceMock = new ConnectivityServiceMock(contextMock);
final ConnectivityManager cm = new ConnectivityManager(contextMock, connectivityServiceMock);
contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
final ITelephonyRegistry.Stub telRegistryMock = new TelephonyRegistryMock();
final SubscriptionControllerMock subControllerMock = new SubscriptionControllerMock(contextMock, telRegistryMock, numPhones);
final SimulatedCommands[] commandsInterfaces = new SimulatedCommands[numPhones];
final PhoneMock[] phones = new PhoneMock[numPhones];
for (int i = 0; i < numPhones; i++) {
commandsInterfaces[i] = new SimulatedCommands();
}
PhoneSwitcher phoneSwitcher = new PhoneSwitcher(maxActivePhones, numPhones, contextMock, subControllerMock, handlerThread.getLooper(), telRegistryMock, commandsInterfaces, phones);
TestHandler testHandler = TestHandler.makeHandler();
Object activePhoneSwitchObject = new Object();
testHandler.setActivePhoneSwitchObject(activePhoneSwitchObject);
connectivityServiceMock.addDefaultRequest();
subControllerMock.setSlotSubId(0, 0);
subControllerMock.setSlotSubId(1, 1);
subControllerMock.setDefaultDataSubId(0);
waitABit();
phoneSwitcher.registerForActivePhoneSwitch(0, testHandler, TestHandler.ACTIVE_PHONE_SWITCH, activePhoneSwitchObject);
waitABit();
// verify initial conditions
if (testHandler.getActivePhoneSwitchCount() != 1) {
fail("Initial conditions not met: ActivePhoneSwitchCount not 1! " + testHandler.getActivePhoneSwitchCount());
}
if (commandsInterfaces[0].isDataAllowed() == false)
fail("data not allowed");
if (commandsInterfaces[1].isDataAllowed())
fail("data allowed");
// now start a higher priority conneciton on the other sub
NetworkRequest request = makeSubSpecificMmsRequest(connectivityServiceMock, 1);
waitABit();
if (testHandler.getActivePhoneSwitchCount() != 2) {
fail("after gain of network request, ActivePhoneSwitchCount not 2!");
}
if (commandsInterfaces[0].isDataAllowed())
fail("data allowed");
if (commandsInterfaces[1].isDataAllowed() == false)
fail("data not allowed");
for (int i = 0; i < numPhones; i++) {
commandsInterfaces[i].dispose();
}
connectivityServiceMock.die();
testHandler.die();
handlerThread.quit();
}
use of com.android.internal.telephony.test.SimulatedCommands in project android_frameworks_opt_telephony by LineageOS.
the class TelephonyTest method setUp.
protected void setUp(String tag) throws Exception {
TAG = tag;
MockitoAnnotations.initMocks(this);
TelephonyManager.disableServiceHandleCaching();
SubscriptionController.disableCaching();
mPhones = new Phone[] { mPhone };
mImsCallProfile = new ImsCallProfile();
mImsCallProfile.setCallerNumberVerificationStatus(ImsCallProfile.VERIFICATION_STATUS_PASSED);
mSimulatedCommands = new SimulatedCommands();
mContextFixture = new ContextFixture();
mContext = mContextFixture.getTestDouble();
mFakeBlockedNumberContentProvider = new FakeBlockedNumberContentProvider();
((MockContentResolver) mContext.getContentResolver()).addProvider(BlockedNumberContract.AUTHORITY, mFakeBlockedNumberContentProvider);
mPhone.mCi = mSimulatedCommands;
mCT.mCi = mSimulatedCommands;
doReturn(mUiccCard).when(mPhone).getUiccCard();
doReturn(mUiccProfile).when(mUiccCard).getUiccProfile();
mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
mTelephonyRegistryManager = (TelephonyRegistryManager) mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
mSubscriptionManager = (SubscriptionManager) mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
mEuiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
mPackageManager = mContext.getPackageManager();
mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
mCarrierConfigManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
// mTelephonyComponentFactory
doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory).inject(anyString());
doReturn(mSST).when(mTelephonyComponentFactory).makeServiceStateTracker(nullable(GsmCdmaPhone.class), nullable(CommandsInterface.class));
doReturn(mEmergencyNumberTracker).when(mTelephonyComponentFactory).makeEmergencyNumberTracker(nullable(Phone.class), nullable(CommandsInterface.class));
doReturn(getTestEmergencyNumber()).when(mEmergencyNumberTracker).getEmergencyNumber(any());
doReturn(mUiccProfile).when(mTelephonyComponentFactory).makeUiccProfile(nullable(Context.class), nullable(CommandsInterface.class), nullable(IccCardStatus.class), anyInt(), nullable(UiccCard.class), nullable(Object.class));
doReturn(mCT).when(mTelephonyComponentFactory).makeGsmCdmaCallTracker(nullable(GsmCdmaPhone.class));
doReturn(mIccPhoneBookIntManager).when(mTelephonyComponentFactory).makeIccPhoneBookInterfaceManager(nullable(Phone.class));
doReturn(mDcTracker).when(mTelephonyComponentFactory).makeDcTracker(nullable(Phone.class), anyInt());
doReturn(mDisplayInfoController).when(mTelephonyComponentFactory).makeDisplayInfoController(nullable(Phone.class));
doReturn(mWspTypeDecoder).when(mTelephonyComponentFactory).makeWspTypeDecoder(nullable(byte[].class));
doReturn(mImsCT).when(mTelephonyComponentFactory).makeImsPhoneCallTracker(nullable(ImsPhone.class));
doReturn(mCdmaSSM).when(mTelephonyComponentFactory).getCdmaSubscriptionSourceManagerInstance(nullable(Context.class), nullable(CommandsInterface.class), nullable(Handler.class), anyInt(), nullable(Object.class));
doReturn(mImsExternalCallTracker).when(mTelephonyComponentFactory).makeImsExternalCallTracker(nullable(ImsPhone.class));
doReturn(mAppSmsManager).when(mTelephonyComponentFactory).makeAppSmsManager(nullable(Context.class));
doReturn(mCarrierSignalAgent).when(mTelephonyComponentFactory).makeCarrierSignalAgent(nullable(Phone.class));
doReturn(mCarrierActionAgent).when(mTelephonyComponentFactory).makeCarrierActionAgent(nullable(Phone.class));
doReturn(mDeviceStateMonitor).when(mTelephonyComponentFactory).makeDeviceStateMonitor(nullable(Phone.class));
doReturn(mTransportManager).when(mTelephonyComponentFactory).makeTransportManager(nullable(Phone.class));
doReturn(mNitzStateMachine).when(mTelephonyComponentFactory).makeNitzStateMachine(nullable(GsmCdmaPhone.class));
doReturn(mLocaleTracker).when(mTelephonyComponentFactory).makeLocaleTracker(nullable(Phone.class), nullable(NitzStateMachine.class), nullable(Looper.class));
doReturn(mDataEnabledSettings).when(mTelephonyComponentFactory).makeDataEnabledSettings(nullable(Phone.class));
doReturn(mEriManager).when(mTelephonyComponentFactory).makeEriManager(nullable(Phone.class), anyInt());
// mPhone
doReturn(mContext).when(mPhone).getContext();
doReturn(mContext).when(mImsPhone).getContext();
doReturn(true).when(mPhone).getUnitTestMode();
doReturn(mUiccProfile).when(mPhone).getIccCard();
doReturn(mServiceState).when(mPhone).getServiceState();
doReturn(mServiceState).when(mImsPhone).getServiceState();
doReturn(mPhone).when(mImsPhone).getDefaultPhone();
doReturn(true).when(mPhone).isPhoneTypeGsm();
doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType();
doReturn(mCT).when(mPhone).getCallTracker();
doReturn(mSST).when(mPhone).getServiceStateTracker();
doReturn(mDeviceStateMonitor).when(mPhone).getDeviceStateMonitor();
doReturn(mDisplayInfoController).when(mPhone).getDisplayInfoController();
doReturn(mEmergencyNumberTracker).when(mPhone).getEmergencyNumberTracker();
doReturn(mCarrierSignalAgent).when(mPhone).getCarrierSignalAgent();
doReturn(mCarrierActionAgent).when(mPhone).getCarrierActionAgent();
doReturn(mAppSmsManager).when(mPhone).getAppSmsManager();
doReturn(mIccSmsInterfaceManager).when(mPhone).getIccSmsInterfaceManager();
doReturn(mTransportManager).when(mPhone).getTransportManager();
doReturn(mDataEnabledSettings).when(mPhone).getDataEnabledSettings();
doReturn(mDcTracker).when(mPhone).getDcTracker(anyInt());
doReturn(mCarrierPrivilegesTracker).when(mPhone).getCarrierPrivilegesTracker();
doReturn(mVoiceCallSessionStats).when(mPhone).getVoiceCallSessionStats();
doReturn(mVoiceCallSessionStats).when(mImsPhone).getVoiceCallSessionStats();
mIccSmsInterfaceManager.mDispatchersController = mSmsDispatchersController;
// mUiccController
doReturn(mUiccCardApplication3gpp).when(mUiccController).getUiccCardApplication(anyInt(), eq(UiccController.APP_FAM_3GPP));
doReturn(mUiccCardApplication3gpp2).when(mUiccController).getUiccCardApplication(anyInt(), eq(UiccController.APP_FAM_3GPP2));
doReturn(mUiccCardApplicationIms).when(mUiccController).getUiccCardApplication(anyInt(), eq(UiccController.APP_FAM_IMS));
doAnswer(new Answer<IccRecords>() {
public IccRecords answer(InvocationOnMock invocation) {
switch((Integer) invocation.getArguments()[1]) {
case UiccController.APP_FAM_3GPP:
return mSimRecords;
case UiccController.APP_FAM_3GPP2:
return mRuimRecords;
case UiccController.APP_FAM_IMS:
return mIsimUiccRecords;
default:
logd("Unrecognized family " + invocation.getArguments()[1]);
return null;
}
}
}).when(mUiccController).getIccRecords(anyInt(), anyInt());
// UiccCardApplication
doReturn(mSimRecords).when(mUiccCardApplication3gpp).getIccRecords();
doReturn(mRuimRecords).when(mUiccCardApplication3gpp2).getIccRecords();
doReturn(mIsimUiccRecords).when(mUiccCardApplicationIms).getIccRecords();
// mUiccProfile
doReturn(mSimRecords).when(mUiccProfile).getIccRecords();
doAnswer(new Answer<IccRecords>() {
public IccRecords answer(InvocationOnMock invocation) {
return (mPhone.isPhoneTypeGsm()) ? mSimRecords : mRuimRecords;
}
}).when(mUiccProfile).getIccRecords();
// mUiccProfile
doReturn(mUiccCardApplication3gpp).when(mUiccProfile).getApplication(eq(UiccController.APP_FAM_3GPP));
doReturn(mUiccCardApplication3gpp2).when(mUiccProfile).getApplication(eq(UiccController.APP_FAM_3GPP2));
doReturn(mUiccCardApplicationIms).when(mUiccProfile).getApplication(eq(UiccController.APP_FAM_IMS));
// SMS
doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
doReturn(true).when(mSmsUsageMonitor).check(nullable(String.class), anyInt());
doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
doReturn(true).when(mTelephonyManager).getSmsSendCapableForPhone(anyInt(), anyBoolean());
// Misc
doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_UMTS).when(mServiceState).getRilDataRadioTechnology();
doReturn(mPhone).when(mCT).getPhone();
mImsManagerInstances.put(mPhone.getPhoneId(), mImsManager);
doReturn(mImsEcbm).when(mImsManager).getEcbmInterface();
doReturn(mPhone).when(mInboundSmsHandler).getPhone();
doReturn(mImsCallProfile).when(mImsCall).getCallProfile();
doReturn(mIBinder).when(mIIntentSender).asBinder();
doReturn(mIIntentSender).when(mIActivityManager).getIntentSenderWithFeature(anyInt(), nullable(String.class), nullable(String.class), nullable(IBinder.class), nullable(String.class), anyInt(), nullable(Intent[].class), nullable(String[].class), anyInt(), nullable(Bundle.class), anyInt());
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
doReturn(true).when(mTelephonyManager).isDataCapable();
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
doReturn(mServiceState).when(mSST).getServiceState();
mSST.mSS = mServiceState;
mSST.mRestrictedState = mRestrictedState;
mServiceManagerMockedServices.put("connectivity_metrics_logger", mConnMetLoggerBinder);
mServiceManagerMockedServices.put("package", mMockPackageManager);
mServiceManagerMockedServices.put("permissionmgr", mMockPermissionManager);
logd("mMockPermissionManager replaced");
doReturn(new int[] { AccessNetworkConstants.TRANSPORT_TYPE_WWAN, AccessNetworkConstants.TRANSPORT_TYPE_WLAN }).when(mTransportManager).getAvailableTransports();
doReturn(AccessNetworkConstants.TRANSPORT_TYPE_WWAN).when(mTransportManager).getCurrentTransport(anyInt());
doReturn(true).when(mDataEnabledSettings).isDataEnabled();
doReturn(true).when(mDataEnabledSettings).isDataEnabled(anyInt());
doReturn(true).when(mDataEnabledSettings).isInternalDataEnabled();
doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(anyInt(), anyInt());
doReturn(new HalVersion(1, 4)).when(mPhone).getHalVersion();
// SIM
doReturn(1).when(mTelephonyManager).getSimCount();
doReturn(1).when(mTelephonyManager).getPhoneCount();
doReturn(1).when(mTelephonyManager).getActiveModemCount();
// Have getMaxPhoneCount always return the same value with getPhoneCount by default.
doAnswer((invocation) -> Math.max(mTelephonyManager.getActiveModemCount(), mTelephonyManager.getPhoneCount())).when(mTelephonyManager).getSupportedModemCount();
doReturn(mStatsManager).when(mContext).getSystemService(eq(Context.NETWORK_STATS_SERVICE));
// Data
// Initial state is: userData enabled, provisioned.
ContentResolver resolver = mContext.getContentResolver();
Settings.Global.putInt(resolver, Settings.Global.MOBILE_DATA, 1);
Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1);
Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, 1);
// CellularNetworkValidator
doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mCellularNetworkValidator).getSubIdInValidation();
doReturn(true).when(mCellularNetworkValidator).isValidationFeatureSupported();
// Metrics
doReturn(null).when(mContext).getFileStreamPath(anyString());
doReturn(mPersistAtomsStorage).when(mMetricsCollector).getAtomsStorage();
// Use reflection to mock singletons
replaceInstance(CallManager.class, "INSTANCE", null, mCallManager);
replaceInstance(TelephonyComponentFactory.class, "sInstance", null, mTelephonyComponentFactory);
replaceInstance(UiccController.class, "mInstance", null, mUiccController);
replaceInstance(CdmaSubscriptionSourceManager.class, "sInstance", null, mCdmaSSM);
replaceInstance(ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances);
replaceInstance(SubscriptionController.class, "sInstance", null, mSubscriptionController);
replaceInstance(ProxyController.class, "sProxyController", null, mProxyController);
replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, mIActivityManagerSingleton);
replaceInstance(CdmaSubscriptionSourceManager.class, "mCdmaSubscriptionSourceChangedRegistrants", mCdmaSSM, mRegistrantList);
replaceInstance(SimulatedCommandsVerifier.class, "sInstance", null, mSimulatedCommandsVerifier);
replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, mIActivityManager);
replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices);
replaceInstance(IntentBroadcaster.class, "sIntentBroadcaster", null, mIntentBroadcaster);
replaceInstance(TelephonyManager.class, "sInstance", null, mContext.getSystemService(Context.TELEPHONY_SERVICE));
replaceInstance(TelephonyManager.class, "sServiceHandleCacheEnabled", null, false);
replaceInstance(PhoneFactory.class, "sMadeDefaults", null, true);
replaceInstance(PhoneFactory.class, "sPhone", null, mPhone);
replaceInstance(PhoneFactory.class, "sPhones", null, mPhones);
replaceInstance(PhoneFactory.class, "sSubInfoRecordUpdater", null, mSubInfoRecordUpdater);
replaceInstance(RadioConfig.class, "sRadioConfig", null, mMockRadioConfig);
replaceInstance(PhoneConfigurationManager.class, "sInstance", null, mPhoneConfigurationManager);
replaceInstance(CellularNetworkValidator.class, "sInstance", null, mCellularNetworkValidator);
replaceInstance(MultiSimSettingController.class, "sInstance", null, mMultiSimSettingController);
replaceInstance(SubscriptionInfoUpdater.class, "sIsSubInfoInitialized", null, true);
replaceInstance(PhoneFactory.class, "sCommandsInterfaces", null, new CommandsInterface[] { mSimulatedCommands });
replaceInstance(PhoneFactory.class, "sMetricsCollector", null, mMetricsCollector);
assertNotNull("Failed to set up SubscriptionController singleton", SubscriptionController.getInstance());
setReady(false);
// create default TestableLooper for test and add to list of monitored loopers
mTestableLooper = TestableLooper.get(TelephonyTest.this);
if (mTestableLooper != null) {
monitorTestableLooper(mTestableLooper);
}
}
use of com.android.internal.telephony.test.SimulatedCommands in project android_frameworks_opt_telephony by LineageOS.
the class PhoneSwitcherTest method testHigherPriorityDefault.
/**
* Verify we don't send spurious DATA_ALLOWED calls when another NetworkFactory
* wins (ie, switch to wifi).
*/
@SmallTest
public void testHigherPriorityDefault() throws Exception {
mTestName = "testPrioritization";
final int numPhones = 2;
final int maxActivePhones = 1;
final HandlerThread handlerThread = new HandlerThread("PhoneSwitcherTestThread");
handlerThread.start();
final ContextFixture contextFixture = new ContextFixture();
String[] networkConfigString = getContext().getResources().getStringArray(com.android.internal.R.array.networkAttributes);
contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes, networkConfigString);
final Context contextMock = contextFixture.getTestDouble();
final ConnectivityServiceMock connectivityServiceMock = new ConnectivityServiceMock(contextMock);
final ConnectivityManager cm = new ConnectivityManager(contextMock, connectivityServiceMock);
contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
final ITelephonyRegistry.Stub telRegistryMock = new TelephonyRegistryMock();
final SubscriptionControllerMock subControllerMock = new SubscriptionControllerMock(contextMock, telRegistryMock, numPhones);
final SimulatedCommands[] commandsInterfaces = new SimulatedCommands[numPhones];
final PhoneMock[] phones = new PhoneMock[numPhones];
for (int i = 0; i < numPhones; i++) {
commandsInterfaces[i] = new SimulatedCommands();
}
PhoneSwitcher phoneSwitcher = new PhoneSwitcher(maxActivePhones, numPhones, contextMock, subControllerMock, handlerThread.getLooper(), telRegistryMock, commandsInterfaces, phones);
TestHandler testHandler = TestHandler.makeHandler();
Object activePhoneSwitchObject = new Object();
testHandler.setActivePhoneSwitchObject(activePhoneSwitchObject);
connectivityServiceMock.addDefaultRequest();
subControllerMock.setSlotSubId(0, 0);
subControllerMock.setSlotSubId(1, 1);
subControllerMock.setDefaultDataSubId(0);
waitABit();
// Phone 0 should be active
if (commandsInterfaces[0].isDataAllowed() == false)
fail("data not allowed");
if (commandsInterfaces[1].isDataAllowed())
fail("data allowed");
connectivityServiceMock.setCurrentScoreForRequest(connectivityServiceMock.defaultRequest, 100);
waitABit();
// should be no change
if (commandsInterfaces[0].isDataAllowed() == false)
fail("data not allowed");
if (commandsInterfaces[1].isDataAllowed())
fail("data allowed");
connectivityServiceMock.setCurrentScoreForRequest(connectivityServiceMock.defaultRequest, 0);
waitABit();
// should be no change
if (commandsInterfaces[0].isDataAllowed() == false)
fail("data not allowed");
if (commandsInterfaces[1].isDataAllowed())
fail("data allowed");
for (int i = 0; i < numPhones; i++) {
commandsInterfaces[i].dispose();
}
connectivityServiceMock.die();
testHandler.die();
handlerThread.quit();
}
Aggregations