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