Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0579827c authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "Note when we don't know a default phoneId" into nyc-dev

parents b0e90cc6 6899928d
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ public class SubscriptionMonitor {
        @Override
        public void onSubscriptionsChanged() {
            synchronized (mLock) {
                int newDefaultDataPhoneId = INVALID_PHONE_INDEX;
                for (int phoneId = 0; phoneId < mPhoneSubId.length; phoneId++) {
                    final int newSubId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
                    final int oldSubId = mPhoneSubId[phoneId];
@@ -128,12 +129,13 @@ public class SubscriptionMonitor {
                                    mDefaultDataSubChangedRegistrants[phoneId].size() +
                                    " registrants");
                            mDefaultDataSubChangedRegistrants[phoneId].notifyRegistrants();
                            if (newSubId == mDefaultDataSubId) {
                                mDefaultDataPhoneId = phoneId;
                        }
                    }
                    if (newSubId == mDefaultDataSubId) {
                        newDefaultDataPhoneId = phoneId;
                    }
                }
                mDefaultDataPhoneId = newDefaultDataPhoneId;
            }
        }
    };
@@ -161,7 +163,6 @@ public class SubscriptionMonitor {
                            }
                        }
                    }

                    if (newDefaultDataPhoneId != oldDefaultDataPhoneId) {
                        log("Default phoneId changed " + oldDefaultDataPhoneId + "->" +
                                newDefaultDataPhoneId + ", " +
+86 −0
Original line number Diff line number Diff line
@@ -752,4 +752,90 @@ public class SubscriptionMonitorTest extends AndroidTestCase {
        testHandler.die();
    }

    /**
     * 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();
    }
}