1 /* 2 * Copyright (C) 2022 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.user.data.source 18 19 import android.content.pm.UserInfo 20 import android.graphics.Bitmap 21 import android.os.UserHandle 22 import com.android.settingslib.RestrictedLockUtils 23 24 /** Encapsulates raw data for a user or an option item related to managing users on the device. */ 25 data class UserRecord( 26 /** Relevant user information. If `null`, this record is not a user but an option item. */ 27 @JvmField val info: UserInfo? = null, 28 /** An image representing the user. */ 29 @JvmField val picture: Bitmap? = null, 30 /** Whether this record represents an option to switch to a guest user. */ 31 @JvmField val isGuest: Boolean = false, 32 /** Whether this record represents the currently-selected user. */ 33 @JvmField val isCurrent: Boolean = false, 34 /** Whether this record represents an option to add another user to the device. */ 35 @JvmField val isAddUser: Boolean = false, 36 /** 37 * If true, the record is only available if unlocked or if the user has granted permission to 38 * access this user action whilst on the device is locked. 39 */ 40 @JvmField val isRestricted: Boolean = false, 41 /** Whether it is possible to switch to this user. */ 42 @JvmField val isSwitchToEnabled: Boolean = false, 43 /** Whether this record represents an option to add another supervised user to the device. */ 44 @JvmField val isAddSupervisedUser: Boolean = false, 45 /** 46 * An enforcing admin, if the user action represented by this record is disabled by the admin. 47 * If not disabled, this is `null`. 48 */ 49 @JvmField val enforcedAdmin: RestrictedLockUtils.EnforcedAdmin? = null, 50 51 /** Whether this record is to go to the Settings page to manage users. */ 52 @JvmField val isManageUsers: Boolean = false 53 ) { 54 /** Returns a new instance of [UserRecord] with its [isCurrent] set to the given value. */ copyWithIsCurrentnull55 fun copyWithIsCurrent(isCurrent: Boolean): UserRecord { 56 return copy(isCurrent = isCurrent) 57 } 58 59 /** 60 * Returns the user ID for the user represented by this instance or [UserHandle.USER_NULL] if 61 * this instance if a guest or does not represent a user (represents an option item). 62 */ resolveIdnull63 fun resolveId(): Int { 64 return if (isGuest || info == null) { 65 UserHandle.USER_NULL 66 } else { 67 info.id 68 } 69 } 70 71 /** 72 * Returns `true` if the user action represented by this record has been disabled by an admin; 73 * `false` otherwise. 74 */ isDisabledByAdminnull75 fun isDisabledByAdmin(): Boolean { 76 return enforcedAdmin != null 77 } 78 79 companion object { 80 @JvmStatic createForGuestnull81 fun createForGuest(): UserRecord { 82 return UserRecord(isGuest = true) 83 } 84 } 85 } 86