17a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt/*
27a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * Copyright (C) 2006 The Android Open Source Project
37a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt *
47a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License");
57a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * you may not use this file except in compliance with the License.
67a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * You may obtain a copy of the License at
77a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt *
87a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt *      http://www.apache.org/licenses/LICENSE-2.0
97a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt *
107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * Unless required by applicable law or agreed to in writing, software
117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS,
127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * See the License for the specific language governing permissions and
147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * limitations under the License.
157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt */
167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltpackage com.android.internal.telephony;
187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.MccTable;
227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.mocks.SubscriptionControllerMock;
237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.mocks.TelephonyRegistryMock;
247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.content.Context;
267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.AsyncResult;
277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.Handler;
287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.HandlerThread;
297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.Looper;
307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.Message;
317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.test.AndroidTestCase;
337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.test.suitebuilder.annotation.SmallTest;
347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.telephony.Rlog;
367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport java.util.concurrent.atomic.AtomicInteger;
387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport java.util.concurrent.atomic.AtomicReference;
397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltpublic class SubscriptionMonitorTest extends AndroidTestCase {
417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    private final static String LOG_TAG = "SubscriptionMonitorTest";
427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    static void failAndStack(String str) {
447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        fail(str + "\n" + SubscriptionMonitorTest.stack());
457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    static String stack() {
487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        StringBuilder sb = new StringBuilder();
497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        for(StackTraceElement e : Thread.currentThread().getStackTrace()) {
507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            sb.append(e.toString()).append("\n");
517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        return sb.toString();
537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    private static class TestHandler extends Handler {
567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public final static int SUBSCRIPTION_CHANGED = 1;
577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public final static int DEFAULT_SUBSCRIPTION_CHANGED = 2;
587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public final static int IN_IDLE = 3;
597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        HandlerThread handlerThread;
617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public TestHandler(Looper looper) {
637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            super(looper);
647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public void die() {
677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            if(handlerThread != null) {
687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                handlerThread.quit();
697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                handlerThread = null;
707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            }
717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public void blockTilIdle() {
747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            Object lock = new Object();
757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            synchronized (lock) {
767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                Message msg = this.obtainMessage(IN_IDLE, lock);
777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                msg.sendToTarget();
787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                try {
797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    lock.wait();
807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                } catch (InterruptedException e) {}
817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            }
827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public static TestHandler makeHandler() {
857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            final HandlerThread handlerThread = new HandlerThread("TestHandler");
867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            handlerThread.start();
877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            final TestHandler result = new TestHandler(handlerThread.getLooper());
887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            result.handlerThread = handlerThread;
897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            return result;
907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        private boolean objectEquals(Object o1, Object o2) {
937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            if (o1 == null) return (o2 == null);
947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            return o1.equals(o2);
957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        private void failAndStack(String str) {
987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            SubscriptionMonitorTest.failAndStack(str);
997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        @Override
1027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public void handleMessage(Message msg) {
1037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            switch (msg.what) {
1047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                case SUBSCRIPTION_CHANGED: {
1057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    AsyncResult ar = (AsyncResult)(msg.obj);
1067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    if (objectEquals(ar.userObj, mSubscriptionChangedObject.get()) == false) {
1077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                        failAndStack("Subscription Changed object is incorrect!");
1087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    }
1097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    mSubscriptionChangedCount.incrementAndGet();
1107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    Rlog.d(LOG_TAG, "SUBSCRIPTION_CHANGED, inc to " +
1117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                            mSubscriptionChangedCount.get());
1127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    break;
1137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                }
1147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                case DEFAULT_SUBSCRIPTION_CHANGED: {
1157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    AsyncResult ar = (AsyncResult)(msg.obj);
1167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    if (objectEquals(ar.userObj,
1177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                            mDefaultSubscriptionChangedObject.get()) == false) {
1187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                        failAndStack("Default Subscription Changed object is incorrect!");
1197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    }
1207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    mDefaultSubscriptionChangedCount.incrementAndGet();
1217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    Rlog.d(LOG_TAG, "DEFAULT_SUBSCRIPTION_CHANGED, inc to " +
1227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                            mDefaultSubscriptionChangedCount.get());
1237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    break;
1247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                }
1257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                case IN_IDLE: {
1267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    Object lock = msg.obj;
1277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    synchronized (lock) {
1287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                        lock.notify();
1297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    }
1307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    break;
1317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                }
1327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            }
1337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        private final AtomicInteger mSubscriptionChangedCount = new AtomicInteger(0);
1367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        private final AtomicReference<Object> mSubscriptionChangedObject =
1377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new AtomicReference<Object>();
1387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        private final AtomicInteger mDefaultSubscriptionChangedCount = new AtomicInteger(0);
1407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        private final AtomicReference<Object> mDefaultSubscriptionChangedObject =
1417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new AtomicReference<Object>();
1427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public void reset() {
1447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            mSubscriptionChangedCount.set(0);
1457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            mSubscriptionChangedObject.set(null);
1467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            mDefaultSubscriptionChangedCount.set(0);
1487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            mDefaultSubscriptionChangedObject.set(null);
1497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public void setSubscriptionChangedObject(Object o) {
1527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            mSubscriptionChangedObject.set(o);
1537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public void setDefaultSubscriptionChangedObject(Object o) {
1557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            mDefaultSubscriptionChangedObject.set(o);
1567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public int getSubscriptionChangedCount() {
1597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            return mSubscriptionChangedCount.get();
1607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        public int getDefaultSubscriptionChangedCount() {
1627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            return mDefaultSubscriptionChangedCount.get();
1637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
1657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
1677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Register and unregister normally.
1687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Verify register worked by causing an event.
1697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Verify unregister by causing another event.
1707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
1717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
1727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testRegister() throws Exception {
1737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
1747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
1757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
1767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
1777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
1787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
1797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
1817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
1827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
1847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
1857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
1867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
1887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
1897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // try events before registering
1917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(0);
1927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(0, 0);
1937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
1947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 0) {
1957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("pretest of SubscriptionChangedCount");
1967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
1977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 0) {
1987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("pretest of DefaultSubscriptionChangedCount");
1997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(0, testHandler,
2027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                  TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
2037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
2047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 1) {
2067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test1 of SubscriptionChangedCount");
2077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 0) {
2097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test1 of DefaultSubscriptionChangedCount");
2107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(0, testHandler,
2137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
2147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
2157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 1) {
2177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test2 of SubscriptionChangedCount");
2187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
2207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test2 of DefaultSubscriptionChangedCount");
2217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(1);
2247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
2257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 1) {
2277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test3 of SubscriptionChangedCount, " +
2287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " vs 1");
2297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
2317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test3 of DefaultSubscriptionChangedCount, " +
2327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " vs 2");
2337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(0, 1);
2367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
2377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
2397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test4 of SubscriptionChangedCount");
2407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
2427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test4 of DefaultSubscriptionChangedCount");
2437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(0, testHandler);
2467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(0, 0);
2477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
2487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
2507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test5 of SubscriptionChangedCount, " +
2517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " vs 3");
2527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
2547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test5 of DefaultSubscriptionChangedCount, " +
2557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " vs 3");
2567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.unregisterForSubscriptionChanged(0, testHandler);
2597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(0, 1);
2617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(0);
2627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
2637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
2657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test6 of SubscriptionChangedCount, " +
2667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " vs 3");
2677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
2697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test6 of DefaultSubscriptionChangedCount, " +
2707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " vs 3");
2717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
2727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
2747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
2757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
2777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Bad register/unregisters
2787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     *
2797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Try phoneId that doesn't exist.
2807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Cause an event and verify don't get notified.
2817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Try to unregister multiple times.
2827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
2837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
2847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testBadRegister() throws Exception {
2857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
2867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
2877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
2887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
2897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
2907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
2917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
2937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
2947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
2967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
2977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
2987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
3007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
3017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        try {
3037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.registerForSubscriptionChanged(-1, testHandler,
3047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                      TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
3057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("IllegalArgumentException expected with bad phoneId");
3067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        } catch (IllegalArgumentException e) {}
3077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        try {
3087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.registerForDefaultDataSubscriptionChanged(-1, testHandler,
3097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
3107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("IllegalArgumentException expected with bad phoneId");
3117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        } catch (IllegalArgumentException e) {}
3127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        try {
3137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.registerForSubscriptionChanged(numPhones, testHandler,
3147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                      TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
3157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("IllegalArgumentException expected with bad phoneId");
3167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        } catch (IllegalArgumentException e) {}
3177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        try {
3187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.registerForDefaultDataSubscriptionChanged(numPhones, testHandler,
3197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
3207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("IllegalArgumentException expected with bad phoneId");
3217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        } catch (IllegalArgumentException e) {}
3227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(0);
3247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(0, 0);
3257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 0) {
3277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported non-zero!");
3287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
3297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 0) {
3307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported non-zero!");
3317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
3327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
3347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
3357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
3377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Try to force spurious notifications - register/unregister in tight loop with
3387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * events happening in the unregistered gap.
3397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
3407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
3417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testSpuriousNotifications() throws Exception {
3427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
3437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
3447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
3457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
3467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
3477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
3487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
3507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
3517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
3537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
3547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
3557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
3577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
3587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int PHONE_ID = 0;
3607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int FIRST_SUB_ID = 0;
3617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_SUB_ID = 1;
3627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
3647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
3657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
3667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
3677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int LOOP_COUNT = 1000;
3687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        for (int i = 0; i < LOOP_COUNT; i++) {
3697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.unregisterForSubscriptionChanged(PHONE_ID, testHandler);
3707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(PHONE_ID, testHandler);
3717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setDefaultDataSubId(FIRST_SUB_ID);
3737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
3747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setDefaultDataSubId(SECOND_SUB_ID);
3767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
3777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
3797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
3807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
3817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
3827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
3837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
3847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one for every registration
3867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 1 + LOOP_COUNT) {
3877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
3887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != " + (1 + LOOP_COUNT));
3897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
3907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 1 + LOOP_COUNT) {
3917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
3927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != " + (1 + LOOP_COUNT));
3937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
3947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
3967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
3977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
3987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
3997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Test duplicate registrations - both should survive
4007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Also test duplicate unreg - shouldn't crash..
4017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
4027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
4037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testMultiRegUnregistration() throws Exception {
4047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
4057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
4067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
4077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
4087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
4097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
4107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
4127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
4137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
4157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
4167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
4177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
4197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
4207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int PHONE_ID = 0;
4227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int FIRST_SUB_ID = 0;
4237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_SUB_ID = 1;
4247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
4267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
4277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
4287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
4297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
4317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
4327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
4337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
4347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(FIRST_SUB_ID);
4367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
4377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(SECOND_SUB_ID);
4397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
4407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
4427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get 1 for each registration and 4 for the two events
4447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 6) {
4457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
4467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != 6");
4477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
4487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // 2 for the 2 registrations, 2 for the single event in the first cluster (2 listeners)
4497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // 2 for the setDefatulDataSub in the second cluster (lost data sub)
4507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // 2 for the setSlotSubId (regain default)
4517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 8) {
4527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
4537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != 8");
4547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
4557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.unregisterForSubscriptionChanged(PHONE_ID, testHandler);
4577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(PHONE_ID, testHandler);
4587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.unregisterForSubscriptionChanged(PHONE_ID, testHandler);
4597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.unregisterForDefaultDataSubscriptionChanged(PHONE_ID, testHandler);
4607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
4627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
4637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
4657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Try event flood while registered - verify receive all.
4667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
4677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
4687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testEventFloodNotifications() throws Exception {
4697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
4707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
4717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
4727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
4737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
4747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
4757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
4777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
4787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
4807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
4817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
4827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
4847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
4857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int PHONE_ID = 0;
4877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int FIRST_SUB_ID = 0;
4887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_SUB_ID = 1;
4897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
4917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
4927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
4937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
4947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
4957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int LOOP_COUNT = 1;
4967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        for (int i = 0; i < LOOP_COUNT; i++) {
4977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setDefaultDataSubId(FIRST_SUB_ID);
4987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
4997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setDefaultDataSubId(SECOND_SUB_ID);
5017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
5027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
5037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
5047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one for registration + 2 per loop
5067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 1 + (2 * LOOP_COUNT)) {
5077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
5087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != " + (1 + (2 * LOOP_COUNT)));
5097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
5107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one for registration + 3 for first loop + 4 for subsequent loops
5117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != (4 * LOOP_COUNT)) {
5127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
5137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != " +
5147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    (4 * LOOP_COUNT));
5157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
5167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
5187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
5197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
5217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Try tests with no default set
5227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
5237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
5247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testNoDefaultNotifications() throws Exception {
5257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
5267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
5277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
5287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
5297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
5307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
5317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
5337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
5347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
5367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
5377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
5387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
5407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
5417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int PHONE_ID = 0;
5437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int FIRST_SUB_ID = 0;
5447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_SUB_ID = 1;
5457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(INVALID_SUBSCRIPTION_ID);
5477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
5487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
5507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
5517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
5527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
5537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
5567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
5577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
5597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
5617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
5627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != 3");
5637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
5647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
5657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
5667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != 1");
5677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
5687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
5707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
5717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
5737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testNoSubChange() throws Exception {
5747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        String TAG = "testNoSubChange";
5757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
5767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
5777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
5787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
5797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
5807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
5817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
5837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
5847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
5867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
5877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
5887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
5907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
5917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int PHONE_ID = 0;
5937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int FIRST_SUB_ID = 0;
5947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_SUB_ID = 1;
5957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
5977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "1");
5987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
5997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
6007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
6017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "2");
6047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
6067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
6077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "3");
6107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
6127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "4");
6157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(FIRST_SUB_ID);
6177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "5");
6207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
6227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
6237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != 2");
6247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
6257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // 1 gained for reg  and 1 for the setting above
6267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
6277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
6287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != 2");
6297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
6307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "6");
6327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // cause a notification that subscription info changed
6347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.notifySubscriptionInfoChanged();
6357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "7");
6387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
6407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
6417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != 2");
6427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
6437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
6447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
6457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != 2");
6467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
6477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // now change the default - should cause a default notification (we lost the default)
6497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(SECOND_SUB_ID);
6507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Rlog.d(TAG, "8");
6537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
6557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getSubscriptionChangedCount reported " +
6567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getSubscriptionChangedCount() + " != 2");
6577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
6587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
6597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("getDefaultSubscriptionChangedCount reported " +
6607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                    testHandler.getDefaultSubscriptionChangedCount() + " != 3");
6617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
6627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
6637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
6647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    /**
6667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * Try setting the subIds first and then the default subId and verify we get all our
6677a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     * notifications.
6687a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt     */
6697a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    @SmallTest
6707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    public void testSubBeforeDefaultNotifications() throws Exception {
6717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int numPhones = 2;
6727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
6737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final Context context = contextFixture.getTestDouble();
6747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
6757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionControllerMock subController =
6767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
6777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        SubscriptionMonitor testedSubMonitor =
6797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
6807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
6827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object subChangedObject = new Object();
6837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
6847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        Object defaultSubChangedObject = new Object();
6867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
6877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
6887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int PHONE_ID = 0;
6897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_PHONE_ID = 1;
6907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int FIRST_SUB_ID = 0;
6917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        final int SECOND_SUB_ID = 1;
6927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
6937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
6947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
6957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
6967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, -2);
6977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(SECOND_PHONE_ID, -3);
6987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
6997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one for registration and 1 for the change
7007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
7017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test1 " + testHandler.getSubscriptionChangedCount() + " != 2");
7027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one for registration
7047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
7057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test2 " + testHandler.getDefaultSubscriptionChangedCount() + " != 1");
7067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(FIRST_SUB_ID);
7097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
7107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // no change
7127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
7137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test3 " + testHandler.getSubscriptionChangedCount() + " != 2");
7147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
7167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test4 " + testHandler.getDefaultSubscriptionChangedCount() + " != 1");
7177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
7207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
7217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one more default-change-notification
7237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
7247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test5 " + testHandler.getSubscriptionChangedCount() + " != 3");
7257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
7277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test6 " + testHandler.getDefaultSubscriptionChangedCount() + " != 2");
7287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(SECOND_SUB_ID);
7317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
7327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one more default-change-notification
7347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
7357a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test7 " + testHandler.getSubscriptionChangedCount() + " != 3");
7367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
7387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test8 " + testHandler.getDefaultSubscriptionChangedCount() + " != 3");
7397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        subController.setDefaultDataSubId(FIRST_SUB_ID);
7427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.blockTilIdle();
7437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        // should get one more default-change-notification
7457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
7467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test9 " + testHandler.getSubscriptionChangedCount() + " != 3");
7477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 4) {
7497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt            fail("test10 " + testHandler.getDefaultSubscriptionChangedCount() + " != 4");
7507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        }
7517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt        testHandler.die();
7537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt    }
7547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
7556899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt    /**
7566899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt     * It turns out when we swap sims on a single sim we do something like:
7576899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt     *   Phone[0] subId  1 -> -2
7586899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt     *   Phone[0] subId -2 ->  2
7596899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt     *   Default change  1 ->  2
7606899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt     * Try that and verify we get all the subId and default changes we expect.
7616899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt     */
7626899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt    @SmallTest
7636899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt    public void testSimSwapNotifications() throws Exception {
7646899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        final int numPhones = 1;
7656899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        final ContextFixture contextFixture = new ContextFixture();
7666899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        final Context context = contextFixture.getTestDouble();
7676899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        ITelephonyRegistry.Stub telRegistry = new TelephonyRegistryMock();
7686899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        SubscriptionControllerMock subController =
7696899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt                new SubscriptionControllerMock(context, telRegistry, numPhones);
7706899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
7716899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        SubscriptionMonitor testedSubMonitor =
7726899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt                new SubscriptionMonitor(telRegistry, context, subController, numPhones);
7736899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
7746899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        TestHandler testHandler = TestHandler.makeHandler();
7756899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        Object subChangedObject = new Object();
7766899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.setSubscriptionChangedObject(subChangedObject);
7776899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
7786899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        Object defaultSubChangedObject = new Object();
7796899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.setDefaultSubscriptionChangedObject(defaultSubChangedObject);
7806899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
7816899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        final int PHONE_ID = 0;
7826899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        final int FIRST_SUB_ID = 0;
7836899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        final int SECOND_SUB_ID = 1;
7846899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testedSubMonitor.registerForSubscriptionChanged(PHONE_ID, testHandler,
7856899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt                TestHandler.SUBSCRIPTION_CHANGED, subChangedObject);
7866899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testedSubMonitor.registerForDefaultDataSubscriptionChanged(PHONE_ID, testHandler,
7876899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt                TestHandler.DEFAULT_SUBSCRIPTION_CHANGED, defaultSubChangedObject);
7886899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        subController.setSlotSubId(PHONE_ID, -2);
7896899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.blockTilIdle();
7906899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        // should get one for registration and 1 for the change
7916899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 2) {
7926899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test1 " + testHandler.getSubscriptionChangedCount() + " != 2");
7936899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
7946899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        // should get one for registration
7956899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 1) {
7966899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test2 " + testHandler.getDefaultSubscriptionChangedCount() + " != 1");
7976899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
7986899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
7996899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        subController.setSlotSubId(PHONE_ID, FIRST_SUB_ID);
8006899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.blockTilIdle();
8016899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 3) {
8026899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test3 " + testHandler.getSubscriptionChangedCount() + " != 3");
8036899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8046899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8056899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        subController.setDefaultDataSubId(FIRST_SUB_ID);
8066899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.blockTilIdle();
8076899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 2) {
8086899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test4 " + testHandler.getDefaultSubscriptionChangedCount() + " != 2");
8096899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8106899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8116899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        // ok - now for the sim swap
8126899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        subController.setSlotSubId(PHONE_ID, -2);
8136899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.blockTilIdle();
8146899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 3) {
8156899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test5 " + testHandler.getDefaultSubscriptionChangedCount() + " != 3");
8166899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8176899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 4) {
8186899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test6 " + testHandler.getSubscriptionChangedCount() + " != 4");
8196899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8206899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8216899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        subController.setSlotSubId(PHONE_ID, SECOND_SUB_ID);
8226899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.blockTilIdle();
8236899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8246899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 5) {
8256899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test7 " + testHandler.getSubscriptionChangedCount() + " != 5");
8266899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8276899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8286899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        subController.setDefaultDataSubId(SECOND_SUB_ID);
8296899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.blockTilIdle();
8306899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8316899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getDefaultSubscriptionChangedCount() != 4) {
8326899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test8 " + testHandler.getDefaultSubscriptionChangedCount() + " != 4");
8336899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8346899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        // no change
8356899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        if (testHandler.getSubscriptionChangedCount() != 5) {
8366899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt            fail("test9 " + testHandler.getSubscriptionChangedCount() + " != 5");
8376899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        }
8386899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt
8396899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt        testHandler.die();
8406899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt    }
8417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt}
842