Search in sources :

Example 1 with TelephonyRegistryMock

use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionMonitorTest method testSimSwapNotifications.

/**
 * It turns out when we swap sims on a single sim we do something like:
 *   Phone[0] subId  1 -> -2
 *   Phone[0] subId -2 ->  2
 *   Default change  1 ->  2
 * Try that and verify we get all the subId and default changes we expect.
 */
@SmallTest
public void testSimSwapNotifications() throws Exception {
    final int numPhones = 1;
    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);
    subController.setSlotSubId(PHONE_ID, -2);
    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.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 3) {
        fail("test3 " + testHandler.getSubscriptionChangedCount() + " != 3");
    }
    subController.setDefaultDataSubId(FIRST_SUB_ID);
    testHandler.blockTilIdle();
    if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
        fail("test4 " + testHandler.getDefaultSubscriptionChangedCount() + " != 2");
    }
    // ok - now for the sim swap
    subController.setSlotSubId(PHONE_ID, -2);
    testHandler.blockTilIdle();
    if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
        fail("test5 " + testHandler.getDefaultSubscriptionChangedCount() + " != 3");
    }
    if (testHandler.getSubscriptionChangedCount() != 4) {
        fail("test6 " + testHandler.getSubscriptionChangedCount() + " != 4");
    }
    subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 5) {
        fail("test7 " + testHandler.getSubscriptionChangedCount() + " != 5");
    }
    subController.setDefaultDataSubId(SECOND_SUB_ID);
    testHandler.blockTilIdle();
    if (testHandler.getDefaultSubscriptionChangedCount() != 4) {
        fail("test8 " + testHandler.getDefaultSubscriptionChangedCount() + " != 4");
    }
    // no change
    if (testHandler.getSubscriptionChangedCount() != 5) {
        fail("test9 " + testHandler.getSubscriptionChangedCount() + " != 5");
    }
    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)

Example 2 with TelephonyRegistryMock

use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionMonitorTest method testEventFloodNotifications.

/**
 * Try event flood while registered - verify receive all.
 */
@SmallTest
public void testEventFloodNotifications() 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);
    final int LOOP_COUNT = 1;
    for (int i = 0; i < LOOP_COUNT; i++) {
        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 one for registration + 2 per loop
    if (testHandler.getSubscriptionChangedCount() != 1 + (2 * LOOP_COUNT)) {
        fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != " + (1 + (2 * LOOP_COUNT)));
    }
    // should get one for registration + 3 for first loop + 4 for subsequent loops
    if (testHandler.getDefaultSubscriptionChangedCount() != (4 * LOOP_COUNT)) {
        fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != " + (4 * LOOP_COUNT));
    }
    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)

Example 3 with TelephonyRegistryMock

use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionMonitorTest method testSpuriousNotifications.

/**
 * Try to force spurious notifications - register/unregister in tight loop with
 * events happening in the unregistered gap.
 */
@SmallTest
public void testSpuriousNotifications() 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);
    final int LOOP_COUNT = 1000;
    for (int i = 0; i < LOOP_COUNT; i++) {
        testedSubMonitor.unregisterForSubscriptionChanged(PHONE_ID, testHandler);
        testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(PHONE_ID, testHandler);
        subController.setDefaultDataSubId(FIRST_SUB_ID);
        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
        subController.setDefaultDataSubId(SECOND_SUB_ID);
        subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
    }
    testHandler.blockTilIdle();
    // should get one for every registration
    if (testHandler.getSubscriptionChangedCount() != 1 + LOOP_COUNT) {
        fail("getSubscriptionChangedCount reported " + testHandler.getSubscriptionChangedCount() + " != " + (1 + LOOP_COUNT));
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 1 + LOOP_COUNT) {
        fail("getDefaultSubscriptionChangedCount reported " + testHandler.getDefaultSubscriptionChangedCount() + " != " + (1 + LOOP_COUNT));
    }
    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)

Example 4 with TelephonyRegistryMock

use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionMonitorTest method testRegister.

