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