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 | package com.android.systemui.statusbar.policy; |
| 17 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 18 | import static junit.framework.Assert.assertEquals; |
| 19 | import static junit.framework.Assert.assertFalse; |
| 20 | import static junit.framework.Assert.assertTrue; |
| 21 | |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 25 | import android.net.ConnectivityManager; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 26 | import android.net.NetworkCapabilities; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 27 | import android.os.Looper; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 28 | import android.telephony.ServiceState; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 29 | import android.telephony.SignalStrength; |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 30 | import android.telephony.SubscriptionInfo; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 31 | import android.telephony.TelephonyManager; |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 32 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 33 | import android.testing.AndroidTestingRunner; |
| 34 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 35 | |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 36 | import com.android.internal.telephony.PhoneConstants; |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 37 | import com.android.internal.telephony.TelephonyIntents; |
Evan Laird | 06e9fd8 | 2018-02-10 09:36:55 -0800 | [diff] [blame] | 38 | import com.android.settingslib.graph.SignalDrawable; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 39 | import com.android.settingslib.net.DataUsageController; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 40 | import com.android.systemui.R; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 41 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 42 | import org.junit.Test; |
| 43 | import org.junit.runner.RunWith; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 44 | import org.mockito.ArgumentCaptor; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 45 | import org.mockito.Mockito; |
| 46 | |
| 47 | import java.util.ArrayList; |
| 48 | import java.util.List; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 49 | |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 50 | @SmallTest |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 51 | @RunWith(AndroidTestingRunner.class) |
| 52 | @RunWithLooper |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 53 | public class NetworkControllerSignalTest extends NetworkControllerBaseTest { |
| 54 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 55 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 56 | public void testNoIconWithoutMobile() { |
| 57 | // Turn off mobile network support. |
| 58 | Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false); |
| 59 | // Create a new NetworkController as this is currently handled in constructor. |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 60 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 61 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 62 | mock(AccessPointControllerImpl.class), mock(DataUsageController.class), |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 63 | mMockSubDefaults, mock(DeviceProvisionedController.class)); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 64 | setupNetworkController(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 65 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 66 | verifyLastMobileDataIndicators(false, -1, 0); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 67 | } |
| 68 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 69 | @Test |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 70 | public void testNoSimsIconPresent() { |
| 71 | // No Subscriptions. |
| 72 | mNetworkController.mMobileSignalControllers.clear(); |
| 73 | mNetworkController.updateNoSims(); |
| 74 | |
| 75 | verifyHasNoSims(true); |
| 76 | } |
| 77 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 78 | @Test |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 79 | public void testEmergencyOnly() { |
| 80 | setupDefaultSignal(); |
| 81 | mNetworkController.recalculateEmergency(); |
| 82 | verifyEmergencyOnly(false); |
| 83 | |
| 84 | mMobileSignalController.getState().isEmergency = true; |
| 85 | mNetworkController.recalculateEmergency(); |
| 86 | verifyEmergencyOnly(true); |
| 87 | } |
| 88 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 89 | @Test |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 90 | public void testEmergencyOnlyNoSubscriptions() { |
| 91 | setupDefaultSignal(); |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 92 | setSubscriptions(); |
| 93 | mNetworkController.mLastServiceState = new ServiceState(); |
| 94 | mNetworkController.mLastServiceState.setEmergencyOnly(true); |
| 95 | mNetworkController.recalculateEmergency(); |
| 96 | verifyEmergencyOnly(true); |
| 97 | } |
| 98 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 99 | @Test |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 100 | public void testNoEmergencyOnlyWrongSubscription() { |
| 101 | setupDefaultSignal(); |
| 102 | setDefaultSubId(42); |
| 103 | mNetworkController.recalculateEmergency(); |
| 104 | verifyEmergencyOnly(false); |
| 105 | } |
| 106 | |
| 107 | @Test |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 108 | public void testNoEmengencyNoSubscriptions() { |
| 109 | setupDefaultSignal(); |
| 110 | setSubscriptions(); |
| 111 | mNetworkController.mLastServiceState = new ServiceState(); |
| 112 | mNetworkController.mLastServiceState.setEmergencyOnly(false); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 113 | mNetworkController.recalculateEmergency(); |
| 114 | verifyEmergencyOnly(false); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 117 | @Test |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 118 | public void testNoSimlessIconWithoutMobile() { |
| 119 | // Turn off mobile network support. |
| 120 | Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false); |
| 121 | // Create a new NetworkController as this is currently handled in constructor. |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 122 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 123 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 124 | mock(AccessPointControllerImpl.class), mock(DataUsageController.class), |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 125 | mMockSubDefaults, mock(DeviceProvisionedController.class)); |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 126 | setupNetworkController(); |
| 127 | |
| 128 | // No Subscriptions. |
| 129 | mNetworkController.mMobileSignalControllers.clear(); |
| 130 | mNetworkController.updateNoSims(); |
| 131 | |
| 132 | verifyHasNoSims(false); |
| 133 | } |
| 134 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 135 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 136 | public void testSignalStrength() { |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 137 | for (int testStrength = 0; |
| 138 | testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) { |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 139 | setupDefaultSignal(); |
| 140 | setLevel(testStrength); |
| 141 | |
| 142 | verifyLastMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 143 | testStrength, DEFAULT_ICON); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 144 | |
| 145 | // Verify low inet number indexing. |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 146 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 147 | verifyLastMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 148 | testStrength, DEFAULT_ICON, false, false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 152 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 153 | public void testCdmaSignalStrength() { |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 154 | for (int testStrength = 0; |
| 155 | testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) { |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 156 | setupDefaultSignal(); |
| 157 | setCdma(); |
| 158 | setLevel(testStrength); |
| 159 | |
| 160 | verifyLastMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 161 | testStrength, |
| 162 | TelephonyIcons.ICON_1X); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 163 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 166 | @Test |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 167 | public void testSignalRoaming() { |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 168 | for (int testStrength = 0; |
| 169 | testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) { |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 170 | setupDefaultSignal(); |
| 171 | setGsmRoaming(true); |
| 172 | setLevel(testStrength); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 173 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 174 | verifyLastMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 175 | testStrength, |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 176 | DEFAULT_ICON, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 180 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 181 | public void testCdmaSignalRoaming() { |
| 182 | for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
| 183 | testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) { |
| 184 | setupDefaultSignal(); |
| 185 | setCdma(); |
| 186 | setCdmaRoaming(true); |
| 187 | setLevel(testStrength); |
| 188 | |
| 189 | verifyLastMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 190 | testStrength, |
| 191 | TelephonyIcons.ICON_1X, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 195 | @Test |
Jason Monk | e153198 | 2017-09-05 11:20:30 -0400 | [diff] [blame] | 196 | public void testRoamingNoService_DoesNotCrash() { |
| 197 | setupDefaultSignal(); |
| 198 | setCdma(); |
| 199 | mServiceState = null; |
| 200 | updateServiceState(); |
| 201 | } |
| 202 | |
| 203 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 204 | public void testQsSignalStrength() { |
| 205 | for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
| 206 | testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) { |
| 207 | setupDefaultSignal(); |
| 208 | setLevel(testStrength); |
| 209 | |
| 210 | verifyLastQsMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 211 | testStrength, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 212 | DEFAULT_QS_ICON, false, false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 216 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 217 | public void testCdmaQsSignalStrength() { |
| 218 | for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
| 219 | testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) { |
| 220 | setupDefaultSignal(); |
| 221 | setCdma(); |
| 222 | setLevel(testStrength); |
| 223 | |
| 224 | verifyLastQsMobileDataIndicators(true, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 225 | testStrength, |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 226 | TelephonyIcons.ICON_1X, false, false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 230 | @Test |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 231 | public void testNoBangWithWifi() { |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 232 | setupDefaultSignal(); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 233 | setConnectivityViaBroadcast(mMobileSignalController.mTransportType, false, false); |
| 234 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_WIFI, true, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 235 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 236 | verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 239 | // Some tests of actual NetworkController code, just internals not display stuff |
| 240 | // TODO: Put this somewhere else, maybe in its own file. |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 241 | @Test |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 242 | public void testHasCorrectMobileControllers() { |
| 243 | int[] testSubscriptions = new int[] { 1, 5, 3 }; |
| 244 | int notTestSubscription = 0; |
| 245 | MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class); |
| 246 | |
| 247 | mNetworkController.mMobileSignalControllers.clear(); |
| 248 | List<SubscriptionInfo> subscriptions = new ArrayList<>(); |
| 249 | for (int i = 0; i < testSubscriptions.length; i++) { |
| 250 | // Force the test controllers into NetworkController. |
| 251 | mNetworkController.mMobileSignalControllers.put(testSubscriptions[i], |
| 252 | mobileSignalController); |
| 253 | |
| 254 | // Generate a list of subscriptions we will tell the NetworkController to use. |
| 255 | SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class); |
| 256 | Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]); |
| 257 | subscriptions.add(mockSubInfo); |
| 258 | } |
| 259 | assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions)); |
| 260 | |
| 261 | // Add a subscription that the NetworkController doesn't know about. |
| 262 | SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class); |
| 263 | Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription); |
| 264 | subscriptions.add(mockSubInfo); |
| 265 | assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions)); |
| 266 | } |
| 267 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 268 | @Test |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 269 | public void testSetCurrentSubscriptions() { |
| 270 | // We will not add one controller to make sure it gets created. |
| 271 | int indexToSkipController = 0; |
| 272 | // We will not add one subscription to make sure it's controller gets removed. |
| 273 | int indexToSkipSubscription = 1; |
| 274 | |
| 275 | int[] testSubscriptions = new int[] { 1, 5, 3 }; |
| 276 | MobileSignalController[] mobileSignalControllers = new MobileSignalController[] { |
| 277 | Mockito.mock(MobileSignalController.class), |
| 278 | Mockito.mock(MobileSignalController.class), |
| 279 | Mockito.mock(MobileSignalController.class), |
| 280 | }; |
| 281 | mNetworkController.mMobileSignalControllers.clear(); |
| 282 | List<SubscriptionInfo> subscriptions = new ArrayList<>(); |
| 283 | for (int i = 0; i < testSubscriptions.length; i++) { |
| 284 | if (i != indexToSkipController) { |
| 285 | // Force the test controllers into NetworkController. |
| 286 | mNetworkController.mMobileSignalControllers.put(testSubscriptions[i], |
| 287 | mobileSignalControllers[i]); |
| 288 | } |
| 289 | |
| 290 | if (i != indexToSkipSubscription) { |
| 291 | // Generate a list of subscriptions we will tell the NetworkController to use. |
| 292 | SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class); |
| 293 | Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]); |
| 294 | Mockito.when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]); |
| 295 | subscriptions.add(mockSubInfo); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // We can only test whether unregister gets called if it thinks its in a listening |
| 300 | // state. |
| 301 | mNetworkController.mListening = true; |
| 302 | mNetworkController.setCurrentSubscriptions(subscriptions); |
| 303 | |
| 304 | for (int i = 0; i < testSubscriptions.length; i++) { |
| 305 | if (i == indexToSkipController) { |
| 306 | // Make sure a controller was created despite us not adding one. |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 307 | assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey( |
| 308 | testSubscriptions[i]) >= 0); |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 309 | } else if (i == indexToSkipSubscription) { |
| 310 | // Make sure the controller that did exist was removed |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 311 | assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey( |
| 312 | testSubscriptions[i]) >= 0); |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 313 | } else { |
| 314 | // If a MobileSignalController is around it needs to not be unregistered. |
| 315 | Mockito.verify(mobileSignalControllers[i], Mockito.never()) |
| 316 | .unregisterListener(); |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 321 | @Test |
Jason Monk | 7f9623f | 2015-02-11 09:03:02 -0500 | [diff] [blame] | 322 | public void testHistorySize() { |
| 323 | // Verify valid history size, otherwise it gits printed out the wrong order and whatnot. |
| 324 | assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1)); |
| 325 | } |
| 326 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 327 | private void setCdma() { |
| 328 | setIsGsm(false); |
| 329 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 330 | TelephonyManager.NETWORK_TYPE_CDMA); |
| 331 | setCdmaRoaming(false); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 332 | } |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 333 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 334 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 335 | public void testOnReceive_stringsUpdatedAction_spn() { |
| 336 | String expectedMNetworkName = "Test"; |
| 337 | Intent intent = createStringsUpdatedIntent(true /* showSpn */, |
| 338 | expectedMNetworkName /* spn */, |
| 339 | false /* showPlmn */, |
| 340 | "NotTest" /* plmn */); |
| 341 | |
| 342 | mNetworkController.onReceive(mContext, intent); |
| 343 | |
| 344 | assertNetworkNameEquals(expectedMNetworkName); |
| 345 | } |
| 346 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 347 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 348 | public void testOnReceive_stringsUpdatedAction_plmn() { |
| 349 | String expectedMNetworkName = "Test"; |
| 350 | |
| 351 | Intent intent = createStringsUpdatedIntent(false /* showSpn */, |
| 352 | "NotTest" /* spn */, |
| 353 | true /* showPlmn */, |
| 354 | expectedMNetworkName /* plmn */); |
| 355 | |
| 356 | mNetworkController.onReceive(mContext, intent); |
| 357 | |
| 358 | assertNetworkNameEquals(expectedMNetworkName); |
| 359 | } |
| 360 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 361 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 362 | public void testOnReceive_stringsUpdatedAction_bothFalse() { |
| 363 | Intent intent = createStringsUpdatedIntent(false /* showSpn */, |
| 364 | "Irrelevant" /* spn */, |
| 365 | false /* showPlmn */, |
| 366 | "Irrelevant" /* plmn */); |
| 367 | |
| 368 | mNetworkController.onReceive(mContext, intent); |
| 369 | |
| 370 | String defaultNetworkName = mMobileSignalController |
| 371 | .getStringIfExists( |
| 372 | com.android.internal.R.string.lockscreen_carrier_default); |
| 373 | assertNetworkNameEquals(defaultNetworkName); |
| 374 | } |
| 375 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 376 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 377 | public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() { |
| 378 | Intent intent = createStringsUpdatedIntent(true /* showSpn */, |
| 379 | null /* spn */, |
| 380 | true /* showPlmn */, |
| 381 | null /* plmn */); |
| 382 | |
| 383 | mNetworkController.onReceive(mContext, intent); |
| 384 | |
| 385 | String defaultNetworkName = mMobileSignalController.getStringIfExists( |
| 386 | com.android.internal.R.string.lockscreen_carrier_default); |
| 387 | assertNetworkNameEquals(defaultNetworkName); |
| 388 | } |
| 389 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 390 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 391 | public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() { |
| 392 | String spn = "Test1"; |
| 393 | String plmn = "Test2"; |
| 394 | |
| 395 | Intent intent = createStringsUpdatedIntent(true /* showSpn */, |
| 396 | spn /* spn */, |
| 397 | true /* showPlmn */, |
| 398 | plmn /* plmn */); |
| 399 | |
| 400 | mNetworkController.onReceive(mContext, intent); |
| 401 | |
| 402 | assertNetworkNameEquals(plmn |
| 403 | + mMobileSignalController.getStringIfExists( |
| 404 | R.string.status_bar_network_name_separator) |
| 405 | + spn); |
| 406 | } |
| 407 | |
| 408 | private Intent createStringsUpdatedIntent(boolean showSpn, String spn, |
| 409 | boolean showPlmn, String plmn) { |
| 410 | |
| 411 | Intent intent = new Intent(); |
| 412 | intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION); |
| 413 | |
| 414 | intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn); |
| 415 | intent.putExtra(TelephonyIntents.EXTRA_SPN, spn); |
| 416 | |
| 417 | intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn); |
| 418 | intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn); |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 419 | intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 420 | |
| 421 | return intent; |
| 422 | } |
| 423 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 424 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 425 | public void testOnUpdateDataActivity_dataIn() { |
| 426 | setupDefaultSignal(); |
| 427 | |
| 428 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN); |
| 429 | |
| 430 | verifyLastQsMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 431 | DEFAULT_LEVEL /* icon */, |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 432 | DEFAULT_QS_ICON /* typeIcon */, |
| 433 | true /* dataIn */, |
| 434 | false /* dataOut */); |
| 435 | |
| 436 | } |
| 437 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 438 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 439 | public void testOnUpdateDataActivity_dataOut() { |
| 440 | setupDefaultSignal(); |
| 441 | |
| 442 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT); |
| 443 | |
| 444 | verifyLastQsMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 445 | DEFAULT_LEVEL /* icon */, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 446 | DEFAULT_QS_ICON /* typeIcon */, |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 447 | false /* dataIn */, |
| 448 | true /* dataOut */); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 451 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 452 | public void testOnUpdateDataActivity_dataInOut() { |
| 453 | setupDefaultSignal(); |
| 454 | |
| 455 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT); |
| 456 | |
| 457 | verifyLastQsMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 458 | DEFAULT_LEVEL /* icon */, |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 459 | DEFAULT_QS_ICON /* typeIcon */, |
| 460 | true /* dataIn */, |
| 461 | true /* dataOut */); |
| 462 | |
| 463 | } |
| 464 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 465 | @Test |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 466 | public void testOnUpdateDataActivity_dataActivityNone() { |
| 467 | setupDefaultSignal(); |
| 468 | |
| 469 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE); |
| 470 | |
| 471 | verifyLastQsMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 472 | DEFAULT_LEVEL /* icon */, |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 473 | DEFAULT_QS_ICON /* typeIcon */, |
| 474 | false /* dataIn */, |
| 475 | false /* dataOut */); |
| 476 | |
| 477 | } |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 478 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 479 | @Test |
Andrew Flynn | 55fc800 | 2015-05-29 08:33:46 -0400 | [diff] [blame] | 480 | public void testCarrierNetworkChange_carrierNetworkChange() { |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 481 | int strength = SignalStrength.SIGNAL_STRENGTH_GREAT; |
| 482 | |
| 483 | setupDefaultSignal(); |
| 484 | setLevel(strength); |
| 485 | |
| 486 | // Verify baseline |
| 487 | verifyLastMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 488 | strength /* strengthIcon */, |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 489 | DEFAULT_ICON /* typeIcon */); |
| 490 | |
Andrew Flynn | 55fc800 | 2015-05-29 08:33:46 -0400 | [diff] [blame] | 491 | // API call is made |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 492 | setCarrierNetworkChange(true /* enabled */); |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 493 | |
Andrew Flynn | 55fc800 | 2015-05-29 08:33:46 -0400 | [diff] [blame] | 494 | // Carrier network change is true, show special indicator |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 495 | verifyLastMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 496 | SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS), |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 497 | 0 /* typeIcon */); |
| 498 | |
| 499 | // Revert back |
| 500 | setCarrierNetworkChange(false /* enabled */); |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 501 | |
| 502 | // Verify back in previous state |
| 503 | verifyLastMobileDataIndicators(true /* visible */, |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 504 | strength /* strengthIcon */, |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 505 | DEFAULT_ICON /* typeIcon */); |
| 506 | } |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 507 | |
Shishir Agrawal | 7ef5b88 | 2017-06-26 12:06:03 -0700 | [diff] [blame] | 508 | @Test |
| 509 | public void testCarrierNetworkChange_roamingBeforeNetworkChange() { |
| 510 | int strength = SignalStrength.SIGNAL_STRENGTH_GREAT; |
| 511 | |
| 512 | setupDefaultSignal(); |
| 513 | setLevel(strength); |
| 514 | setGsmRoaming(true); |
| 515 | |
| 516 | // Verify baseline |
| 517 | verifyLastMobileDataIndicators(true /* visible */, |
| 518 | strength /* strengthIcon */, |
| 519 | DEFAULT_ICON /* typeIcon */, |
| 520 | true /* roaming */); |
| 521 | |
| 522 | // API call is made |
| 523 | setCarrierNetworkChange(true /* enabled */); |
| 524 | |
| 525 | // Carrier network change is true, show special indicator, no roaming. |
| 526 | verifyLastMobileDataIndicators(true /* visible */, |
| 527 | SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS), |
| 528 | 0 /* typeIcon */, |
| 529 | false /* roaming */); |
| 530 | |
| 531 | // Revert back |
| 532 | setCarrierNetworkChange(false /* enabled */); |
| 533 | |
| 534 | // Verify back in previous state |
| 535 | verifyLastMobileDataIndicators(true /* visible */, |
| 536 | strength /* strengthIcon */, |
| 537 | DEFAULT_ICON /* typeIcon */, |
| 538 | true /* roaming */); |
| 539 | } |
| 540 | |
| 541 | @Test |
| 542 | public void testCarrierNetworkChange_roamingAfterNetworkChange() { |
| 543 | int strength = SignalStrength.SIGNAL_STRENGTH_GREAT; |
| 544 | |
| 545 | setupDefaultSignal(); |
| 546 | setLevel(strength); |
| 547 | |
| 548 | // Verify baseline |
| 549 | verifyLastMobileDataIndicators(true /* visible */, |
| 550 | strength /* strengthIcon */, |
| 551 | DEFAULT_ICON /* typeIcon */, |
| 552 | false /* roaming */); |
| 553 | |
| 554 | // API call is made |
| 555 | setCarrierNetworkChange(true /* enabled */); |
| 556 | |
| 557 | // Carrier network change is true, show special indicator, no roaming. |
| 558 | verifyLastMobileDataIndicators(true /* visible */, |
| 559 | SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS), |
| 560 | 0 /* typeIcon */, |
| 561 | false /* roaming */); |
| 562 | |
| 563 | setGsmRoaming(true); |
| 564 | |
| 565 | // Roaming should not show. |
| 566 | verifyLastMobileDataIndicators(true /* visible */, |
| 567 | SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS), |
| 568 | 0 /* typeIcon */, |
| 569 | false /* roaming */); |
| 570 | |
| 571 | // Revert back |
| 572 | setCarrierNetworkChange(false /* enabled */); |
| 573 | |
| 574 | // Verify back in previous state |
| 575 | verifyLastMobileDataIndicators(true /* visible */, |
| 576 | strength /* strengthIcon */, |
| 577 | DEFAULT_ICON /* typeIcon */, |
| 578 | true /* roaming */); |
| 579 | } |
| 580 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 581 | private void verifyEmergencyOnly(boolean isEmergencyOnly) { |
| 582 | ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class); |
| 583 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly( |
| 584 | emergencyOnly.capture()); |
| 585 | assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue()); |
| 586 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 587 | } |