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