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 package com.android.systemui.car.userpicker; 17 18 import static android.car.CarOccupantZoneManager.OCCUPANT_TYPE_DRIVER; 19 import static android.car.CarOccupantZoneManager.OCCUPANT_TYPE_FRONT_PASSENGER; 20 import static android.car.CarOccupantZoneManager.OCCUPANT_TYPE_REAR_PASSENGER; 21 import static android.car.VehicleAreaSeat.SEAT_ROW_1_CENTER; 22 import static android.car.VehicleAreaSeat.SEAT_ROW_1_LEFT; 23 import static android.car.VehicleAreaSeat.SEAT_ROW_1_RIGHT; 24 import static android.car.VehicleAreaSeat.SEAT_ROW_2_CENTER; 25 import static android.car.VehicleAreaSeat.SEAT_ROW_2_LEFT; 26 import static android.car.VehicleAreaSeat.SEAT_ROW_2_RIGHT; 27 import static android.car.VehicleAreaSeat.SEAT_ROW_3_CENTER; 28 import static android.car.VehicleAreaSeat.SEAT_ROW_3_LEFT; 29 import static android.car.VehicleAreaSeat.SEAT_ROW_3_RIGHT; 30 31 import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; 32 33 import android.car.CarOccupantZoneManager.OccupantZoneInfo; 34 import android.content.pm.UserInfo; 35 import android.view.Display; 36 import android.view.DisplayAdjustments; 37 import android.view.DisplayInfo; 38 import android.view.LayoutInflater; 39 40 import com.android.systemui.R; 41 import com.android.systemui.SysuiTestCase; 42 43 import org.junit.Before; 44 45 public abstract class UserPickerTestCase extends SysuiTestCase { 46 static final int IDLE_TIMEOUT = 1_500; 47 48 static final int USER_ID_DRIVER = 999; 49 static final int USER_ID_FRONT = 1000; 50 static final int USER_ID_REAR = 1001; 51 static final int USER_ID_GUEST = 1010; 52 53 static final String USER_NAME_DRIVER = "Driver"; 54 static final String USER_NAME_FRONT = "Front"; 55 static final String USER_NAME_REAR = "Rear"; 56 57 static final int MAIN_DISPLAY_ID = 0; 58 static final int FRONT_PASSENGER_DISPLAY_ID = 2; 59 static final int REAR_PASSENGER_DISPLAY_ID = 3; 60 61 static final Display MAIN_DISPLAY = new Display(null, 62 MAIN_DISPLAY_ID, new DisplayInfo(), new DisplayAdjustments()); 63 static final Display FRONT_PASSENGER_DISPLAY = new Display(null, 64 FRONT_PASSENGER_DISPLAY_ID, new DisplayInfo(), new DisplayAdjustments()); 65 static final Display REAR_PASSENGER_DISPLAY = new Display(null, 66 REAR_PASSENGER_DISPLAY_ID, new DisplayInfo(), new DisplayAdjustments()); 67 68 static final int ZONE_ID_DRIVER = 0; 69 static final int ZONE_ID_FRONT = 1; 70 static final int ZONE_ID_REAR = 2; 71 72 final int mRefreshLayoutSize = 1200; 73 74 final LayoutInflater mInflater = LayoutInflater.from(mContext); 75 final String mGuestLabel = mContext.getString(R.string.car_guest); 76 final String mAddLabel = mContext.getString(R.string.car_add_user); 77 final String mLoggedinLabel = mContext.getString(R.string.logged_in_text); 78 79 UserInfo mDriverUserInfo = new UserInfo(USER_ID_DRIVER, USER_NAME_DRIVER, 80 UserInfo.FLAG_ADMIN | UserInfo.FLAG_FULL); 81 UserInfo mFrontUserInfo = new UserInfo(USER_ID_FRONT, USER_NAME_FRONT, UserInfo.FLAG_FULL); 82 UserInfo mRearUserInfo = new UserInfo(USER_ID_REAR, USER_NAME_REAR, UserInfo.FLAG_FULL); 83 84 @Before setUpUserPickerTest()85 public void setUpUserPickerTest() { 86 spyOn(mContext); 87 mContext.setTheme(R.style.Theme_UserPicker); 88 } 89 getZoneDesc(OccupantZoneInfo zoneInfo)90 String getZoneDesc(OccupantZoneInfo zoneInfo) { 91 StringBuilder seat = new StringBuilder(15); 92 if (zoneInfo.occupantType == OCCUPANT_TYPE_DRIVER) { 93 seat.append(mContext.getString(R.string.seat_driver)); 94 } else { 95 if (zoneInfo.occupantType == OCCUPANT_TYPE_FRONT_PASSENGER) { 96 seat.append(mContext.getString(R.string.seat_front)); 97 } else if (zoneInfo.occupantType == OCCUPANT_TYPE_REAR_PASSENGER) { 98 seat.append(mContext.getString(R.string.seat_rear)); 99 } 100 seat.append(" "); 101 switch (zoneInfo.seat) { 102 case SEAT_ROW_1_LEFT: 103 case SEAT_ROW_2_LEFT: 104 case SEAT_ROW_3_LEFT: 105 seat.append(mContext.getString(R.string.seat_left_side)); 106 break; 107 case SEAT_ROW_1_CENTER: 108 case SEAT_ROW_2_CENTER: 109 case SEAT_ROW_3_CENTER: 110 seat.append(mContext.getString(R.string.seat_center_side)); 111 break; 112 case SEAT_ROW_1_RIGHT: 113 case SEAT_ROW_2_RIGHT: 114 case SEAT_ROW_3_RIGHT: 115 seat.append(mContext.getString(R.string.seat_right_side)); 116 break; 117 default: 118 return null; 119 } 120 } 121 return seat.toString(); 122 } 123 } 124