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