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.dump.DumpManager; 27 import com.android.systemui.settings.DisplayTracker; 28 29 public class UserPickerBaseTestActivity extends UserPickerActivity { 30 private final boolean mTestIsDriver; 31 private final boolean mMockUserPickerAdapter; 32 boolean mCalledFinished; 33 UserPickerBaseTestActivity(boolean isDriver)34 public UserPickerBaseTestActivity(boolean isDriver) { 35 this(isDriver, true); 36 } 37 UserPickerBaseTestActivity(boolean isDriver, boolean mockUserPickerAdapter)38 public UserPickerBaseTestActivity(boolean isDriver, boolean mockUserPickerAdapter) { 39 super(); 40 mController = mock(UserPickerController.class); 41 mDialogManager = mock(DialogManager.class); 42 mSnackbarManager = mock(SnackbarManager.class); 43 mDisplayTracker = mock(DisplayTracker.class); 44 mDumpManager = mock(DumpManager.class); 45 mTestIsDriver = isDriver; 46 mMockUserPickerAdapter = mockUserPickerAdapter; 47 if (mMockUserPickerAdapter) { 48 mAdapter = mock(UserPickerAdapter.class); 49 when(mAdapter.getStateRestorationPolicy()).thenReturn( 50 RecyclerView.Adapter.StateRestorationPolicy.ALLOW); 51 } 52 when(mDisplayTracker.getDefaultDisplayId()).thenReturn(Display.DEFAULT_DISPLAY); 53 } 54 55 @Override shouldStartAsSystemUser()56 boolean shouldStartAsSystemUser() { 57 // return false to allow starting the activity as the current test user 58 return false; 59 } 60 61 @Override getIsDriver()62 boolean getIsDriver() { 63 return mTestIsDriver; 64 } 65 66 @Override createUserPickerAdapter()67 UserPickerAdapter createUserPickerAdapter() { 68 if (mMockUserPickerAdapter) { 69 return mAdapter; 70 } 71 return super.createUserPickerAdapter(); 72 } 73 74 @Override finishAndRemoveTask()75 public void finishAndRemoveTask() { 76 mCalledFinished = true; 77 } 78 } 79