/**
 * Register and unregister normally.
 * Verify register worked by causing an event.
 * Verify unregister by causing another event.
 */
@SmallTest
public void testRegister() 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);
    // try events before registering
    subController.setDefaultDataSubId(0);
    subController.setSlotSubId(0, 0);
    if (testHandler.getSubscriptionChangedCount() != 0) {
        fail("pretest of SubscriptionChangedCount");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 0) {
        fail("pretest of DefaultSubscriptionChangedCount");
    }
    testedSubMonitor.registerForSubscriptionChanged(0, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 1) {
        fail("test1 of SubscriptionChangedCount");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 0) {
        fail("test1 of DefaultSubscriptionChangedCount");
    }
    testedSubMonitor.registerForDefaultDataSubscriptionChanged(0, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 1) {
        fail("test2 of SubscriptionChangedCount");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
        fail("test2 of DefaultSubscriptionChangedCount");
    }
    subController.setDefaultDataSubId(1);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 1) {
        fail("test3 of SubscriptionChangedCount, " + testHandler.getSubscriptionChangedCount() + " vs 1");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
        fail("test3 of DefaultSubscriptionChangedCount, " + testHandler.getDefaultSubscriptionChangedCount() + " vs 2");
    }
    subController.setSlotSubId(0, 1);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 2) {
        fail("test4 of SubscriptionChangedCount");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
        fail("test4 of DefaultSubscriptionChangedCount");
    }
    testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(0, testHandler);
    subController.setSlotSubId(0, 0);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 3) {
        fail("test5 of SubscriptionChangedCount, " + testHandler.getSubscriptionChangedCount() + " vs 3");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
        fail("test5 of DefaultSubscriptionChangedCount, " + testHandler.getDefaultSubscriptionChangedCount() + " vs 3");
    }
    testedSubMonitor.unregisterForSubscriptionChanged(0, testHandler);
    subController.setSlotSubId(0, 1);
    subController.setDefaultDataSubId(0);
    testHandler.blockTilIdle();
    if (testHandler.getSubscriptionChangedCount() != 3) {
        fail("test6 of SubscriptionChangedCount, " + testHandler.getSubscriptionChangedCount() + " vs 3");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
        fail("test6 of DefaultSubscriptionChangedCount, " + testHandler.getDefaultSubscriptionChangedCount() + " vs 3");
    }
    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)

Example 5 with TelephonyRegistryMock

use of com.android.internal.telephony.mocks.TelephonyRegistryMock in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionMonitorTest method testBadRegister.

/**
 * Bad register/unregisters
 *
 * Try phoneId that doesn't exist.
 * Cause an event and verify don't get notified.
 * Try to unregister multiple times.
 */
@SmallTest
public void testBadRegister() 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);
    try {
        testedSubMonitor.registerForSubscriptionChanged(-1, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
        fail("IllegalArgumentException expected with bad phoneId");
    } catch (IllegalArgumentException e) {
    }
    try {
        testedSubMonitor.registerForDefaultDataSubscriptionChanged(-1, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
        fail("IllegalArgumentException expected with bad phoneId");
    } catch (IllegalArgumentException e) {
    }
    try {
        testedSubMonitor.registerForSubscriptionChanged(numPhones, testHandler, TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
        fail("IllegalArgumentException expected with bad phoneId");
    } catch (IllegalArgumentException e) {
    }
    try {
        testedSubMonitor.registerForDefaultDataSubscriptionChanged(numPhones, testHandler, TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
        fail("IllegalArgumentException expected with bad phoneId");
    } catch (IllegalArgumentException e) {
    }
    subController.setDefaultDataSubId(0);
    subController.setSlotSubId(0, 0);
    if (testHandler.getSubscriptionChangedCount() != 0) {
        fail("getSubscriptionChangedCount reported non-zero!");
    }
    if (testHandler.getDefaultSubscriptionChangedCount() != 0) {
        fail("getDefaultSubscriptionChangedCount reported non-zero!");
    }
    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