Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 16 | |
| 17 | package com.android.systemui.statusbar.policy; |
| 18 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 19 | import static junit.framework.Assert.assertEquals; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 20 | import static junit.framework.Assert.assertNotNull; |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 21 | |
| 22 | import static org.mockito.Matchers.any; |
| 23 | import static org.mockito.Matchers.anyBoolean; |
| 24 | import static org.mockito.Matchers.anyInt; |
| 25 | import static org.mockito.Matchers.anyString; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 26 | import static org.mockito.Matchers.eq; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 27 | import static org.mockito.Matchers.isA; |
| 28 | import static org.mockito.Mockito.atLeastOnce; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 29 | import static org.mockito.Mockito.doAnswer; |
Jason Monk | f6a3cf9 | 2016-02-29 13:01:08 -0500 | [diff] [blame] | 30 | import static org.mockito.Mockito.mock; |
| 31 | import static org.mockito.Mockito.when; |
| 32 | |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 33 | import android.content.Intent; |
| 34 | import android.net.ConnectivityManager; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 35 | import android.net.Network; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 36 | import android.net.NetworkCapabilities; |
| 37 | import android.net.wifi.WifiManager; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 38 | import android.os.Handler; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 39 | import android.provider.Settings; |
| 40 | import android.provider.Settings.Global; |
| 41 | import android.telephony.PhoneStateListener; |
| 42 | import android.telephony.ServiceState; |
| 43 | import android.telephony.SignalStrength; |
| 44 | import android.telephony.SubscriptionInfo; |
| 45 | import android.telephony.SubscriptionManager; |
| 46 | import android.telephony.TelephonyManager; |
| 47 | import android.testing.TestableLooper; |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 48 | import android.testing.TestableResources; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 49 | import android.util.Log; |
| 50 | |
| 51 | import com.android.internal.telephony.cdma.EriInfo; |
Evan Laird | 06e9fd8 | 2018-02-10 09:36:55 -0800 | [diff] [blame] | 52 | import com.android.settingslib.graph.SignalDrawable; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 53 | import com.android.settingslib.net.DataUsageController; |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 54 | import com.android.systemui.R; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 55 | import com.android.systemui.SysuiTestCase; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 56 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
| 57 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
| 58 | import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; |
| 59 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config; |
| 60 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionDefaults; |
| 61 | |
| 62 | import org.junit.Before; |
| 63 | import org.junit.Rule; |
| 64 | import org.junit.rules.TestWatcher; |
| 65 | import org.junit.runner.Description; |
| 66 | import org.mockito.ArgumentCaptor; |
| 67 | import org.mockito.Mockito; |
| 68 | |
| 69 | import java.io.PrintWriter; |
| 70 | import java.io.StringWriter; |
| 71 | import java.util.ArrayList; |
| 72 | import java.util.List; |
| 73 | |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 74 | public class NetworkControllerBaseTest extends SysuiTestCase { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 75 | private static final String TAG = "NetworkControllerBaseTest"; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 76 | protected static final int DEFAULT_LEVEL = 2; |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 77 | protected static final int DEFAULT_SIGNAL_STRENGTH = DEFAULT_LEVEL; |
| 78 | protected static final int DEFAULT_QS_SIGNAL_STRENGTH = DEFAULT_LEVEL; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 79 | protected static final int DEFAULT_ICON = TelephonyIcons.ICON_3G; |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 80 | protected static final int DEFAULT_QS_ICON = TelephonyIcons.ICON_3G; |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 81 | protected static final String NO_DATA_STRING = "Data disabled"; |
| 82 | protected static final String NOT_DEFAULT_DATA_STRING = "Not default data"; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 83 | |
| 84 | protected NetworkControllerImpl mNetworkController; |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 85 | protected MobileSignalController mMobileSignalController; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 86 | protected PhoneStateListener mPhoneStateListener; |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 87 | protected SignalStrength mSignalStrength; |
| 88 | protected ServiceState mServiceState; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 89 | protected ConnectivityManager mMockCm; |
| 90 | protected WifiManager mMockWm; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 91 | protected SubscriptionManager mMockSm; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 92 | protected TelephonyManager mMockTm; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 93 | protected Config mConfig; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 94 | protected CallbackHandler mCallbackHandler; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 95 | protected SubscriptionDefaults mMockSubDefaults; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 96 | protected DeviceProvisionedController mMockProvisionController; |
| 97 | protected DeviceProvisionedListener mUserCallback; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 98 | |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 99 | protected int mSubId; |
| 100 | |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 101 | private NetworkCapabilities mNetCapabilities; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 102 | private ConnectivityManager.NetworkCallback mNetworkCallback; |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 103 | |
Geoffrey Pitsch | d80035a | 2016-09-14 09:34:17 -0400 | [diff] [blame] | 104 | @Rule |
| 105 | public TestWatcher failWatcher = new TestWatcher() { |
| 106 | @Override |
| 107 | protected void failed(Throwable e, Description description) { |
| 108 | // Print out mNetworkController state if the test fails. |
| 109 | StringWriter sw = new StringWriter(); |
| 110 | PrintWriter pw = new PrintWriter(sw); |
| 111 | mNetworkController.dump(null, pw, null); |
| 112 | pw.flush(); |
| 113 | Log.d(TAG, sw.toString()); |
| 114 | } |
| 115 | }; |
| 116 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 117 | @Before |
| 118 | public void setUp() throws Exception { |
Jason Monk | a3c3d85 | 2017-08-14 11:04:42 -0400 | [diff] [blame] | 119 | Settings.Global.putInt(mContext.getContentResolver(), Global.AIRPLANE_MODE_ON, 0); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 120 | TestableResources res = mContext.getOrCreateTestableResources(); |
| 121 | res.addOverride(R.string.cell_data_off_content_description, NO_DATA_STRING); |
| 122 | res.addOverride(R.string.not_default_data_content_description, NOT_DEFAULT_DATA_STRING); |
| 123 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 124 | mMockWm = mock(WifiManager.class); |
| 125 | mMockTm = mock(TelephonyManager.class); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 126 | mMockSm = mock(SubscriptionManager.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 127 | mMockCm = mock(ConnectivityManager.class); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 128 | mMockSubDefaults = mock(SubscriptionDefaults.class); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 129 | mNetCapabilities = new NetworkCapabilities(); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 130 | when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 131 | when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn( |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 132 | new NetworkCapabilities[] { mNetCapabilities }); |
chen xu | 84a9087 | 2019-03-28 15:44:12 -0700 | [diff] [blame] | 133 | when(mMockTm.createForSubscriptionId(anyInt())).thenReturn(mMockTm); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 134 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 135 | mSignalStrength = mock(SignalStrength.class); |
| 136 | mServiceState = mock(ServiceState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 137 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 138 | mConfig = new Config(); |
| 139 | mConfig.hspaDataDistinguishable = true; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 140 | mCallbackHandler = mock(CallbackHandler.class); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 141 | |
| 142 | mMockProvisionController = mock(DeviceProvisionedController.class); |
| 143 | when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(true); |
| 144 | doAnswer(invocation -> { |
| 145 | mUserCallback = (DeviceProvisionedListener) invocation.getArguments()[0]; |
| 146 | mUserCallback.onUserSetupChanged(); |
| 147 | mUserCallback.onDeviceProvisionedChanged(); |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 148 | TestableLooper.get(this).processAllMessages(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 149 | return null; |
| 150 | }).when(mMockProvisionController).addCallback(any()); |
| 151 | |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 152 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 153 | mConfig, TestableLooper.get(this).getLooper(), mCallbackHandler, |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 154 | mock(AccessPointControllerImpl.class), mock(DataUsageController.class), |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 155 | mMockSubDefaults, mMockProvisionController); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 156 | setupNetworkController(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 157 | |
| 158 | // Trigger blank callbacks to always get the current state (some tests don't trigger |
| 159 | // changes from default state). |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 160 | mNetworkController.addCallback(mock(SignalCallback.class)); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 161 | mNetworkController.addEmergencyListener(null); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | protected void setupNetworkController() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 165 | // For now just pretend to be the data sim, so we can test that too. |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 166 | mSubId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 167 | when(mMockTm.isDataCapable()).thenReturn(true); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 168 | setDefaultSubId(mSubId); |
| 169 | setSubscriptions(mSubId); |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 170 | mMobileSignalController = mNetworkController.mMobileSignalControllers.get(mSubId); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 171 | mPhoneStateListener = mMobileSignalController.mPhoneStateListener; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 172 | |
| 173 | ArgumentCaptor<ConnectivityManager.NetworkCallback> callbackArg = |
| 174 | ArgumentCaptor.forClass(ConnectivityManager.NetworkCallback.class); |
| 175 | Mockito.verify(mMockCm, atLeastOnce()) |
| 176 | .registerDefaultNetworkCallback(callbackArg.capture(), isA(Handler.class)); |
| 177 | mNetworkCallback = callbackArg.getValue(); |
| 178 | assertNotNull(mNetworkCallback); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 179 | } |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 180 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 181 | protected void setDefaultSubId(int subId) { |
| 182 | when(mMockSubDefaults.getDefaultDataSubId()).thenReturn(subId); |
| 183 | when(mMockSubDefaults.getDefaultVoiceSubId()).thenReturn(subId); |
| 184 | } |
| 185 | |
| 186 | protected void setSubscriptions(int... subIds) { |
| 187 | List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>(); |
| 188 | for (int subId : subIds) { |
| 189 | SubscriptionInfo subscription = mock(SubscriptionInfo.class); |
| 190 | when(subscription.getSubscriptionId()).thenReturn(subId); |
| 191 | subs.add(subscription); |
| 192 | } |
| 193 | when(mMockSm.getActiveSubscriptionInfoList()).thenReturn(subs); |
Malcolm Chen | d2d400cb | 2018-12-21 17:11:10 -0800 | [diff] [blame] | 194 | when(mMockSm.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(subs); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 195 | mNetworkController.doUpdateMobileControllers(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 198 | protected NetworkControllerImpl setUpNoMobileData() { |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 199 | when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false); |
| 200 | NetworkControllerImpl networkControllerNoMobile |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 201 | = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 202 | mConfig, TestableLooper.get(this).getLooper(), mCallbackHandler, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 203 | mock(AccessPointControllerImpl.class), |
| 204 | mock(DataUsageController.class), mMockSubDefaults, |
| 205 | mock(DeviceProvisionedController.class)); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 206 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 207 | setupNetworkController(); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 208 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 209 | return networkControllerNoMobile; |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 210 | |
| 211 | } |
| 212 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 213 | // 2 Bars 3G GSM. |
| 214 | public void setupDefaultSignal() { |
| 215 | setIsGsm(true); |
| 216 | setVoiceRegState(ServiceState.STATE_IN_SERVICE); |
| 217 | setGsmRoaming(false); |
| 218 | setLevel(DEFAULT_LEVEL); |
| 219 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 220 | TelephonyManager.NETWORK_TYPE_UMTS); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 221 | setConnectivityViaBroadcast( |
| 222 | NetworkCapabilities.TRANSPORT_CELLULAR, true, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 225 | public void setupDefaultNr5GIconConfiguration() { |
| 226 | NetworkControllerImpl.Config.add5GIconMapping("connected_mmwave:5g_plus", mConfig); |
| 227 | NetworkControllerImpl.Config.add5GIconMapping("connected:5g", mConfig); |
| 228 | } |
| 229 | |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 230 | public void setConnectivityViaBroadcast( |
| 231 | int networkType, boolean validated, boolean isConnected) { |
| 232 | setConnectivityCommon(networkType, validated, isConnected); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 233 | Intent i = new Intent(ConnectivityManager.INET_CONDITION_ACTION); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 234 | mNetworkController.onReceive(mContext, i); |
| 235 | } |
| 236 | |
| 237 | public void setConnectivityViaCallback( |
| 238 | int networkType, boolean validated, boolean isConnected){ |
| 239 | setConnectivityCommon(networkType, validated, isConnected); |
| 240 | mNetworkCallback.onCapabilitiesChanged( |
| 241 | mock(Network.class), new NetworkCapabilities(mNetCapabilities)); |
| 242 | } |
| 243 | |
| 244 | private void setConnectivityCommon( |
| 245 | int networkType, boolean validated, boolean isConnected){ |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 246 | // TODO: Separate out into several NetworkCapabilities. |
| 247 | if (isConnected) { |
| 248 | mNetCapabilities.addTransportType(networkType); |
| 249 | } else { |
| 250 | mNetCapabilities.removeTransportType(networkType); |
| 251 | } |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 252 | if (validated) { |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 253 | mNetCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 254 | } else { |
| 255 | mNetCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 256 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | public void setGsmRoaming(boolean isRoaming) { |
| 260 | when(mServiceState.getRoaming()).thenReturn(isRoaming); |
| 261 | updateServiceState(); |
| 262 | } |
| 263 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 264 | public void setCdmaRoaming(boolean isRoaming) { |
| 265 | when(mServiceState.getCdmaEriIconIndex()).thenReturn(isRoaming ? |
| 266 | EriInfo.ROAMING_INDICATOR_ON : EriInfo.ROAMING_INDICATOR_OFF); |
| 267 | when(mServiceState.getCdmaEriIconMode()).thenReturn(isRoaming ? |
| 268 | EriInfo.ROAMING_ICON_MODE_NORMAL : -1); |
| 269 | updateServiceState(); |
| 270 | } |
| 271 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 272 | public void setVoiceRegState(int voiceRegState) { |
| 273 | when(mServiceState.getVoiceRegState()).thenReturn(voiceRegState); |
| 274 | updateServiceState(); |
| 275 | } |
| 276 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 277 | public void setDataRegState(int dataRegState) { |
| 278 | when(mServiceState.getDataRegState()).thenReturn(dataRegState); |
| 279 | updateServiceState(); |
| 280 | } |
| 281 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 282 | public void setIsEmergencyOnly(boolean isEmergency) { |
| 283 | when(mServiceState.isEmergencyOnly()).thenReturn(isEmergency); |
| 284 | updateServiceState(); |
| 285 | } |
| 286 | |
| 287 | public void setCdmaLevel(int level) { |
| 288 | when(mSignalStrength.getCdmaLevel()).thenReturn(level); |
| 289 | updateSignalStrength(); |
| 290 | } |
| 291 | |
| 292 | public void setLevel(int level) { |
| 293 | when(mSignalStrength.getLevel()).thenReturn(level); |
| 294 | updateSignalStrength(); |
| 295 | } |
| 296 | |
| 297 | public void setIsGsm(boolean gsm) { |
| 298 | when(mSignalStrength.isGsm()).thenReturn(gsm); |
| 299 | updateSignalStrength(); |
| 300 | } |
| 301 | |
| 302 | public void setCdmaEri(int index, int mode) { |
| 303 | // TODO: Figure this out. |
| 304 | } |
| 305 | |
| 306 | private void updateSignalStrength() { |
| 307 | Log.d(TAG, "Sending Signal Strength: " + mSignalStrength); |
| 308 | mPhoneStateListener.onSignalStrengthsChanged(mSignalStrength); |
| 309 | } |
| 310 | |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 311 | protected void updateServiceState() { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 312 | Log.d(TAG, "Sending Service State: " + mServiceState); |
| 313 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 314 | } |
| 315 | |
| 316 | public void updateCallState(int state) { |
| 317 | // Inputs not currently used in NetworkControllerImpl. |
| 318 | mPhoneStateListener.onCallStateChanged(state, "0123456789"); |
| 319 | } |
| 320 | |
| 321 | public void updateDataConnectionState(int dataState, int dataNetType) { |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 322 | when(mServiceState.getDataNetworkType()).thenReturn(dataNetType); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 323 | mPhoneStateListener.onDataConnectionStateChanged(dataState, dataNetType); |
| 324 | } |
| 325 | |
| 326 | public void updateDataActivity(int dataActivity) { |
| 327 | mPhoneStateListener.onDataActivity(dataActivity); |
| 328 | } |
| 329 | |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 330 | public void setCarrierNetworkChange(boolean enable) { |
| 331 | Log.d(TAG, "setCarrierNetworkChange(" + enable + ")"); |
| 332 | mPhoneStateListener.onCarrierNetworkChange(enable); |
| 333 | } |
| 334 | |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 335 | protected void verifyHasNoSims(boolean hasNoSimsVisible) { |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 336 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setNoSims( |
| 337 | eq(hasNoSimsVisible), eq(false)); |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 338 | } |
| 339 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 340 | protected void verifyLastQsMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 341 | boolean dataIn, boolean dataOut) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 342 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 343 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 344 | ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class); |
| 345 | ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 346 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 347 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 348 | any(), |
| 349 | iconArg.capture(), |
| 350 | anyInt(), |
| 351 | typeIconArg.capture(), dataInArg.capture(), dataOutArg.capture(), |
| 352 | anyString(), anyString(), anyBoolean(), anyInt(), anyBoolean()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 353 | IconState iconState = iconArg.getValue(); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 354 | int state = SignalDrawable.getState(icon, SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 355 | false); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 356 | assertEquals("Visibility in, quick settings", visible, iconState.visible); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 357 | assertEquals("Signal icon in, quick settings", state, iconState.icon); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 358 | assertEquals("Data icon in, quick settings", typeIcon, (int) typeIconArg.getValue()); |
| 359 | assertEquals("Data direction in, in quick settings", dataIn, |
| 360 | (boolean) dataInArg.getValue()); |
| 361 | assertEquals("Data direction out, in quick settings", dataOut, |
| 362 | (boolean) dataOutArg.getValue()); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon) { |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 366 | verifyLastMobileDataIndicators(visible, icon, typeIcon, false); |
| 367 | } |
| 368 | |
| 369 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
| 370 | boolean roaming) { |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 371 | verifyLastMobileDataIndicators(visible, icon, typeIcon, roaming, true); |
| 372 | } |
| 373 | |
| 374 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 375 | boolean roaming, boolean inet) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 376 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 377 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 378 | |
| 379 | // TODO: Verify all fields. |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 380 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
| 381 | iconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 382 | any(), |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 383 | typeIconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 384 | anyInt(), anyBoolean(), anyBoolean(), anyString(), anyString(), anyBoolean(), |
| 385 | anyInt(), eq(roaming)); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 386 | IconState iconState = iconArg.getValue(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 387 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 388 | int state = icon == -1 ? 0 |
| 389 | : SignalDrawable.getState(icon, SignalStrength.NUM_SIGNAL_STRENGTH_BINS, !inet); |
| 390 | assertEquals("Signal icon in status bar", state, iconState.icon); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 391 | assertEquals("Data icon in status bar", typeIcon, (int) typeIconArg.getValue()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 392 | assertEquals("Visibility in status bar", visible, iconState.visible); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 393 | } |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 394 | |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 395 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 396 | boolean qsVisible, int qsIcon, int qsTypeIcon, boolean dataIn, boolean dataOut) { |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 397 | verifyLastMobileDataIndicators( |
| 398 | visible, icon, typeIcon, qsVisible, qsIcon, qsTypeIcon, dataIn, dataOut, false); |
| 399 | } |
| 400 | |
| 401 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
| 402 | boolean qsVisible, int qsIcon, int qsTypeIcon, boolean dataIn, boolean dataOut, |
| 403 | boolean cutOut) { |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 404 | verifyLastMobileDataIndicators( |
| 405 | visible, icon, typeIcon, qsVisible, qsIcon, qsTypeIcon, dataIn, dataOut, cutOut, |
| 406 | null); |
| 407 | } |
| 408 | |
| 409 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
| 410 | boolean qsVisible, int qsIcon, int qsTypeIcon, boolean dataIn, boolean dataOut, |
| 411 | boolean cutOut, String typeContentDescription) { |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 412 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
| 413 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 414 | ArgumentCaptor<IconState> qsIconArg = ArgumentCaptor.forClass(IconState.class); |
| 415 | ArgumentCaptor<Integer> qsTypeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 416 | ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class); |
| 417 | ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 418 | ArgumentCaptor<String> typeContentDescriptionArg = ArgumentCaptor.forClass(String.class); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 419 | |
| 420 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
| 421 | iconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 422 | qsIconArg.capture(), |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 423 | typeIconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 424 | qsTypeIconArg.capture(), |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 425 | dataInArg.capture(), |
| 426 | dataOutArg.capture(), |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 427 | typeContentDescriptionArg.capture(), |
| 428 | anyString(), anyBoolean(), anyInt(), anyBoolean()); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 429 | |
| 430 | IconState iconState = iconArg.getValue(); |
| 431 | |
andychou | b935e68 | 2019-04-11 23:40:49 +0800 | [diff] [blame] | 432 | int numSignalStrengthBins = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; |
| 433 | if (mMobileSignalController.mInflateSignalStrengths) { |
| 434 | numSignalStrengthBins++; |
| 435 | icon++; |
| 436 | } |
| 437 | int state = SignalDrawable.getState(icon, numSignalStrengthBins, cutOut); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 438 | assertEquals("Data icon in status bar", typeIcon, (int) typeIconArg.getValue()); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 439 | assertEquals("Signal icon in status bar", state, iconState.icon); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 440 | assertEquals("Visibility in status bar", visible, iconState.visible); |
| 441 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 442 | iconState = qsIconArg.getValue(); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 443 | assertEquals("Visibility in quick settings", qsVisible, iconState.visible); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 444 | assertEquals("Signal icon in quick settings", state, iconState.icon); |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 445 | assertEquals("Data icon in quick settings", qsTypeIcon, (int) qsTypeIconArg.getValue()); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 446 | assertEquals("Data direction in in quick settings", dataIn, |
| 447 | (boolean) dataInArg.getValue()); |
| 448 | assertEquals("Data direction out in quick settings", dataOut, |
| 449 | (boolean) dataOutArg.getValue()); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 450 | if (typeContentDescription != null) { // Only check if it was provided |
| 451 | assertEquals("Type content description", typeContentDescription, |
| 452 | typeContentDescriptionArg.getValue()); |
| 453 | } |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 454 | } |
| 455 | |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 456 | protected void assertNetworkNameEquals(String expected) { |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 457 | assertEquals("Network name", expected, mMobileSignalController.getState().networkName); |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | protected void assertDataNetworkNameEquals(String expected) { |
| 461 | assertEquals("Data network name", expected, mNetworkController.getMobileDataNetworkName()); |
| 462 | } |
| 463 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 464 | } |