blob: 1bfe1b10299b805061f2fec336654880fcb26409 [file] [log] [blame]
Fabian Kozynskia48d2d02019-02-27 11:36:02 -05001/*
2 * Copyright (C) 2019 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 */
16
17package com.android.systemui.qs;
18
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050019import static org.mockito.ArgumentMatchers.any;
20import static org.mockito.ArgumentMatchers.anyBoolean;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050021import static org.mockito.ArgumentMatchers.anyInt;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050022import static org.mockito.Mockito.doAnswer;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050023import static org.mockito.Mockito.mock;
24import static org.mockito.Mockito.when;
25
Fabian Kozynskibeeec062019-09-24 10:34:00 -040026import android.os.Handler;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050027import android.telephony.SubscriptionManager;
28import android.testing.AndroidTestingRunner;
29import android.testing.TestableLooper;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050030import android.view.View;
31import android.widget.TextView;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050032
33import androidx.test.filters.SmallTest;
34
35import com.android.keyguard.CarrierTextController;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050036import com.android.systemui.plugins.ActivityStarter;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050037import com.android.systemui.statusbar.policy.NetworkController;
38import com.android.systemui.utils.leaks.LeakCheckedTest;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050039import com.android.systemui.utils.os.FakeHandler;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050040
41import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050044import org.mockito.Mock;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050045import org.mockito.Mockito;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050046import org.mockito.MockitoAnnotations;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050047import org.mockito.stubbing.Answer;
48
49@RunWith(AndroidTestingRunner.class)
50@TestableLooper.RunWithLooper
51@SmallTest
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050052public class QSCarrierGroupControllerTest extends LeakCheckedTest {
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050053
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050054 private QSCarrierGroupController mQSCarrierGroupController;
55 private NetworkController.SignalCallback mSignalCallback;
Fabian Kozynskibeeec062019-09-24 10:34:00 -040056 private CarrierTextController.CarrierTextCallback mCallback;
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050057 @Mock
58 private QSCarrierGroup mQSCarrierGroup;
59 @Mock
60 private ActivityStarter mActivityStarter;
61 @Mock
62 private NetworkController mNetworkController;
63 @Mock
64 private CarrierTextController.Builder mCarrierTextControllerBuilder;
65 @Mock
66 private CarrierTextController mCarrierTextController;
Fabian Kozynskibeeec062019-09-24 10:34:00 -040067 private TestableLooper mTestableLooper;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050068
69 @Before
70 public void setup() throws Exception {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050071 MockitoAnnotations.initMocks(this);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050072 injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
Fabian Kozynskibeeec062019-09-24 10:34:00 -040073 mTestableLooper = TestableLooper.get(this);
Dave Mankoffc4fe6c42019-11-18 17:03:29 -050074 Handler handler = new FakeHandler(TestableLooper.get(this).getLooper());
75
76 when(mNetworkController.hasVoiceCallingFeature()).thenReturn(true);
77 doAnswer(invocation -> mSignalCallback = invocation.getArgument(0))
78 .when(mNetworkController)
79 .addCallback(any(NetworkController.SignalCallback.class));
80
81 when(mCarrierTextControllerBuilder.setShowAirplaneMode(anyBoolean()))
82 .thenReturn(mCarrierTextControllerBuilder);
83 when(mCarrierTextControllerBuilder.setShowMissingSim(anyBoolean()))
84 .thenReturn(mCarrierTextControllerBuilder);
85 when(mCarrierTextControllerBuilder.build()).thenReturn(mCarrierTextController);
86
87 doAnswer(invocation -> mCallback = invocation.getArgument(0))
88 .when(mCarrierTextController)
89 .setListening(any(CarrierTextController.CarrierTextCallback.class));
90
91 when(mQSCarrierGroup.getNoSimTextView()).thenReturn(new TextView(mContext));
92 when(mQSCarrierGroup.getCarrier1View()).thenReturn(mock(QSCarrier.class));
93 when(mQSCarrierGroup.getCarrier2View()).thenReturn(mock(QSCarrier.class));
94 when(mQSCarrierGroup.getCarrier3View()).thenReturn(mock(QSCarrier.class));
95 when(mQSCarrierGroup.getCarrierDivider1()).thenReturn(new View(mContext));
96 when(mQSCarrierGroup.getCarrierDivider2()).thenReturn(new View(mContext));
97
98 mQSCarrierGroupController = new QSCarrierGroupController.Builder(
99 mActivityStarter, handler, TestableLooper.get(this).getLooper(),
100 mNetworkController, mCarrierTextControllerBuilder)
101 .setQSCarrierGroup(mQSCarrierGroup)
102 .build();
103
104 mQSCarrierGroupController.setListening(true);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500105 }
106
107 @Test // throws no Exception
108 public void testUpdateCarrierText_sameLengths() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500109 QSCarrierGroupController spiedCarrierGroupController =
110 Mockito.spy(mQSCarrierGroupController);
111 when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenAnswer(
112 (Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0));
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500113
114 // listOfCarriers length 1, subscriptionIds length 1, anySims false
115 CarrierTextController.CarrierTextCallbackInfo
116 c1 = new CarrierTextController.CarrierTextCallbackInfo(
117 "",
118 new CharSequence[]{""},
119 false,
120 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400121 mCallback.updateCarrierInfo(c1);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500122
123 // listOfCarriers length 1, subscriptionIds length 1, anySims true
124 CarrierTextController.CarrierTextCallbackInfo
125 c2 = new CarrierTextController.CarrierTextCallbackInfo(
126 "",
127 new CharSequence[]{""},
128 true,
129 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400130 mCallback.updateCarrierInfo(c2);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500131
132 // listOfCarriers length 2, subscriptionIds length 2, anySims false
133 CarrierTextController.CarrierTextCallbackInfo
134 c3 = new CarrierTextController.CarrierTextCallbackInfo(
135 "",
136 new CharSequence[]{"", ""},
137 false,
138 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400139 mCallback.updateCarrierInfo(c3);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500140
141 // listOfCarriers length 2, subscriptionIds length 2, anySims true
142 CarrierTextController.CarrierTextCallbackInfo
143 c4 = new CarrierTextController.CarrierTextCallbackInfo(
144 "",
145 new CharSequence[]{"", ""},
146 true,
147 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400148 mCallback.updateCarrierInfo(c4);
149
150 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500151 }
152
153 @Test // throws no Exception
154 public void testUpdateCarrierText_differentLength() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500155 QSCarrierGroupController spiedCarrierGroupController =
156 Mockito.spy(mQSCarrierGroupController);
157 when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenAnswer(
158 (Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0));
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500159
160 // listOfCarriers length 2, subscriptionIds length 1, anySims false
161 CarrierTextController.CarrierTextCallbackInfo
162 c1 = new CarrierTextController.CarrierTextCallbackInfo(
163 "",
164 new CharSequence[]{"", ""},
165 false,
166 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400167 mCallback.updateCarrierInfo(c1);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500168
169 // listOfCarriers length 2, subscriptionIds length 1, anySims true
170 CarrierTextController.CarrierTextCallbackInfo
171 c2 = new CarrierTextController.CarrierTextCallbackInfo(
172 "",
173 new CharSequence[]{"", ""},
174 true,
175 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400176 mCallback.updateCarrierInfo(c2);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500177
178 // listOfCarriers length 1, subscriptionIds length 2, anySims false
179 CarrierTextController.CarrierTextCallbackInfo
180 c3 = new CarrierTextController.CarrierTextCallbackInfo(
181 "",
182 new CharSequence[]{""},
183 false,
184 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400185 mCallback.updateCarrierInfo(c3);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500186
187 // listOfCarriers length 1, subscriptionIds length 2, anySims true
188 CarrierTextController.CarrierTextCallbackInfo
189 c4 = new CarrierTextController.CarrierTextCallbackInfo(
190 "",
191 new CharSequence[]{""},
192 true,
193 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400194 mCallback.updateCarrierInfo(c4);
195 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500196 }
197
198 @Test // throws no Exception
199 public void testUpdateCarrierText_invalidSim() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500200 QSCarrierGroupController spiedCarrierGroupController =
201 Mockito.spy(mQSCarrierGroupController);
202 when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenReturn(
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500203 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500204
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500205 CarrierTextController.CarrierTextCallbackInfo
206 c4 = new CarrierTextController.CarrierTextCallbackInfo(
207 "",
208 new CharSequence[]{"", ""},
209 true,
210 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400211 mCallback.updateCarrierInfo(c4);
212 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500213 }
214
215 @Test // throws no Exception
216 public void testSetMobileDataIndicators_invalidSim() {
Dave Mankoffc4fe6c42019-11-18 17:03:29 -0500217 mSignalCallback.setMobileDataIndicators(
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500218 mock(NetworkController.IconState.class),
219 mock(NetworkController.IconState.class),
220 0, 0, true, true, "", "", true, 0, true);
221 }
222}