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