use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionMonitorTest method testNoDefaultNotifications.
/**
* Try tests with no default set
*/
@SmallTest
public void testNoDefaultNotifications() throws Exception {
final int numPhones = 2;
final ContextFixture contextFixture = new ContextFixture();
final Context context = contextFixture.getTestDouble();
ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
SubscriptionControllerMock subController = new SubscriptionControllerMock(context, telRegistry, numPhones);
SubscriptionMonitor testedSubMonitor = new SubscriptionMonitor(telRegistry, context, subController, numPhones);
TestHandler testHandler = TestHandler.makeHandler();
Object subChangedObject = new Object();
testHandler.setSubscriptionChangedObject(subChangedObject);
Object defaultSubChangedObject = new Object();
testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
final int PHONE_ID = 0;
final int FIRST_SUB_ID = 0;
final int SECOND_SUB_ID = 1;
subController.setDefaultDataSubId(INVALID_SUBSCRIPTION_ID);
subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
testHandler.blockTilIdle();
if (testHandler.getSubscriptionChangedCount() != 3) {
fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != 3");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != 1");
}
testHandler.die();
}
use of com.android.internal.telephony.mocks.TelephonyRegistryMock 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.mocks.TelephonyRegistryMock 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();
}
use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionMonitorTest method testSubBeforeDefaultNotifications.
/**
* Try setting the subIds first and then the default subId and verify we get all our
* notifications.
*/
@SmallTest
public void testSubBeforeDefaultNotifications() throws Exception {
final int numPhones = 2;
final ContextFixture contextFixture = new ContextFixture();
final Context context = contextFixture.getTestDouble();
ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
SubscriptionControllerMock subController = new SubscriptionControllerMock(context, telRegistry, numPhones);
SubscriptionMonitor testedSubMonitor = new SubscriptionMonitor(telRegistry, context, subController, numPhones);
TestHandler testHandler = TestHandler.makeHandler();
Object subChangedObject = new Object();
testHandler.setSubscriptionChangedObject(subChangedObject);
Object defaultSubChangedObject = new Object();
testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
final int PHONE_ID = 0;
final int SECOND_PHONE_ID = 1;
final int FIRST_SUB_ID = 0;
final int SECOND_SUB_ID = 1;
testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
subController.setSlotSubId(PHONE_ID, -2);
subController.setSlotSubId(SECOND_PHONE_ID, -3);
testHandler.blockTilIdle();
// should get one for registration and 1 for the change
if (testHandler.getSubscriptionChangedCount() != 2) {
fail("test1 " + testHandler.getSubscriptionChangedCount() + " != 2");
}
// should get one for registration
if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
fail("test2 " + testHandler.getDefaultSubscriptionChangedCount() + " != 1");
}
subController.setDefaultDataSubId(FIRST_SUB_ID);
testHandler.blockTilIdle();
// no change
if (testHandler.getSubscriptionChangedCount() != 2) {
fail("test3 " + testHandler.getSubscriptionChangedCount() + " != 2");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
fail("test4 " + testHandler.getDefaultSubscriptionChangedCount() + " != 1");
}
subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
testHandler.blockTilIdle();
// should get one more default-change-notification
if (testHandler.getSubscriptionChangedCount() != 3) {
fail("test5 " + testHandler.getSubscriptionChangedCount() + " != 3");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
fail("test6 " + testHandler.getDefaultSubscriptionChangedCount() + " != 2");
}
subController.setDefaultDataSubId(SECOND_SUB_ID);
testHandler.blockTilIdle();
// should get one more default-change-notification
if (testHandler.getSubscriptionChangedCount() != 3) {
fail("test7 " + testHandler.getSubscriptionChangedCount() + " != 3");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
fail("test8 " + testHandler.getDefaultSubscriptionChangedCount() + " != 3");
}
subController.setDefaultDataSubId(FIRST_SUB_ID);
testHandler.blockTilIdle();
// should get one more default-change-notification
if (testHandler.getSubscriptionChangedCount() != 3) {
fail("test9 " + testHandler.getSubscriptionChangedCount() + " != 3");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 4) {
fail("test10 " + testHandler.getDefaultSubscriptionChangedCount() + " != 4");
}
testHandler.die();
}
use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionMonitorTest method testNoSubChange.
@SmallTest
public void testNoSubChange() throws Exception {
String TAG = "testNoSubChange";
final int numPhones = 2;
final ContextFixture contextFixture = new ContextFixture();
final Context context = contextFixture.getTestDouble();
ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
SubscriptionControllerMock subController = new SubscriptionControllerMock(context, telRegistry, numPhones);
SubscriptionMonitor testedSubMonitor = new SubscriptionMonitor(telRegistry, context, subController, numPhones);
TestHandler testHandler = TestHandler.makeHandler();
Object subChangedObject = new Object();
testHandler.setSubscriptionChangedObject(subChangedObject);
Object defaultSubChangedObject = new Object();
testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
final int PHONE_ID = 0;
final int FIRST_SUB_ID = 0;
final int SECOND_SUB_ID = 1;
testHandler.blockTilIdle();
Rlog.d(TAG, "1");
testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
testHandler.blockTilIdle();
Rlog.d(TAG, "2");
testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
testHandler.blockTilIdle();
Rlog.d(TAG, "3");
subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
testHandler.blockTilIdle();
Rlog.d(TAG, "4");
subController.setDefaultDataSubId(FIRST_SUB_ID);
testHandler.blockTilIdle();
Rlog.d(TAG, "5");
if (testHandler.getSubscriptionChangedCount() != 2) {
fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != 2");
}
// 1 gained for reg and 1 for the setting above
if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != 2");
}
Rlog.d(TAG, "6");
// cause a notification that subscription info changed
subController.notifySubscriptionInfoChanged();
testHandler.blockTilIdle();
Rlog.d(TAG, "7");
if (testHandler.getSubscriptionChangedCount() != 2) {
fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != 2");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != 2");
}
// now change the default - should cause a default notification (we lost the default)
subController.setDefaultDataSubId(SECOND_SUB_ID);
testHandler.blockTilIdle();
Rlog.d(TAG, "8");
if (testHandler.getSubscriptionChangedCount() != 2) {
fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != 2");
}
if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != 3");
}
testHandler.die();
}
Aggregations