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; |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 20 | |
| 21 | import static org.mockito.Matchers.any; |
| 22 | import static org.mockito.Matchers.anyBoolean; |
| 23 | import static org.mockito.Matchers.anyInt; |
| 24 | import static org.mockito.Matchers.anyString; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 25 | import static org.mockito.Matchers.eq; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 26 | import static org.mockito.Mockito.doAnswer; |
Jason Monk | f6a3cf9 | 2016-02-29 13:01:08 -0500 | [diff] [blame] | 27 | import static org.mockito.Mockito.mock; |
| 28 | import static org.mockito.Mockito.when; |
| 29 | |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 30 | import android.content.Intent; |
| 31 | import android.net.ConnectivityManager; |
| 32 | import android.net.NetworkCapabilities; |
| 33 | import android.net.wifi.WifiManager; |
| 34 | import android.provider.Settings; |
| 35 | import android.provider.Settings.Global; |
| 36 | import android.telephony.PhoneStateListener; |
| 37 | import android.telephony.ServiceState; |
| 38 | import android.telephony.SignalStrength; |
| 39 | import android.telephony.SubscriptionInfo; |
| 40 | import android.telephony.SubscriptionManager; |
| 41 | import android.telephony.TelephonyManager; |
| 42 | import android.testing.TestableLooper; |
| 43 | import android.util.Log; |
| 44 | |
| 45 | import com.android.internal.telephony.cdma.EriInfo; |
Evan Laird | 06e9fd8 | 2018-02-10 09:36:55 -0800 | [diff] [blame^] | 46 | import com.android.settingslib.graph.SignalDrawable; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 47 | import com.android.settingslib.net.DataUsageController; |
| 48 | import com.android.systemui.SysuiTestCase; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
| 50 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
| 51 | import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; |
| 52 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config; |
| 53 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionDefaults; |
| 54 | |
| 55 | import org.junit.Before; |
| 56 | import org.junit.Rule; |
| 57 | import org.junit.rules.TestWatcher; |
| 58 | import org.junit.runner.Description; |
| 59 | import org.mockito.ArgumentCaptor; |
| 60 | import org.mockito.Mockito; |
| 61 | |
| 62 | import java.io.PrintWriter; |
| 63 | import java.io.StringWriter; |
| 64 | import java.util.ArrayList; |
| 65 | import java.util.List; |
| 66 | |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 67 | public class NetworkControllerBaseTest extends SysuiTestCase { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 68 | private static final String TAG = "NetworkControllerBaseTest"; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 69 | protected static final int DEFAULT_LEVEL = 2; |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 70 | protected static final int DEFAULT_SIGNAL_STRENGTH = DEFAULT_LEVEL; |
| 71 | protected static final int DEFAULT_QS_SIGNAL_STRENGTH = DEFAULT_LEVEL; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 72 | protected static final int DEFAULT_ICON = TelephonyIcons.ICON_3G; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 73 | protected static final int DEFAULT_QS_ICON = TelephonyIcons.QS_DATA_3G; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 74 | |
| 75 | protected NetworkControllerImpl mNetworkController; |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 76 | protected MobileSignalController mMobileSignalController; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 77 | protected PhoneStateListener mPhoneStateListener; |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 78 | protected SignalStrength mSignalStrength; |
| 79 | protected ServiceState mServiceState; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 80 | protected ConnectivityManager mMockCm; |
| 81 | protected WifiManager mMockWm; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 82 | protected SubscriptionManager mMockSm; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 83 | protected TelephonyManager mMockTm; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 84 | protected Config mConfig; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 85 | protected CallbackHandler mCallbackHandler; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 86 | protected SubscriptionDefaults mMockSubDefaults; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 87 | protected DeviceProvisionedController mMockProvisionController; |
| 88 | protected DeviceProvisionedListener mUserCallback; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 89 | |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 90 | protected int mSubId; |
| 91 | |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 92 | private NetworkCapabilities mNetCapabilities; |
| 93 | |
Geoffrey Pitsch | d80035a | 2016-09-14 09:34:17 -0400 | [diff] [blame] | 94 | @Rule |
| 95 | public TestWatcher failWatcher = new TestWatcher() { |
| 96 | @Override |
| 97 | protected void failed(Throwable e, Description description) { |
| 98 | // Print out mNetworkController state if the test fails. |
| 99 | StringWriter sw = new StringWriter(); |
| 100 | PrintWriter pw = new PrintWriter(sw); |
| 101 | mNetworkController.dump(null, pw, null); |
| 102 | pw.flush(); |
| 103 | Log.d(TAG, sw.toString()); |
| 104 | } |
| 105 | }; |
| 106 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 107 | @Before |
| 108 | public void setUp() throws Exception { |
Jason Monk | a3c3d85 | 2017-08-14 11:04:42 -0400 | [diff] [blame] | 109 | Settings.Global.putInt(mContext.getContentResolver(), Global.AIRPLANE_MODE_ON, 0); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 110 | mMockWm = mock(WifiManager.class); |
| 111 | mMockTm = mock(TelephonyManager.class); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 112 | mMockSm = mock(SubscriptionManager.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 113 | mMockCm = mock(ConnectivityManager.class); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 114 | mMockSubDefaults = mock(SubscriptionDefaults.class); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 115 | mNetCapabilities = new NetworkCapabilities(); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 116 | when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 117 | when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn( |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 118 | new NetworkCapabilities[] { mNetCapabilities }); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 119 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 120 | mSignalStrength = mock(SignalStrength.class); |
| 121 | mServiceState = mock(ServiceState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 122 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 123 | mConfig = new Config(); |
| 124 | mConfig.hspaDataDistinguishable = true; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 125 | mCallbackHandler = mock(CallbackHandler.class); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 126 | |
| 127 | mMockProvisionController = mock(DeviceProvisionedController.class); |
| 128 | when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(true); |
| 129 | doAnswer(invocation -> { |
| 130 | mUserCallback = (DeviceProvisionedListener) invocation.getArguments()[0]; |
| 131 | mUserCallback.onUserSetupChanged(); |
| 132 | mUserCallback.onDeviceProvisionedChanged(); |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 133 | TestableLooper.get(this).processAllMessages(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 134 | return null; |
| 135 | }).when(mMockProvisionController).addCallback(any()); |
| 136 | |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 137 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 138 | mConfig, TestableLooper.get(this).getLooper(), mCallbackHandler, |
Jason Monk | f668d7cc | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 139 | mock(AccessPointControllerImpl.class), mock(DataUsageController.class), |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 140 | mMockSubDefaults, mMockProvisionController); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 141 | setupNetworkController(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 142 | |
| 143 | // Trigger blank callbacks to always get the current state (some tests don't trigger |
| 144 | // changes from default state). |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 145 | mNetworkController.addCallback(mock(SignalCallback.class)); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 146 | mNetworkController.addEmergencyListener(null); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | protected void setupNetworkController() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 150 | // 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] | 151 | mSubId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
Jason Monk | f6a3cf9 | 2016-02-29 13:01:08 -0500 | [diff] [blame] | 152 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(true); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 153 | setDefaultSubId(mSubId); |
| 154 | setSubscriptions(mSubId); |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 155 | mMobileSignalController = mNetworkController.mMobileSignalControllers.get(mSubId); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 156 | mPhoneStateListener = mMobileSignalController.mPhoneStateListener; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 157 | } |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 158 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 159 | protected void setDefaultSubId(int subId) { |
| 160 | when(mMockSubDefaults.getDefaultDataSubId()).thenReturn(subId); |
| 161 | when(mMockSubDefaults.getDefaultVoiceSubId()).thenReturn(subId); |
| 162 | } |
| 163 | |
| 164 | protected void setSubscriptions(int... subIds) { |
| 165 | List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>(); |
| 166 | for (int subId : subIds) { |
| 167 | SubscriptionInfo subscription = mock(SubscriptionInfo.class); |
| 168 | when(subscription.getSubscriptionId()).thenReturn(subId); |
| 169 | subs.add(subscription); |
| 170 | } |
| 171 | when(mMockSm.getActiveSubscriptionInfoList()).thenReturn(subs); |
| 172 | mNetworkController.doUpdateMobileControllers(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 175 | protected NetworkControllerImpl setUpNoMobileData() { |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 176 | when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false); |
| 177 | NetworkControllerImpl networkControllerNoMobile |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 178 | = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 179 | mConfig, TestableLooper.get(this).getLooper(), mCallbackHandler, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 180 | mock(AccessPointControllerImpl.class), |
| 181 | mock(DataUsageController.class), mMockSubDefaults, |
| 182 | mock(DeviceProvisionedController.class)); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 183 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 184 | setupNetworkController(); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 185 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 186 | return networkControllerNoMobile; |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 187 | |
| 188 | } |
| 189 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 190 | // 2 Bars 3G GSM. |
| 191 | public void setupDefaultSignal() { |
| 192 | setIsGsm(true); |
| 193 | setVoiceRegState(ServiceState.STATE_IN_SERVICE); |
| 194 | setGsmRoaming(false); |
| 195 | setLevel(DEFAULT_LEVEL); |
| 196 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 197 | TelephonyManager.NETWORK_TYPE_UMTS); |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 198 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, true, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 201 | public void setConnectivity(int networkType, boolean inetCondition, boolean isConnected) { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 202 | Intent i = new Intent(ConnectivityManager.INET_CONDITION_ACTION); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 203 | // TODO: Separate out into several NetworkCapabilities. |
| 204 | if (isConnected) { |
| 205 | mNetCapabilities.addTransportType(networkType); |
| 206 | } else { |
| 207 | mNetCapabilities.removeTransportType(networkType); |
| 208 | } |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 209 | if (inetCondition) { |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 210 | mNetCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 211 | } else { |
| 212 | mNetCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 213 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 214 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 215 | mNetworkController.onReceive(mContext, i); |
| 216 | } |
| 217 | |
| 218 | public void setGsmRoaming(boolean isRoaming) { |
| 219 | when(mServiceState.getRoaming()).thenReturn(isRoaming); |
| 220 | updateServiceState(); |
| 221 | } |
| 222 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 223 | public void setCdmaRoaming(boolean isRoaming) { |
| 224 | when(mServiceState.getCdmaEriIconIndex()).thenReturn(isRoaming ? |
| 225 | EriInfo.ROAMING_INDICATOR_ON : EriInfo.ROAMING_INDICATOR_OFF); |
| 226 | when(mServiceState.getCdmaEriIconMode()).thenReturn(isRoaming ? |
| 227 | EriInfo.ROAMING_ICON_MODE_NORMAL : -1); |
| 228 | updateServiceState(); |
| 229 | } |
| 230 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 231 | public void setVoiceRegState(int voiceRegState) { |
| 232 | when(mServiceState.getVoiceRegState()).thenReturn(voiceRegState); |
| 233 | updateServiceState(); |
| 234 | } |
| 235 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 236 | public void setDataRegState(int dataRegState) { |
| 237 | when(mServiceState.getDataRegState()).thenReturn(dataRegState); |
| 238 | updateServiceState(); |
| 239 | } |
| 240 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 241 | public void setIsEmergencyOnly(boolean isEmergency) { |
| 242 | when(mServiceState.isEmergencyOnly()).thenReturn(isEmergency); |
| 243 | updateServiceState(); |
| 244 | } |
| 245 | |
| 246 | public void setCdmaLevel(int level) { |
| 247 | when(mSignalStrength.getCdmaLevel()).thenReturn(level); |
| 248 | updateSignalStrength(); |
| 249 | } |
| 250 | |
| 251 | public void setLevel(int level) { |
| 252 | when(mSignalStrength.getLevel()).thenReturn(level); |
| 253 | updateSignalStrength(); |
| 254 | } |
| 255 | |
| 256 | public void setIsGsm(boolean gsm) { |
| 257 | when(mSignalStrength.isGsm()).thenReturn(gsm); |
| 258 | updateSignalStrength(); |
| 259 | } |
| 260 | |
| 261 | public void setCdmaEri(int index, int mode) { |
| 262 | // TODO: Figure this out. |
| 263 | } |
| 264 | |
| 265 | private void updateSignalStrength() { |
| 266 | Log.d(TAG, "Sending Signal Strength: " + mSignalStrength); |
| 267 | mPhoneStateListener.onSignalStrengthsChanged(mSignalStrength); |
| 268 | } |
| 269 | |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 270 | protected void updateServiceState() { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 271 | Log.d(TAG, "Sending Service State: " + mServiceState); |
| 272 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 273 | } |
| 274 | |
| 275 | public void updateCallState(int state) { |
| 276 | // Inputs not currently used in NetworkControllerImpl. |
| 277 | mPhoneStateListener.onCallStateChanged(state, "0123456789"); |
| 278 | } |
| 279 | |
| 280 | public void updateDataConnectionState(int dataState, int dataNetType) { |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 281 | when(mServiceState.getDataNetworkType()).thenReturn(dataNetType); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 282 | mPhoneStateListener.onDataConnectionStateChanged(dataState, dataNetType); |
| 283 | } |
| 284 | |
| 285 | public void updateDataActivity(int dataActivity) { |
| 286 | mPhoneStateListener.onDataActivity(dataActivity); |
| 287 | } |
| 288 | |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 289 | public void setCarrierNetworkChange(boolean enable) { |
| 290 | Log.d(TAG, "setCarrierNetworkChange(" + enable + ")"); |
| 291 | mPhoneStateListener.onCarrierNetworkChange(enable); |
| 292 | } |
| 293 | |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 294 | protected void verifyHasNoSims(boolean hasNoSimsVisible) { |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 295 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setNoSims( |
| 296 | eq(hasNoSimsVisible), eq(false)); |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 299 | protected void verifyLastQsMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 300 | boolean dataIn, boolean dataOut) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 301 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 302 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 303 | ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class); |
| 304 | ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 305 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 306 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 307 | any(), |
| 308 | iconArg.capture(), |
| 309 | anyInt(), |
| 310 | typeIconArg.capture(), dataInArg.capture(), dataOutArg.capture(), |
| 311 | anyString(), anyString(), anyBoolean(), anyInt(), anyBoolean()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 312 | IconState iconState = iconArg.getValue(); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 313 | int state = SignalDrawable.getState(icon, SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 314 | false); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 315 | assertEquals("Visibility in, quick settings", visible, iconState.visible); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 316 | assertEquals("Signal icon in, quick settings", state, iconState.icon); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 317 | assertEquals("Data icon in, quick settings", typeIcon, (int) typeIconArg.getValue()); |
| 318 | assertEquals("Data direction in, in quick settings", dataIn, |
| 319 | (boolean) dataInArg.getValue()); |
| 320 | assertEquals("Data direction out, in quick settings", dataOut, |
| 321 | (boolean) dataOutArg.getValue()); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon) { |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 325 | verifyLastMobileDataIndicators(visible, icon, typeIcon, false); |
| 326 | } |
| 327 | |
| 328 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
| 329 | boolean roaming) { |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 330 | verifyLastMobileDataIndicators(visible, icon, typeIcon, roaming, true); |
| 331 | } |
| 332 | |
| 333 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 334 | boolean roaming, boolean inet) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 335 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 336 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 337 | |
| 338 | // TODO: Verify all fields. |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 339 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
| 340 | iconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 341 | any(), |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 342 | typeIconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 343 | anyInt(), anyBoolean(), anyBoolean(), anyString(), anyString(), anyBoolean(), |
| 344 | anyInt(), eq(roaming)); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 345 | IconState iconState = iconArg.getValue(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 346 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 347 | int state = icon == -1 ? 0 |
| 348 | : SignalDrawable.getState(icon, SignalStrength.NUM_SIGNAL_STRENGTH_BINS, !inet); |
| 349 | assertEquals("Signal icon in status bar", state, iconState.icon); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 350 | assertEquals("Data icon in status bar", typeIcon, (int) typeIconArg.getValue()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 351 | assertEquals("Visibility in status bar", visible, iconState.visible); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 352 | } |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 353 | |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 354 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 355 | boolean qsVisible, int qsIcon, int qsTypeIcon, boolean dataIn, boolean dataOut) { |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 356 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
| 357 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 358 | ArgumentCaptor<IconState> qsIconArg = ArgumentCaptor.forClass(IconState.class); |
| 359 | ArgumentCaptor<Integer> qsTypeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 360 | ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class); |
| 361 | ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class); |
| 362 | |
| 363 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
| 364 | iconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 365 | qsIconArg.capture(), |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 366 | typeIconArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 367 | qsTypeIconArg.capture(), |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 368 | dataInArg.capture(), |
| 369 | dataOutArg.capture(), |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 370 | anyString(), anyString(), anyBoolean(), anyInt(), anyBoolean()); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 371 | |
| 372 | IconState iconState = iconArg.getValue(); |
| 373 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 374 | int state = SignalDrawable.getState(icon, SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 375 | false); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 376 | assertEquals("Data icon in status bar", typeIcon, (int) typeIconArg.getValue()); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 377 | assertEquals("Signal icon in status bar", state, iconState.icon); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 378 | assertEquals("Visibility in status bar", visible, iconState.visible); |
| 379 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 380 | iconState = qsIconArg.getValue(); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 381 | assertEquals("Visibility in quick settings", qsVisible, iconState.visible); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 382 | assertEquals("Signal icon in quick settings", state, iconState.icon); |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 383 | assertEquals("Data icon in quick settings", qsTypeIcon, (int) qsTypeIconArg.getValue()); |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 384 | assertEquals("Data direction in in quick settings", dataIn, |
| 385 | (boolean) dataInArg.getValue()); |
| 386 | assertEquals("Data direction out in quick settings", dataOut, |
| 387 | (boolean) dataOutArg.getValue()); |
| 388 | } |
| 389 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 390 | protected void assertNetworkNameEquals(String expected) { |
| 391 | assertEquals("Network name", expected, mMobileSignalController.getState().networkName); |
| 392 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 393 | } |