1e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt/*
2e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * Copyright (C) 2006 The Android Open Source Project
3e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt *
4e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License");
5e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * you may not use this file except in compliance with the License.
6e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * You may obtain a copy of the License at
7e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt *
8e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt *      http://www.apache.org/licenses/LICENSE-2.0
9e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt *
10e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * Unless required by applicable law or agreed to in writing, software
11e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS,
12e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * See the License for the specific language governing permissions and
14e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt * limitations under the License.
15e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt */
16e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
17e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltpackage com.android.internal.telephony.dataconnection;
18e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
19e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.content.Context;
20e73ef117c8f5a7ea2feaa9ba8a15ec2de4137c7dJordan Liuimport android.net.ConnectivityManager;
21e73ef117c8f5a7ea2feaa9ba8a15ec2de4137c7dJordan Liuimport android.net.NetworkCapabilities;
22e73ef117c8f5a7ea2feaa9ba8a15ec2de4137c7dJordan Liuimport android.net.NetworkRequest;
2326c3198e70345a70e5dfa8ee422c7c4e60916cbeLorenzo Colittiimport android.net.StringNetworkSpecifier;
24e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Binder;
25e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.HandlerThread;
26e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Looper;
27e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Message;
28e73ef117c8f5a7ea2feaa9ba8a15ec2de4137c7dJordan Liuimport android.support.test.filters.FlakyTest;
29cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport android.telephony.Rlog;
30e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.test.AndroidTestCase;
31e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.test.suitebuilder.annotation.SmallTest;
32e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
33cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.ContextFixture;
34cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.mocks.ConnectivityServiceMock;
35cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.mocks.DcTrackerMock;
36cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.mocks.PhoneSwitcherMock;
37cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.mocks.SubscriptionControllerMock;
38cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.mocks.SubscriptionMonitorMock;
39cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yuimport com.android.internal.telephony.mocks.TelephonyRegistryMock;
40e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
41cc940f429180765b6072a071becae8117e665954Amit Mahajanimport org.junit.Ignore;
42e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
43e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltpublic class TelephonyNetworkFactoryTest extends AndroidTestCase {
44e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private final static String LOG_TAG = "TelephonyNetworkFactoryTest";
45e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
46e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private void waitABit() {
47e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        try {
48e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Thread.sleep(250);
49e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        } catch (Exception e) {}
50e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
51e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
52e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private String mTestName = "";
53e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
54e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private void log(String str) {
55e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        Rlog.d(LOG_TAG + " " + mTestName, str);
56e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
57e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
58e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private class TestSetup {
59e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final TelephonyRegistryMock telephonyRegistryMock;
60e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final PhoneSwitcherMock phoneSwitcherMock;
61e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final SubscriptionControllerMock subscriptionControllerMock;
62e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final SubscriptionMonitorMock subscriptionMonitorMock;
63e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final HandlerThread handlerThread;
64e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final ConnectivityServiceMock connectivityServiceMock;
65e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final Looper looper;
66e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        DcTrackerMock dcTrackerMock;
67e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final Context contextMock;
68b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu        private Object mLock = new Object();
69b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu        private static final int MAX_INIT_WAIT_MS = 30000; // 30 seconds
70e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
71e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TestSetup(int numPhones) {
72b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu            handlerThread = new HandlerThread("TelephonyNetworkFactoryTest") {
73b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                @Override
74b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                public void onLooperPrepared() {
75b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                    synchronized (mLock) {
76b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                        if (dcTrackerMock == null) dcTrackerMock = new DcTrackerMock();
77b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                        mLock.notifyAll();
78b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                    }
79e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                }
80e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            };
81b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu            handlerThread.start();
82b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu            // wait until dct created
83b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu            synchronized (mLock) {
84b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                try {
85b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                    mLock.wait(MAX_INIT_WAIT_MS);
86b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                } catch (InterruptedException ie) {
87b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                }
88b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu                if (dcTrackerMock == null) fail("failed to initialize dct");
89b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu            }
90b50e68e3f36c75d03de4fc1ba64be82e01ce4e0efionaxu            looper = handlerThread.getLooper();
91e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
92e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            final ContextFixture contextFixture = new ContextFixture();
93e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            String[] networkConfigString = getContext().getResources().getStringArray(
94e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    com.android.internal.R.array.networkAttributes);
95e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
96e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    networkConfigString);
97e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            contextMock = contextFixture.getTestDouble();
98e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
99e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            connectivityServiceMock = new ConnectivityServiceMock(contextMock);
100e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            ConnectivityManager cm =
101e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    new ConnectivityManager(contextMock, connectivityServiceMock);
102e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
103e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
104e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            telephonyRegistryMock = new TelephonyRegistryMock();
105e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            phoneSwitcherMock = new PhoneSwitcherMock(numPhones, looper);
106e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            subscriptionControllerMock =
107e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    new SubscriptionControllerMock(contextMock, telephonyRegistryMock, numPhones);
108e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            subscriptionMonitorMock = new SubscriptionMonitorMock(numPhones);
109e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
110e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
111e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        void die() {
112ae6e8f99bdb297f906d6dcdc0a385ba27eee47fdJack Yu            connectivityServiceMock.die();
113e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            looper.quit();
114e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            handlerThread.quit();
115e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
116e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
117e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
118e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private TelephonyNetworkFactory makeTnf(int phoneId, TestSetup ts) {
119e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return new TelephonyNetworkFactory(ts.phoneSwitcherMock, ts.subscriptionControllerMock,
120e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                ts.subscriptionMonitorMock, ts.looper, ts.contextMock, phoneId, ts.dcTrackerMock);
121e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
122e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
123e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private NetworkRequest makeSubSpecificDefaultRequest(TestSetup ts, int subId) {
124e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkCapabilities netCap = (new NetworkCapabilities()).
125e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).
126e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED).
127e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
12826c3198e70345a70e5dfa8ee422c7c4e60916cbeLorenzo Colitti        netCap.setNetworkSpecifier(new StringNetworkSpecifier(Integer.toString(subId)));
129e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return ts.connectivityServiceMock.requestNetwork(netCap, null, 0, new Binder(), -1);
130e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
131e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private NetworkRequest makeSubSpecificMmsRequest(TestSetup ts, int subId) {
132e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkCapabilities netCap = (new NetworkCapabilities()).
133e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_MMS).
134e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED).
135e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
13626c3198e70345a70e5dfa8ee422c7c4e60916cbeLorenzo Colitti        netCap.setNetworkSpecifier(new StringNetworkSpecifier(Integer.toString(subId)));
137e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return ts.connectivityServiceMock.requestNetwork(netCap, null, 0, new Binder(), -1);
138e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
139e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
140e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
141e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    /**
142e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     * Test that phone active changes cause the DcTracker to get poked.
143e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     */
14492428df50d736a3d1d0f32779a22c65fcec0efabJordan Liu    @FlakyTest
145e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    @SmallTest
146e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    public void testActive() throws Exception {
147e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        mTestName = "testActive";
148e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int numberOfPhones = 1;
149e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int phoneId = 0;
150e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int subId = 0;
151e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
152e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TestSetup ts = new TestSetup(numberOfPhones);
153e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
154ae6e8f99bdb297f906d6dcdc0a385ba27eee47fdJack Yu        makeTnf(phoneId, ts);
155e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
156e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(subId);
157e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, subId);
158e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
159e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
160e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
161cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("addDefaultRequest");
162e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.addDefaultRequest();
163e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
164e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
165e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("pretest of LiveRequests != 0");
166e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
167e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
168cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("setPhoneActive true: phoneId = " + phoneId);
169e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
170e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
171e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
172e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-active test of LiveRequests != 1");
173e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
174e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
175cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("makeSubSpecificDefaultRequest: subId = " + subId);
176e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkRequest subSpecificDefault = makeSubSpecificDefaultRequest(ts, subId);
177e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
178e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 2) {
179e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-second-request test of LiveRequests != 2");
180e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
181e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
182cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("setPhoneActive false: phoneId = " + phoneId);
183e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, false);
184e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
185e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
186e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-inactive test of LiveRequests != 0");
187e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
188e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
189cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("makeSubSpecificDefaultRequest: subId = " + subId);
190e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkRequest subSpecificMms = makeSubSpecificMmsRequest(ts, subId);
191e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
192e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
193e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-mms-add test of LiveRequests != 0");
194e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
195e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
196cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("setPhoneActive true: phoneId = " + phoneId);
197e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
198e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
199e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 3) {
200e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-active-mms-add test of LiveRequests != 3");
201e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
202e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
203cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("releaseNetworkRequest: subSpecificDefault = " + subSpecificDefault);
204e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.releaseNetworkRequest(subSpecificDefault);
205e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
206e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 2) {
207e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-remove-default test of LiveRequests != 2");
208e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
209e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
210cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("setPhoneActive false: phoneId = " + phoneId);
211e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, false);
212e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
213e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
214e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 8, LiveRequests != 0");
215e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
216e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
217cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("releaseNetworkRequest: subSpecificMms = " + subSpecificMms);
218e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.releaseNetworkRequest(subSpecificMms);
219e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
220e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
221e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 9, LiveRequests != 0");
222e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
223e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
224cef2ab5e676f7a8187e5cddaa1d2547b13f48f39Jack Yu        log("setPhoneActive true: phoneId = " + phoneId);
225e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
226e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
227e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
228e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 10, LiveRequests != 1," + ts.dcTrackerMock.getNumberOfLiveRequests());
229e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
230e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
231e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.die();
232e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
233e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
234e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    /**
235e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     * Test that network request changes cause the DcTracker to get poked.
236e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     */
237e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    @SmallTest
238e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    public void testRequests() throws Exception {
239e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        mTestName = "testActive";
240e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int numberOfPhones = 2;
241e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int phoneId = 0;
242e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int altPhoneId = 1;
243e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int subId = 0;
244e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int altSubId = 1;
245e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int unusedSubId = 2;
246e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
247e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TestSetup ts = new TestSetup(numberOfPhones);
248e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
249ae6e8f99bdb297f906d6dcdc0a385ba27eee47fdJack Yu        makeTnf(phoneId, ts);
250e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
251e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(subId);
252e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, subId);
253e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
254e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
255e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
256e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
257e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
258e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 1, LiveRequests != 0");
259e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
260e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
261e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
262e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
263e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
264e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 2, LiveRequests != 0");
265e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
266e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
267e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.addDefaultRequest();
268e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
269e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
270e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 3, LiveRequests != 1");
271e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
272e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
273e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(altPhoneId, altSubId);
274e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
275e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
276e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 4, LiveRequests != 1");
277e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
278e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
279e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(altSubId);
280e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
281e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(altPhoneId);
282e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
283e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
284e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 5, LiveRequests != 0");
285e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
286e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
287ae6e8f99bdb297f906d6dcdc0a385ba27eee47fdJack Yu        makeSubSpecificMmsRequest(ts, subId);
288e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
289e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
290e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 6,  LiveRequests != 1");
291e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
292e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
293e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, unusedSubId);
294e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
295e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
296e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
297e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 7,  LiveRequests != 0");
298e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
299e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
300ae6e8f99bdb297f906d6dcdc0a385ba27eee47fdJack Yu        makeSubSpecificDefaultRequest(ts, subId);
301e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
302e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
303e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 8, LiveRequests != 0");
304e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
305e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
306e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, subId);
307e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
308e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
309e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 2) {
310e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 9,  LiveRequests != 2");
311e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
312e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
313e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(subId);
314e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
315e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(altPhoneId);
316e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
317e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
318e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 3) {
319e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 10, LiveRequests != 3");
320e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
321e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.die();
322e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
323e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt}
324