Search in sources :

Example 11 with SubscriptionControllerMock

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();
}
Also used : Context(android.content.Context) TelephonyRegistryMock(com.android.internal.telephony.mocks.TelephonyRegistryMock) SubscriptionControllerMock(com.android.internal.telephony.mocks.SubscriptionControllerMock) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

Context (android.content.Context)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)11 SubscriptionControllerMock (com.android.internal.telephony.mocks.SubscriptionControllerMock)11 TelephonyRegistryMock (com.android.internal.telephony.mocks.TelephonyRegistryMock)11 ConnectivityManager (android.net.ConnectivityManager)2 HandlerThread (android.os.HandlerThread)2 ConnectivityServiceMock (com.android.internal.telephony.mocks.ConnectivityServiceMock)2 SimulatedCommands (com.android.internal.telephony.test.SimulatedCommands)2 NetworkRequest (android.net.NetworkRequest)1