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