use of com.android.internal.telephony.mocks.ConnectivityServiceMock 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.ConnectivityServiceMock 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