use of com.android.internal.telephony.mocks.SubscriptionControllerMock in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionMonitorTest method testMultiRegUnregistration.
/**
* Test duplicate registrations - both should survive
* Also test duplicate unreg - shouldn't crash..
*/
@SmallTest
public void testMultiRegUnregistration() 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;
testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
subController.setDefaultDataSubId(FIRST_SUB_ID);
subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
subController.setDefaultDataSubId(SECOND_SUB_ID);
subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
testHandler.blockTilIdle();
// should get 1 for each registration and 4 for the two events
if (testHandler.getSubscriptionChangedCount() != 6) {
fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != 6");
}
// 2 for the setSlotSubId (regain default)
if (testHandler.getDefaultSubscriptionChangedCount() != 8) {
fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != 8");
}
testedSubMonitor.unregisterForSubscriptionChanged(PHONE_ID, testHandler);
testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(PHONE_ID, testHandler);
testedSubMonitor.unregisterForSubscriptionChanged(PHONE_ID, testHandler);
testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(PHONE_ID, testHandler);
testHandler.die();
}
Aggregations