Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 android.content.pm; |
| 18 | |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 21 | import android.annotation.UserIdInt; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 24 | import android.os.UserHandle; |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 25 | import android.os.UserManager; |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 26 | import android.util.DebugUtils; |
| 27 | |
| 28 | import java.lang.annotation.Retention; |
| 29 | import java.lang.annotation.RetentionPolicy; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Per-user information. |
Bookatz | 75f0a07 | 2019-08-05 14:12:16 -0700 | [diff] [blame] | 33 | * |
| 34 | * <p>There are 3 base properties of users: {@link #FLAG_SYSTEM}, {@link #FLAG_FULL}, and |
| 35 | * {@link #FLAG_MANAGED_PROFILE}. Every user must have one of the following combination of these |
| 36 | * flags: |
| 37 | * <ul> |
| 38 | * <li>FLAG_SYSTEM (user {@link UserHandle#USER_SYSTEM} on a headless-user-0 device)</li> |
| 39 | * <li>FLAG_SYSTEM and FLAG_FULL (user {@link UserHandle#USER_SYSTEM} on a regular device)</li> |
| 40 | * <li>FLAG_FULL (non-profile secondary user)</li> |
| 41 | * <li>FLAG_MANAGED_PROFILE (profile users)</li> |
| 42 | * </ul> |
| 43 | * Users can have also have additional flags (such as FLAG_GUEST) as appropriate. |
| 44 | * |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 45 | * @hide |
| 46 | */ |
| 47 | public class UserInfo implements Parcelable { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 48 | |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 49 | /** 16 bits for user type */ |
| 50 | public static final int FLAG_MASK_USER_TYPE = 0x0000FFFF; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 51 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 52 | /** |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 53 | * *************************** NOTE *************************** |
| 54 | * These flag values CAN NOT CHANGE because they are written |
| 55 | * directly to storage. |
| 56 | */ |
| 57 | |
| 58 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 59 | * Primary user. Only one user can have this flag set. It identifies the first human user |
Ying Zheng | 215116f | 2019-09-11 12:50:09 -0700 | [diff] [blame] | 60 | * on a device. This flag is not supported in headless system user mode. |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 61 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 62 | @UnsupportedAppUsage |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 63 | public static final int FLAG_PRIMARY = 0x00000001; |
| 64 | |
| 65 | /** |
| 66 | * User with administrative privileges. Such a user can create and |
| 67 | * delete users. |
| 68 | */ |
| 69 | public static final int FLAG_ADMIN = 0x00000002; |
| 70 | |
| 71 | /** |
| 72 | * Indicates a guest user that may be transient. |
| 73 | */ |
| 74 | public static final int FLAG_GUEST = 0x00000004; |
| 75 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 76 | /** |
| 77 | * Indicates the user has restrictions in privileges, in addition to those for normal users. |
| 78 | * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts. |
| 79 | */ |
| 80 | public static final int FLAG_RESTRICTED = 0x00000008; |
| 81 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 82 | /** |
| 83 | * Indicates that this user has gone through its first-time initialization. |
| 84 | */ |
| 85 | public static final int FLAG_INITIALIZED = 0x00000010; |
| 86 | |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 87 | /** |
| 88 | * Indicates that this user is a profile of another user, for example holding a users |
| 89 | * corporate data. |
| 90 | */ |
| 91 | public static final int FLAG_MANAGED_PROFILE = 0x00000020; |
| 92 | |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 93 | /** |
| 94 | * Indicates that this user is disabled. |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 95 | * |
| 96 | * <p>Note: If an ephemeral user is disabled, it shouldn't be later re-enabled. Ephemeral users |
| 97 | * are disabled as their removal is in progress to indicate that they shouldn't be re-entered. |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 98 | */ |
| 99 | public static final int FLAG_DISABLED = 0x00000040; |
| 100 | |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 101 | public static final int FLAG_QUIET_MODE = 0x00000080; |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 102 | |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 103 | /** |
| 104 | * Indicates that this user is ephemeral. I.e. the user will be removed after leaving |
| 105 | * the foreground. |
| 106 | */ |
| 107 | public static final int FLAG_EPHEMERAL = 0x00000100; |
| 108 | |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 109 | /** |
| 110 | * User is for demo purposes only and can be removed at any time. |
| 111 | */ |
| 112 | public static final int FLAG_DEMO = 0x00000200; |
| 113 | |
Bookatz | 75f0a07 | 2019-08-05 14:12:16 -0700 | [diff] [blame] | 114 | /** |
| 115 | * Indicates that this user is a non-profile human user. |
| 116 | * |
| 117 | * <p>When creating a new (non-system) user, this flag will always be forced true unless the |
| 118 | * user is a {@link #FLAG_MANAGED_PROFILE}. If user {@link UserHandle#USER_SYSTEM} is also a |
| 119 | * human user, it must also be flagged as FULL. |
| 120 | */ |
| 121 | public static final int FLAG_FULL = 0x00000400; |
| 122 | |
| 123 | /** |
| 124 | * Indicates that this user is {@link UserHandle#USER_SYSTEM}. Not applicable to created users. |
| 125 | */ |
| 126 | public static final int FLAG_SYSTEM = 0x00000800; |
| 127 | |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 128 | /** |
Bookatz | 04d7ae5 | 2019-08-05 14:07:12 -0700 | [diff] [blame^] | 129 | * Indicates that this user is some sort of profile. Right now, the only profile type is |
| 130 | * {@link #FLAG_MANAGED_PROFILE}, but this can include other types of profiles too if any |
| 131 | * are created in the future. This is therefore not a flag, but an OR of several flags. |
| 132 | */ |
| 133 | public static final int PROFILE_FLAGS_MASK = FLAG_MANAGED_PROFILE; |
| 134 | |
| 135 | /** |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 136 | * @hide |
| 137 | */ |
| 138 | @IntDef(flag = true, prefix = "FLAG_", value = { |
| 139 | FLAG_PRIMARY, |
| 140 | FLAG_ADMIN, |
| 141 | FLAG_GUEST, |
| 142 | FLAG_RESTRICTED, |
| 143 | FLAG_INITIALIZED, |
| 144 | FLAG_MANAGED_PROFILE, |
| 145 | FLAG_DISABLED, |
| 146 | FLAG_QUIET_MODE, |
| 147 | FLAG_EPHEMERAL, |
| 148 | FLAG_DEMO, |
| 149 | FLAG_FULL, |
| 150 | FLAG_SYSTEM |
| 151 | }) |
| 152 | @Retention(RetentionPolicy.SOURCE) |
| 153 | public @interface UserInfoFlag { |
| 154 | } |
| 155 | |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 156 | public static final int NO_PROFILE_GROUP_ID = UserHandle.USER_NULL; |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 157 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 158 | @UnsupportedAppUsage |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 159 | public @UserIdInt int id; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 160 | @UnsupportedAppUsage |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 161 | public int serialNumber; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 162 | @UnsupportedAppUsage |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 163 | public String name; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 164 | @UnsupportedAppUsage |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 165 | public String iconPath; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 166 | @UnsupportedAppUsage |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 167 | public @UserInfoFlag int flags; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 168 | @UnsupportedAppUsage |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 169 | public long creationTime; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 170 | @UnsupportedAppUsage |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 171 | public long lastLoggedInTime; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 172 | public String lastLoggedInFingerprint; |
Tony Mak | d3986be | 2016-11-01 18:12:10 +0000 | [diff] [blame] | 173 | /** |
| 174 | * If this user is a parent user, it would be its own user id. |
| 175 | * If this user is a child user, it would be its parent user id. |
| 176 | * Otherwise, it would be {@link #NO_PROFILE_GROUP_ID}. |
| 177 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 178 | @UnsupportedAppUsage |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 179 | public int profileGroupId; |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 180 | public int restrictedProfileParentId; |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 181 | /** Which profile badge color/label to use. */ |
| 182 | public int profileBadge; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 183 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 184 | /** User is only partially created. */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 185 | @UnsupportedAppUsage |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 186 | public boolean partial; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 187 | @UnsupportedAppUsage |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 188 | public boolean guestToRemove; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 189 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 190 | @UnsupportedAppUsage |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 191 | public UserInfo(int id, String name, int flags) { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 192 | this(id, name, null, flags); |
| 193 | } |
| 194 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 195 | @UnsupportedAppUsage |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 196 | public UserInfo(int id, String name, String iconPath, int flags) { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 197 | this.id = id; |
| 198 | this.name = name; |
| 199 | this.flags = flags; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 200 | this.iconPath = iconPath; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 201 | this.profileGroupId = NO_PROFILE_GROUP_ID; |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 202 | this.restrictedProfileParentId = NO_PROFILE_GROUP_ID; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 205 | @UnsupportedAppUsage |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 206 | public boolean isPrimary() { |
| 207 | return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; |
| 208 | } |
| 209 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 210 | @UnsupportedAppUsage |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 211 | public boolean isAdmin() { |
| 212 | return (flags & FLAG_ADMIN) == FLAG_ADMIN; |
| 213 | } |
| 214 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 215 | @UnsupportedAppUsage |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 216 | public boolean isGuest() { |
| 217 | return (flags & FLAG_GUEST) == FLAG_GUEST; |
| 218 | } |
| 219 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 220 | @UnsupportedAppUsage |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 221 | public boolean isRestricted() { |
| 222 | return (flags & FLAG_RESTRICTED) == FLAG_RESTRICTED; |
| 223 | } |
| 224 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 225 | @UnsupportedAppUsage |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 226 | public boolean isManagedProfile() { |
| 227 | return (flags & FLAG_MANAGED_PROFILE) == FLAG_MANAGED_PROFILE; |
| 228 | } |
| 229 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 230 | @UnsupportedAppUsage |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 231 | public boolean isEnabled() { |
| 232 | return (flags & FLAG_DISABLED) != FLAG_DISABLED; |
| 233 | } |
| 234 | |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 235 | public boolean isQuietModeEnabled() { |
| 236 | return (flags & FLAG_QUIET_MODE) == FLAG_QUIET_MODE; |
| 237 | } |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 238 | |
| 239 | public boolean isEphemeral() { |
| 240 | return (flags & FLAG_EPHEMERAL) == FLAG_EPHEMERAL; |
| 241 | } |
| 242 | |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 243 | public boolean isInitialized() { |
| 244 | return (flags & FLAG_INITIALIZED) == FLAG_INITIALIZED; |
| 245 | } |
| 246 | |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 247 | public boolean isDemo() { |
| 248 | return (flags & FLAG_DEMO) == FLAG_DEMO; |
| 249 | } |
| 250 | |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 251 | public boolean isFull() { |
| 252 | return (flags & FLAG_FULL) == FLAG_FULL; |
| 253 | } |
| 254 | |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 255 | /** |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 256 | * Returns true if the user is a split system user. |
| 257 | * <p>If {@link UserManager#isSplitSystemUser split system user mode} is not enabled, |
| 258 | * the method always returns false. |
| 259 | */ |
| 260 | public boolean isSystemOnly() { |
Xiaohui Chen | a449062 | 2015-09-22 15:29:31 -0700 | [diff] [blame] | 261 | return isSystemOnly(id); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Returns true if the given user is a split system user. |
| 266 | * <p>If {@link UserManager#isSplitSystemUser split system user mode} is not enabled, |
| 267 | * the method always returns false. |
| 268 | */ |
| 269 | public static boolean isSystemOnly(int userId) { |
| 270 | return userId == UserHandle.USER_SYSTEM && UserManager.isSplitSystemUser(); |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 274 | * @return true if this user can be switched to. |
| 275 | **/ |
| 276 | public boolean supportsSwitchTo() { |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 277 | if (isEphemeral() && !isEnabled()) { |
| 278 | // Don't support switching to an ephemeral user with removal in progress. |
| 279 | return false; |
| 280 | } |
Robin Lee | 434a74f | 2016-08-04 15:58:08 +0100 | [diff] [blame] | 281 | return !isManagedProfile(); |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 284 | /** |
| 285 | * @return true if this user can be switched to by end user through UI. |
| 286 | */ |
| 287 | public boolean supportsSwitchToByUser() { |
| 288 | // Hide the system user when it does not represent a human user. |
| 289 | boolean hideSystemUser = UserManager.isSplitSystemUser(); |
| 290 | return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); |
| 291 | } |
| 292 | |
Nicolas Prevot | b818681 | 2015-08-06 15:00:03 +0100 | [diff] [blame] | 293 | /* @hide */ |
| 294 | public boolean canHaveProfile() { |
| 295 | if (isManagedProfile() || isGuest() || isRestricted()) { |
| 296 | return false; |
| 297 | } |
Eric Jeong | e7ead1b | 2019-07-18 09:37:08 -0700 | [diff] [blame] | 298 | if (UserManager.isSplitSystemUser() || UserManager.isHeadlessSystemUserMode()) { |
Nicolas Prevot | b818681 | 2015-08-06 15:00:03 +0100 | [diff] [blame] | 299 | return id != UserHandle.USER_SYSTEM; |
Xiaohui Chen | bd0e03b | 2015-08-21 09:19:49 -0700 | [diff] [blame] | 300 | } else { |
| 301 | return id == UserHandle.USER_SYSTEM; |
Nicolas Prevot | b818681 | 2015-08-06 15:00:03 +0100 | [diff] [blame] | 302 | } |
Nicolas Prevot | b818681 | 2015-08-06 15:00:03 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 305 | public UserInfo() { |
| 306 | } |
| 307 | |
| 308 | public UserInfo(UserInfo orig) { |
| 309 | name = orig.name; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 310 | iconPath = orig.iconPath; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 311 | id = orig.id; |
| 312 | flags = orig.flags; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 313 | serialNumber = orig.serialNumber; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 314 | creationTime = orig.creationTime; |
| 315 | lastLoggedInTime = orig.lastLoggedInTime; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 316 | lastLoggedInFingerprint = orig.lastLoggedInFingerprint; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 317 | partial = orig.partial; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 318 | profileGroupId = orig.profileGroupId; |
Amith Yamasani | 6f48d6e | 2016-03-23 14:28:25 -0700 | [diff] [blame] | 319 | restrictedProfileParentId = orig.restrictedProfileParentId; |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 320 | guestToRemove = orig.guestToRemove; |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 321 | profileBadge = orig.profileBadge; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 324 | @UnsupportedAppUsage |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 325 | public UserHandle getUserHandle() { |
| 326 | return new UserHandle(id); |
| 327 | } |
| 328 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 329 | @Override |
| 330 | public String toString() { |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 331 | // NOTE: do not change this string, it's used by 'pm list users', which in turn is |
| 332 | // used and parsed by TestDevice. In other words, if you change it, you'd have to change |
| 333 | // TestDevice, TestDeviceTest, and possibly others.... |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 334 | return "UserInfo{" + id + ":" + name + ":" + Integer.toHexString(flags) + "}"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 337 | /** @hide */ |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 338 | public String toFullString() { |
| 339 | return "UserInfo[id=" + id |
| 340 | + ", name=" + name |
| 341 | + ", flags=" + flagsToString(flags) |
| 342 | + "]"; |
| 343 | } |
| 344 | |
| 345 | /** @hide */ |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 346 | public static String flagsToString(int flags) { |
| 347 | return DebugUtils.flagsToString(UserInfo.class, "FLAG_", flags); |
| 348 | } |
| 349 | |
| 350 | @Override |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 351 | public int describeContents() { |
| 352 | return 0; |
| 353 | } |
| 354 | |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 355 | @Override |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 356 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 357 | dest.writeInt(id); |
| 358 | dest.writeString(name); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 359 | dest.writeString(iconPath); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 360 | dest.writeInt(flags); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 361 | dest.writeInt(serialNumber); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 362 | dest.writeLong(creationTime); |
| 363 | dest.writeLong(lastLoggedInTime); |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 364 | dest.writeString(lastLoggedInFingerprint); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 365 | dest.writeInt(partial ? 1 : 0); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 366 | dest.writeInt(profileGroupId); |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 367 | dest.writeInt(guestToRemove ? 1 : 0); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 368 | dest.writeInt(restrictedProfileParentId); |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 369 | dest.writeInt(profileBadge); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 372 | @UnsupportedAppUsage |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 373 | public static final @android.annotation.NonNull Parcelable.Creator<UserInfo> CREATOR |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 374 | = new Parcelable.Creator<UserInfo>() { |
| 375 | public UserInfo createFromParcel(Parcel source) { |
| 376 | return new UserInfo(source); |
| 377 | } |
| 378 | public UserInfo[] newArray(int size) { |
| 379 | return new UserInfo[size]; |
| 380 | } |
| 381 | }; |
| 382 | |
| 383 | private UserInfo(Parcel source) { |
| 384 | id = source.readInt(); |
| 385 | name = source.readString(); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 386 | iconPath = source.readString(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 387 | flags = source.readInt(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 388 | serialNumber = source.readInt(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 389 | creationTime = source.readLong(); |
| 390 | lastLoggedInTime = source.readLong(); |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 391 | lastLoggedInFingerprint = source.readString(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 392 | partial = source.readInt() != 0; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 393 | profileGroupId = source.readInt(); |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 394 | guestToRemove = source.readInt() != 0; |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 395 | restrictedProfileParentId = source.readInt(); |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 396 | profileBadge = source.readInt(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 397 | } |
| 398 | } |