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