blob: 8a412bff03ac6af581d47655a60219ec25d62701 [file] [log] [blame]
Fabian Kozynskia48d2d02019-02-27 11:36:02 -05001/*
Fabian Kozynski00afd492020-02-15 19:58:10 -05002 * Copyright (C) 2020 The Android Open Source Project
Fabian Kozynskia48d2d02019-02-27 11:36:02 -05003 *
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 Kozynski00afd492020-02-15 19:58:10 -050017package com.android.systemui.qs.carrier;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050018
Fabian Kozynskibc9d52d2020-03-27 12:58:44 -040019import static org.junit.Assert.assertEquals;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050020import static org.mockito.ArgumentMatchers.any;
21import static org.mockito.ArgumentMatchers.anyBoolean;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050022import static org.mockito.ArgumentMatchers.anyInt;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050023import static org.mockito.Mockito.doAnswer;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050024import static org.mockito.Mockito.mock;
25import static org.mockito.Mockito.when;
26
Fabian Kozynskibeeec062019-09-24 10:34:00 -040027import android.os.Handler;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050028import android.telephony.SubscriptionManager;
29import android.testing.AndroidTestingRunner;
30import android.testing.TestableLooper;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050031import android.view.View;
32import android.widget.TextView;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050033
34import androidx.test.filters.SmallTest;
35
36import com.android.keyguard.CarrierTextController;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050037import com.android.systemui.plugins.ActivityStarter;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050038import com.android.systemui.statusbar.policy.NetworkController;
39import com.android.systemui.utils.leaks.LeakCheckedTest;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050040import com.android.systemui.utils.os.FakeHandler;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050041
42import org.junit.Before;
43import org.junit.Test;
44import org.junit.runner.RunWith;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050045import org.mockito.Mock;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050046import org.mockito.Mockito;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050047import org.mockito.MockitoAnnotations;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050048import org.mockito.stubbing.Answer;
49
50@RunWith(AndroidTestingRunner.class)
51@TestableLooper.RunWithLooper
52@SmallTest
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050053public class QSCarrierGroupControllerTest extends LeakCheckedTest {
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050054
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050055 private QSCarrierGroupController mQSCarrierGroupController;
56 private NetworkController.SignalCallback mSignalCallback;
Fabian Kozynskibeeec062019-09-24 10:34:00 -040057 private CarrierTextController.CarrierTextCallback mCallback;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050058 @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 Kozynskibeeec062019-09-24 10:34:00 -040068 private TestableLooper mTestableLooper;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050069
70 @Before
71 public void setup() throws Exception {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050072 MockitoAnnotations.initMocks(this);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050073 injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
Fabian Kozynskibeeec062019-09-24 10:34:00 -040074 mTestableLooper = TestableLooper.get(this);
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050075 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 Kozynskia48d2d02019-02-27 11:36:02 -0500106 }
107
108 @Test // throws no Exception
109 public void testUpdateCarrierText_sameLengths() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500110 QSCarrierGroupController spiedCarrierGroupController =
111 Mockito.spy(mQSCarrierGroupController);
112 when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenAnswer(
113 (Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0));
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500114
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 Kozynskibeeec062019-09-24 10:34:00 -0400122 mCallback.updateCarrierInfo(c1);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500123
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 Kozynskibeeec062019-09-24 10:34:00 -0400131 mCallback.updateCarrierInfo(c2);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500132
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 Kozynskibeeec062019-09-24 10:34:00 -0400140 mCallback.updateCarrierInfo(c3);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500141
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 Kozynskibeeec062019-09-24 10:34:00 -0400149 mCallback.updateCarrierInfo(c4);
150
151 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500152 }
153
154 @Test // throws no Exception
155 public void testUpdateCarrierText_differentLength() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500156 QSCarrierGroupController spiedCarrierGroupController =
157 Mockito.spy(mQSCarrierGroupController);
158 when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenAnswer(
159 (Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0));
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500160
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 Kozynskibeeec062019-09-24 10:34:00 -0400168 mCallback.updateCarrierInfo(c1);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500169
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 Kozynskibeeec062019-09-24 10:34:00 -0400177 mCallback.updateCarrierInfo(c2);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500178
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 Kozynskibeeec062019-09-24 10:34:00 -0400186 mCallback.updateCarrierInfo(c3);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500187
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 Kozynskibeeec062019-09-24 10:34:00 -0400195 mCallback.updateCarrierInfo(c4);
196 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500197 }
198
199 @Test // throws no Exception
200 public void testUpdateCarrierText_invalidSim() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500201 QSCarrierGroupController spiedCarrierGroupController =
202 Mockito.spy(mQSCarrierGroupController);
203 when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenReturn(
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500204 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500205
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500206 CarrierTextController.CarrierTextCallbackInfo
207 c4 = new CarrierTextController.CarrierTextCallbackInfo(
208 "",
209 new CharSequence[]{"", ""},
210 true,
211 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400212 mCallback.updateCarrierInfo(c4);
213 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500214 }
215
216 @Test // throws no Exception
217 public void testSetMobileDataIndicators_invalidSim() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500218 mSignalCallback.setMobileDataIndicators(
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500219 mock(NetworkController.IconState.class),
220 mock(NetworkController.IconState.class),
Evan Laird5784a6b2019-09-24 19:14:05 -0400221 0, 0, true, true, "", "", "", true, 0, true);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500222 }
Fabian Kozynskibc9d52d2020-03-27 12:58:44 -0400223
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 Kozynskia48d2d02019-02-27 11:36:02 -0500237}