• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
17 package com.android.systemui.car.userpicker;
18 
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.when;
21 
22 import android.view.Display;
23 
24 import androidx.recyclerview.widget.RecyclerView;
25 
26 import com.android.systemui.car.systembar.element.CarSystemBarElementInitializer;
27 import com.android.systemui.dump.DumpManager;
28 import com.android.systemui.settings.DisplayTracker;
29 
30 public class UserPickerBaseTestActivity extends UserPickerActivity {
31     private final boolean mTestIsDriver;
32     private final boolean mMockUserPickerAdapter;
33     boolean mCalledFinished;
34 
UserPickerBaseTestActivity(boolean isDriver)35     public UserPickerBaseTestActivity(boolean isDriver) {
36         this(isDriver, true);
37     }
38 
UserPickerBaseTestActivity(boolean isDriver, boolean mockUserPickerAdapter)39     public UserPickerBaseTestActivity(boolean isDriver, boolean mockUserPickerAdapter) {
40         super();
41         mController = mock(UserPickerController.class);
42         mDialogManager = mock(DialogManager.class);
43         mSnackbarManager = mock(SnackbarManager.class);
44         mCarSystemBarElementInitializer = mock(CarSystemBarElementInitializer.class);
45         mDisplayTracker = mock(DisplayTracker.class);
46         mDumpManager = mock(DumpManager.class);
47         mTestIsDriver = isDriver;
48         mMockUserPickerAdapter = mockUserPickerAdapter;
49         if (mMockUserPickerAdapter) {
50             mAdapter = mock(UserPickerAdapter.class);
51             when(mAdapter.getStateRestorationPolicy()).thenReturn(
52                     RecyclerView.Adapter.StateRestorationPolicy.ALLOW);
53         }
54         when(mDisplayTracker.getDefaultDisplayId()).thenReturn(Display.DEFAULT_DISPLAY);
55     }
56 
57     @Override
shouldStartAsSystemUser()58     boolean shouldStartAsSystemUser() {
59         // return false to allow starting the activity as the current test user
60         return false;
61     }
62 
63     @Override
getIsDriver()64     boolean getIsDriver() {
65         return mTestIsDriver;
66     }
67 
68     @Override
createUserPickerAdapter()69     UserPickerAdapter createUserPickerAdapter() {
70         if (mMockUserPickerAdapter) {
71             return mAdapter;
72         }
73         return super.createUserPickerAdapter();
74     }
75 
76     @Override
finishAndRemoveTask()77     public void finishAndRemoveTask() {
78         mCalledFinished = true;
79     }
80 }
81