Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 1 | /* |
Fabian Kozynski | 00afd49 | 2020-02-15 19:58:10 -0500 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 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 | */ |
| 16 | |
Fabian Kozynski | 00afd49 | 2020-02-15 19:58:10 -0500 | [diff] [blame] | 17 | package com.android.systemui.qs.carrier; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 18 | |
Fabian Kozynski | bc9d52d | 2020-03-27 12:58:44 -0400 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.any; |
| 21 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.anyInt; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 23 | import static org.mockito.Mockito.doAnswer; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 24 | import static org.mockito.Mockito.mock; |
| 25 | import static org.mockito.Mockito.when; |
| 26 | |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 27 | import android.os.Handler; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 28 | import android.telephony.SubscriptionManager; |
| 29 | import android.testing.AndroidTestingRunner; |
| 30 | import android.testing.TestableLooper; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 31 | import android.view.View; |
| 32 | import android.widget.TextView; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 33 | |
| 34 | import androidx.test.filters.SmallTest; |
| 35 | |
| 36 | import com.android.keyguard.CarrierTextController; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 37 | import com.android.systemui.plugins.ActivityStarter; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 38 | import com.android.systemui.statusbar.policy.NetworkController; |
| 39 | import com.android.systemui.utils.leaks.LeakCheckedTest; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 40 | import com.android.systemui.utils.os.FakeHandler; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 41 | |
| 42 | import org.junit.Before; |
| 43 | import org.junit.Test; |
| 44 | import org.junit.runner.RunWith; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 45 | import org.mockito.Mock; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 46 | import org.mockito.Mockito; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 47 | import org.mockito.MockitoAnnotations; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 48 | import org.mockito.stubbing.Answer; |
| 49 | |
| 50 | @RunWith(AndroidTestingRunner.class) |
| 51 | @TestableLooper.RunWithLooper |
| 52 | @SmallTest |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 53 | public class QSCarrierGroupControllerTest extends LeakCheckedTest { |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 54 | |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 55 | private QSCarrierGroupController mQSCarrierGroupController; |
| 56 | private NetworkController.SignalCallback mSignalCallback; |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 57 | private CarrierTextController.CarrierTextCallback mCallback; |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 58 | @Mock |
| 59 | private QSCarrierGroup mQSCarrierGroup; |
| 60 | @Mock |
| 61 | private ActivityStarter mActivityStarter; |
| 62 | @Mock |
| 63 | private NetworkController mNetworkController; |
| 64 | @Mock |
| 65 | private CarrierTextController.Builder mCarrierTextControllerBuilder; |
| 66 | @Mock |
| 67 | private CarrierTextController mCarrierTextController; |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 68 | private TestableLooper mTestableLooper; |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 69 | |
| 70 | @Before |
| 71 | public void setup() throws Exception { |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 72 | MockitoAnnotations.initMocks(this); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 73 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 74 | mTestableLooper = TestableLooper.get(this); |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 75 | Handler handler = new FakeHandler(TestableLooper.get(this).getLooper()); |
| 76 | |
| 77 | when(mNetworkController.hasVoiceCallingFeature()).thenReturn(true); |
| 78 | doAnswer(invocation -> mSignalCallback = invocation.getArgument(0)) |
| 79 | .when(mNetworkController) |
| 80 | .addCallback(any(NetworkController.SignalCallback.class)); |
| 81 | |
| 82 | when(mCarrierTextControllerBuilder.setShowAirplaneMode(anyBoolean())) |
| 83 | .thenReturn(mCarrierTextControllerBuilder); |
| 84 | when(mCarrierTextControllerBuilder.setShowMissingSim(anyBoolean())) |
| 85 | .thenReturn(mCarrierTextControllerBuilder); |
| 86 | when(mCarrierTextControllerBuilder.build()).thenReturn(mCarrierTextController); |
| 87 | |
| 88 | doAnswer(invocation -> mCallback = invocation.getArgument(0)) |
| 89 | .when(mCarrierTextController) |
| 90 | .setListening(any(CarrierTextController.CarrierTextCallback.class)); |
| 91 | |
| 92 | when(mQSCarrierGroup.getNoSimTextView()).thenReturn(new TextView(mContext)); |
| 93 | when(mQSCarrierGroup.getCarrier1View()).thenReturn(mock(QSCarrier.class)); |
| 94 | when(mQSCarrierGroup.getCarrier2View()).thenReturn(mock(QSCarrier.class)); |
| 95 | when(mQSCarrierGroup.getCarrier3View()).thenReturn(mock(QSCarrier.class)); |
| 96 | when(mQSCarrierGroup.getCarrierDivider1()).thenReturn(new View(mContext)); |
| 97 | when(mQSCarrierGroup.getCarrierDivider2()).thenReturn(new View(mContext)); |
| 98 | |
| 99 | mQSCarrierGroupController = new QSCarrierGroupController.Builder( |
| 100 | mActivityStarter, handler, TestableLooper.get(this).getLooper(), |
| 101 | mNetworkController, mCarrierTextControllerBuilder) |
| 102 | .setQSCarrierGroup(mQSCarrierGroup) |
| 103 | .build(); |
| 104 | |
| 105 | mQSCarrierGroupController.setListening(true); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test // throws no Exception |
| 109 | public void testUpdateCarrierText_sameLengths() { |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 110 | QSCarrierGroupController spiedCarrierGroupController = |
| 111 | Mockito.spy(mQSCarrierGroupController); |
| 112 | when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenAnswer( |
| 113 | (Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0)); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 114 | |
| 115 | // listOfCarriers length 1, subscriptionIds length 1, anySims false |
| 116 | CarrierTextController.CarrierTextCallbackInfo |
| 117 | c1 = new CarrierTextController.CarrierTextCallbackInfo( |
| 118 | "", |
| 119 | new CharSequence[]{""}, |
| 120 | false, |
| 121 | new int[]{0}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 122 | mCallback.updateCarrierInfo(c1); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 123 | |
| 124 | // listOfCarriers length 1, subscriptionIds length 1, anySims true |
| 125 | CarrierTextController.CarrierTextCallbackInfo |
| 126 | c2 = new CarrierTextController.CarrierTextCallbackInfo( |
| 127 | "", |
| 128 | new CharSequence[]{""}, |
| 129 | true, |
| 130 | new int[]{0}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 131 | mCallback.updateCarrierInfo(c2); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 132 | |
| 133 | // listOfCarriers length 2, subscriptionIds length 2, anySims false |
| 134 | CarrierTextController.CarrierTextCallbackInfo |
| 135 | c3 = new CarrierTextController.CarrierTextCallbackInfo( |
| 136 | "", |
| 137 | new CharSequence[]{"", ""}, |
| 138 | false, |
| 139 | new int[]{0, 1}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 140 | mCallback.updateCarrierInfo(c3); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 141 | |
| 142 | // listOfCarriers length 2, subscriptionIds length 2, anySims true |
| 143 | CarrierTextController.CarrierTextCallbackInfo |
| 144 | c4 = new CarrierTextController.CarrierTextCallbackInfo( |
| 145 | "", |
| 146 | new CharSequence[]{"", ""}, |
| 147 | true, |
| 148 | new int[]{0, 1}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 149 | mCallback.updateCarrierInfo(c4); |
| 150 | |
| 151 | mTestableLooper.processAllMessages(); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Test // throws no Exception |
| 155 | public void testUpdateCarrierText_differentLength() { |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 156 | QSCarrierGroupController spiedCarrierGroupController = |
| 157 | Mockito.spy(mQSCarrierGroupController); |
| 158 | when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenAnswer( |
| 159 | (Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0)); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 160 | |
| 161 | // listOfCarriers length 2, subscriptionIds length 1, anySims false |
| 162 | CarrierTextController.CarrierTextCallbackInfo |
| 163 | c1 = new CarrierTextController.CarrierTextCallbackInfo( |
| 164 | "", |
| 165 | new CharSequence[]{"", ""}, |
| 166 | false, |
| 167 | new int[]{0}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 168 | mCallback.updateCarrierInfo(c1); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 169 | |
| 170 | // listOfCarriers length 2, subscriptionIds length 1, anySims true |
| 171 | CarrierTextController.CarrierTextCallbackInfo |
| 172 | c2 = new CarrierTextController.CarrierTextCallbackInfo( |
| 173 | "", |
| 174 | new CharSequence[]{"", ""}, |
| 175 | true, |
| 176 | new int[]{0}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 177 | mCallback.updateCarrierInfo(c2); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 178 | |
| 179 | // listOfCarriers length 1, subscriptionIds length 2, anySims false |
| 180 | CarrierTextController.CarrierTextCallbackInfo |
| 181 | c3 = new CarrierTextController.CarrierTextCallbackInfo( |
| 182 | "", |
| 183 | new CharSequence[]{""}, |
| 184 | false, |
| 185 | new int[]{0, 1}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 186 | mCallback.updateCarrierInfo(c3); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 187 | |
| 188 | // listOfCarriers length 1, subscriptionIds length 2, anySims true |
| 189 | CarrierTextController.CarrierTextCallbackInfo |
| 190 | c4 = new CarrierTextController.CarrierTextCallbackInfo( |
| 191 | "", |
| 192 | new CharSequence[]{""}, |
| 193 | true, |
| 194 | new int[]{0, 1}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 195 | mCallback.updateCarrierInfo(c4); |
| 196 | mTestableLooper.processAllMessages(); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Test // throws no Exception |
| 200 | public void testUpdateCarrierText_invalidSim() { |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 201 | QSCarrierGroupController spiedCarrierGroupController = |
| 202 | Mockito.spy(mQSCarrierGroupController); |
| 203 | when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenReturn( |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 204 | SubscriptionManager.INVALID_SIM_SLOT_INDEX); |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 205 | |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 206 | CarrierTextController.CarrierTextCallbackInfo |
| 207 | c4 = new CarrierTextController.CarrierTextCallbackInfo( |
| 208 | "", |
| 209 | new CharSequence[]{"", ""}, |
| 210 | true, |
| 211 | new int[]{0, 1}); |
Fabian Kozynski | beeec06 | 2019-09-24 10:34:00 -0400 | [diff] [blame] | 212 | mCallback.updateCarrierInfo(c4); |
| 213 | mTestableLooper.processAllMessages(); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Test // throws no Exception |
| 217 | public void testSetMobileDataIndicators_invalidSim() { |
Dave Mankoff | c4fe6c4 | 2019-11-18 17:03:29 -0500 | [diff] [blame] | 218 | mSignalCallback.setMobileDataIndicators( |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 219 | mock(NetworkController.IconState.class), |
| 220 | mock(NetworkController.IconState.class), |
Evan Laird | 5784a6b | 2019-09-24 19:14:05 -0400 | [diff] [blame] | 221 | 0, 0, true, true, "", "", "", true, 0, true); |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 222 | } |
Fabian Kozynski | bc9d52d | 2020-03-27 12:58:44 -0400 | [diff] [blame] | 223 | |
| 224 | @Test |
| 225 | public void testNoEmptyVisibleView_airplaneMode() { |
| 226 | CarrierTextController.CarrierTextCallbackInfo |
| 227 | info = new CarrierTextController.CarrierTextCallbackInfo( |
| 228 | "", |
| 229 | new CharSequence[]{""}, |
| 230 | true, |
| 231 | new int[]{0}, |
| 232 | true /* airplaneMode */); |
| 233 | mCallback.updateCarrierInfo(info); |
| 234 | mTestableLooper.processAllMessages(); |
| 235 | assertEquals(View.GONE, mQSCarrierGroup.getNoSimTextView().getVisibility()); |
| 236 | } |
Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame] | 237 | } |