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 /** Whether this record represents an option to sign out of the current user. */ 46 @JvmField val isSignOut: Boolean = false, 47 /** 48 * An enforcing admin, if the user action represented by this record is disabled by the admin. 49 * If not disabled, this is `null`. 50 */ 51 @JvmField val enforcedAdmin: RestrictedLockUtils.EnforcedAdmin? = null, 52 53 /** Whether this record is to go to the Settings page to manage users. */ 54 @JvmField val isManageUsers: Boolean = false, 55 ) { 56 /** Returns a new instance of [UserRecord] with its [isCurrent] set to the given value. */ copyWithIsCurrentnull57 fun copyWithIsCurrent(isCurrent: Boolean): UserRecord { 58 return copy(isCurrent = isCurrent) 59 } 60 61 /** 62 * Returns the user ID for the user represented by this instance or [UserHandle.USER_NULL] if 63 * this instance if a guest or does not represent a user (represents an option item). 64 */ resolveIdnull65 fun resolveId(): Int { 66 return if (isGuest || info == null) { 67 UserHandle.USER_NULL 68 } else { 69 info.id 70 } 71 } 72 73 /** 74 * Returns `true` if the user action represented by this record has been disabled by an admin; 75 * `false` otherwise. 76 */ isDisabledByAdminnull77 fun isDisabledByAdmin(): Boolean { 78 return enforcedAdmin != null 79 } 80 81 companion object { 82 @JvmStatic createForGuestnull83 fun createForGuest(): UserRecord { 84 return UserRecord(isGuest = true) 85 } 86 } 87 } 88