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