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