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