[go: nahoru, domu]

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 com.android.internal.telephony.ContextFixture;
20e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.dataconnection.TelephonyNetworkFactory;
21e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.mocks.ConnectivityServiceMock;
22e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.mocks.DcTrackerMock;
23e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.mocks.PhoneSwitcherMock;
24e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.mocks.SubscriptionControllerMock;
25e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.mocks.SubscriptionMonitorMock;
26e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.mocks.TelephonyRegistryMock;
27e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.test.SimulatedCommands;
28e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
29e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.content.Context;
30e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.AsyncResult;
31e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Binder;
32e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Handler;
33e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.HandlerThread;
34e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Looper;
35e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.os.Message;
36e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.ConnectivityManager;
37e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.IConnectivityManager;
38e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.NetworkCapabilities;
39e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.NetworkRequest;
40e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
41e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.test.AndroidTestCase;
42e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.test.suitebuilder.annotation.SmallTest;
43e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
44e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.telephony.Rlog;
45e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
46e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
47e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltpublic class TelephonyNetworkFactoryTest extends AndroidTestCase {
48e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private final static String LOG_TAG = "TelephonyNetworkFactoryTest";
49e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
50e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private void waitABit() {
51e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        try {
52e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Thread.sleep(250);
53e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        } catch (Exception e) {}
54e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
55e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
56e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private String mTestName = "";
57e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
58e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private void log(String str) {
59e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        Rlog.d(LOG_TAG + " " + mTestName, str);
60e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
61e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
62e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private class TestSetup {
63e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final TelephonyRegistryMock telephonyRegistryMock;
64e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final PhoneSwitcherMock phoneSwitcherMock;
65e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final SubscriptionControllerMock subscriptionControllerMock;
66e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final SubscriptionMonitorMock subscriptionMonitorMock;
67e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final HandlerThread handlerThread;
68e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final ConnectivityServiceMock connectivityServiceMock;
69e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final Looper looper;
70e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        DcTrackerMock dcTrackerMock;
71e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final Context contextMock;
72e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
73e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TestSetup(int numPhones) {
74e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            handlerThread = new HandlerThread("TelephonyNetworkFactoryTest");
75e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            handlerThread.start();
76e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            looper = handlerThread.getLooper();
77e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
78e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Handler myHandler = new Handler(looper) {
79e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                public void handleMessage(Message msg) {
80e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    if (dcTrackerMock == null) dcTrackerMock = new DcTrackerMock();
81e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                }
82e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            };
83e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            myHandler.obtainMessage(0).sendToTarget();
84e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
85e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            final ContextFixture contextFixture = new ContextFixture();
86e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            String[] networkConfigString = getContext().getResources().getStringArray(
87e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    com.android.internal.R.array.networkAttributes);
88e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
89e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    networkConfigString);
90e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            contextMock = contextFixture.getTestDouble();
91e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
92e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            connectivityServiceMock = new ConnectivityServiceMock(contextMock);
93e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            ConnectivityManager cm =
94e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    new ConnectivityManager(contextMock, connectivityServiceMock);
95e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
96e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
97e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            telephonyRegistryMock = new TelephonyRegistryMock();
98e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            phoneSwitcherMock = new PhoneSwitcherMock(numPhones, looper);
99e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            subscriptionControllerMock =
100e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                    new SubscriptionControllerMock(contextMock, telephonyRegistryMock, numPhones);
101e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            subscriptionMonitorMock = new SubscriptionMonitorMock(numPhones);
102e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
103e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
104e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        void die() {
105e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            looper.quit();
106e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            handlerThread.quit();
107e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
108e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
109e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
110e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private TelephonyNetworkFactory makeTnf(int phoneId, TestSetup ts) {
111e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return new TelephonyNetworkFactory(ts.phoneSwitcherMock, ts.subscriptionControllerMock,
112e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                ts.subscriptionMonitorMock, ts.looper, ts.contextMock, phoneId, ts.dcTrackerMock);
113e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
114e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
115e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private NetworkRequest makeSubSpecificDefaultRequest(TestSetup ts, int subId) {
116e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkCapabilities netCap = (new NetworkCapabilities()).
117e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).
118e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED).
119e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
120e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        netCap.setNetworkSpecifier(Integer.toString(subId));
121e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return ts.connectivityServiceMock.requestNetwork(netCap, null, 0, new Binder(), -1);
122e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
123e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private NetworkRequest makeSubSpecificMmsRequest(TestSetup ts, int subId) {
124e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkCapabilities netCap = (new NetworkCapabilities()).
125e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_MMS).
126e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED).
127e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
128e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        netCap.setNetworkSpecifier(Integer.toString(subId));
129e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return ts.connectivityServiceMock.requestNetwork(netCap, null, 0, new Binder(), -1);
130e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
131e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
132e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
133e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    /**
134e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     * Test that phone active changes cause the DcTracker to get poked.
135e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     */
136e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    @SmallTest
137e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    public void testActive() throws Exception {
138e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        mTestName = "testActive";
139e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int numberOfPhones = 1;
140e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int phoneId = 0;
141e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int subId = 0;
142e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
143e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TestSetup ts = new TestSetup(numberOfPhones);
144e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
145e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TelephonyNetworkFactory tnf = makeTnf(phoneId, ts);
146e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
147e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(subId);
148e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, subId);
149e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
150e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
151e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
152e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.addDefaultRequest();
153e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
154e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
155e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("pretest of LiveRequests != 0");
156e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
157e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
158e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
159e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
160e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
161e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-active test of LiveRequests != 1");
162e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
163e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
164e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkRequest subSpecificDefault = makeSubSpecificDefaultRequest(ts, subId);
165e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
166e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 2) {
167e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-second-request test of LiveRequests != 2");
168e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
169e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
170e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, false);
171e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
172e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
173e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-inactive test of LiveRequests != 0");
174e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
175e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
176e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkRequest subSpecificMms = makeSubSpecificMmsRequest(ts, subId);
177e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
178e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
179e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-mms-add test of LiveRequests != 0");
180e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
181e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
182e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
183e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
184e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 3) {
185e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-active-mms-add test of LiveRequests != 3");
186e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
187e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
188e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.releaseNetworkRequest(subSpecificDefault);
189e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
190e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 2) {
191e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("post-remove-default test of LiveRequests != 2");
192e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
193e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
194e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, false);
195e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
196e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
197e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 8, LiveRequests != 0");
198e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
199e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
200e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.releaseNetworkRequest(subSpecificMms);
201e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
202e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
203e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 9, LiveRequests != 0");
204e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
205e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
206e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
207e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
208e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
209e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 10, LiveRequests != 1," + ts.dcTrackerMock.getNumberOfLiveRequests());
210e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
211e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
212e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.die();
213e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
214e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
215e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    /**
216e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     * Test that network request changes cause the DcTracker to get poked.
217e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt     */
218e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    @SmallTest
219e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    public void testRequests() throws Exception {
220e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        mTestName = "testActive";
221e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int numberOfPhones = 2;
222e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int phoneId = 0;
223e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int altPhoneId = 1;
224e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int subId = 0;
225e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int altSubId = 1;
226e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        final int unusedSubId = 2;
227e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
228e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TestSetup ts = new TestSetup(numberOfPhones);
229e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
230e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        TelephonyNetworkFactory tnf = makeTnf(phoneId, ts);
231e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
232e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(subId);
233e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, subId);
234e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
235e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
236e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
237e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
238e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
239e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 1, LiveRequests != 0");
240e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
241e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
242e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.phoneSwitcherMock.setPhoneActive(phoneId, true);
243e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
244e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
245e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 2, LiveRequests != 0");
246e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
247e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
248e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.connectivityServiceMock.addDefaultRequest();
249e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
250e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
251e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 3, LiveRequests != 1");
252e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
253e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
254e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(altPhoneId, altSubId);
255e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
256e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
257e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 4, LiveRequests != 1");
258e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
259e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
260e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(altSubId);
261e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
262e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(altPhoneId);
263e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
264e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
265e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 5, LiveRequests != 0");
266e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
267e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
268e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkRequest subSpecificMms = makeSubSpecificMmsRequest(ts, subId);
269e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
270e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 1) {
271e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 6,  LiveRequests != 1");
272e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
273e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
274e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, unusedSubId);
275e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
276e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
277e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
278e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 7,  LiveRequests != 0");
279e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
280e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
281e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkRequest subSpecificDefault = makeSubSpecificDefaultRequest(ts, subId);
282e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
283e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 0) {
284e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 8, LiveRequests != 0");
285e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
286e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
287e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setSlotSubId(phoneId, subId);
288e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifySubscriptionChanged(phoneId);
289e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
290e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 2) {
291e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 9,  LiveRequests != 2");
292e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
293e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
294e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionControllerMock.setDefaultDataSubId(subId);
295e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
296e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(altPhoneId);
297e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.subscriptionMonitorMock.notifyDefaultSubscriptionChanged(phoneId);
298e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        waitABit();
299e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (ts.dcTrackerMock.getNumberOfLiveRequests() != 3) {
300e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            fail("test 10, LiveRequests != 3");
301e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
302e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        ts.die();
303e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
304e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt}
305