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