2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.content.pm;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.os.SystemProperties;
22 import android.os.UserHandle;
23 import android.os.UserManager;
26 * Per-user information.
29 public class UserInfo implements Parcelable {
31 /** 16 bits for user type */
32 public static final int FLAG_MASK_USER_TYPE = 0x0000FFFF;
35 * *************************** NOTE ***************************
36 * These flag values CAN NOT CHANGE because they are written
37 * directly to storage.
41 * Primary user. Only one user can have this flag set. It identifies the first human user
44 public static final int FLAG_PRIMARY = 0x00000001;
47 * User with administrative privileges. Such a user can create and
50 public static final int FLAG_ADMIN = 0x00000002;
53 * Indicates a guest user that may be transient.
55 public static final int FLAG_GUEST = 0x00000004;
58 * Indicates the user has restrictions in privileges, in addition to those for normal users.
59 * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts.
61 public static final int FLAG_RESTRICTED = 0x00000008;
64 * Indicates that this user has gone through its first-time initialization.
66 public static final int FLAG_INITIALIZED = 0x00000010;
69 * Indicates that this user is a profile of another user, for example holding a users
72 public static final int FLAG_MANAGED_PROFILE = 0x00000020;
75 * Indicates that this user is disabled.
77 * <p>Note: If an ephemeral user is disabled, it shouldn't be later re-enabled. Ephemeral users
78 * are disabled as their removal is in progress to indicate that they shouldn't be re-entered.
80 public static final int FLAG_DISABLED = 0x00000040;
82 public static final int FLAG_QUIET_MODE = 0x00000080;
85 * Indicates that this user is ephemeral. I.e. the user will be removed after leaving
88 public static final int FLAG_EPHEMERAL = 0x00000100;
91 * User is for demo purposes only and can be removed at any time.
93 public static final int FLAG_DEMO = 0x00000200;
95 public static final int NO_PROFILE_GROUP_ID = UserHandle.USER_NULL;
98 public int serialNumber;
100 public String iconPath;
102 public long creationTime;
103 public long lastLoggedInTime;
104 public String lastLoggedInFingerprint;
105 public int profileGroupId;
106 public int restrictedProfileParentId;
108 /** User is only partially created. */
109 public boolean partial;
110 public boolean guestToRemove;
112 public UserInfo(int id, String name, int flags) {
113 this(id, name, null, flags);
116 public UserInfo(int id, String name, String iconPath, int flags) {
120 this.iconPath = iconPath;
121 this.profileGroupId = NO_PROFILE_GROUP_ID;
122 this.restrictedProfileParentId = NO_PROFILE_GROUP_ID;
125 public boolean isPrimary() {
126 return (flags & FLAG_PRIMARY) == FLAG_PRIMARY;
129 public boolean isAdmin() {
130 return (flags & FLAG_ADMIN) == FLAG_ADMIN;
133 public boolean isGuest() {
134 return (flags & FLAG_GUEST) == FLAG_GUEST;
137 public boolean isRestricted() {
138 return (flags & FLAG_RESTRICTED) == FLAG_RESTRICTED;
141 public boolean isManagedProfile() {
142 return (flags & FLAG_MANAGED_PROFILE) == FLAG_MANAGED_PROFILE;
145 public boolean isEnabled() {
146 return (flags & FLAG_DISABLED) != FLAG_DISABLED;
149 public boolean isQuietModeEnabled() {
150 return (flags & FLAG_QUIET_MODE) == FLAG_QUIET_MODE;
153 public boolean isEphemeral() {
154 return (flags & FLAG_EPHEMERAL) == FLAG_EPHEMERAL;
157 public boolean isInitialized() {
158 return (flags & FLAG_INITIALIZED) == FLAG_INITIALIZED;
161 public boolean isDemo() {
162 return (flags & FLAG_DEMO) == FLAG_DEMO;
166 * Returns true if the user is a split system user.
167 * <p>If {@link UserManager#isSplitSystemUser split system user mode} is not enabled,
168 * the method always returns false.
170 public boolean isSystemOnly() {
171 return isSystemOnly(id);
175 * Returns true if the given user is a split system user.
176 * <p>If {@link UserManager#isSplitSystemUser split system user mode} is not enabled,
177 * the method always returns false.
179 public static boolean isSystemOnly(int userId) {
180 return userId == UserHandle.USER_SYSTEM && UserManager.isSplitSystemUser();
184 * @return true if this user can be switched to.
186 public boolean supportsSwitchTo() {
187 if (isEphemeral() && !isEnabled()) {
188 // Don't support switching to an ephemeral user with removal in progress.
191 // TODO remove fw.show_hidden_users when we have finished developing managed profiles.
192 return !isManagedProfile() || SystemProperties.getBoolean("fw.show_hidden_users", false);
196 * @return true if this user can be switched to by end user through UI.
198 public boolean supportsSwitchToByUser() {
199 // Hide the system user when it does not represent a human user.
200 boolean hideSystemUser = UserManager.isSplitSystemUser();
201 return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo();
205 public boolean canHaveProfile() {
206 if (isManagedProfile() || isGuest() || isRestricted()) {
209 if (UserManager.isSplitSystemUser()) {
210 return id != UserHandle.USER_SYSTEM;
212 return id == UserHandle.USER_SYSTEM;
219 public UserInfo(UserInfo orig) {
221 iconPath = orig.iconPath;
224 serialNumber = orig.serialNumber;
225 creationTime = orig.creationTime;
226 lastLoggedInTime = orig.lastLoggedInTime;
227 lastLoggedInFingerprint = orig.lastLoggedInFingerprint;
228 partial = orig.partial;
229 profileGroupId = orig.profileGroupId;
230 restrictedProfileParentId = orig.restrictedProfileParentId;
231 guestToRemove = orig.guestToRemove;
234 public UserHandle getUserHandle() {
235 return new UserHandle(id);
239 public String toString() {
240 return "UserInfo{" + id + ":" + name + ":" + Integer.toHexString(flags) + "}";
243 public int describeContents() {
247 public void writeToParcel(Parcel dest, int parcelableFlags) {
249 dest.writeString(name);
250 dest.writeString(iconPath);
251 dest.writeInt(flags);
252 dest.writeInt(serialNumber);
253 dest.writeLong(creationTime);
254 dest.writeLong(lastLoggedInTime);
255 dest.writeString(lastLoggedInFingerprint);
256 dest.writeInt(partial ? 1 : 0);
257 dest.writeInt(profileGroupId);
258 dest.writeInt(guestToRemove ? 1 : 0);
259 dest.writeInt(restrictedProfileParentId);
262 public static final Parcelable.Creator<UserInfo> CREATOR
263 = new Parcelable.Creator<UserInfo>() {
264 public UserInfo createFromParcel(Parcel source) {
265 return new UserInfo(source);
267 public UserInfo[] newArray(int size) {
268 return new UserInfo[size];
272 private UserInfo(Parcel source) {
273 id = source.readInt();
274 name = source.readString();
275 iconPath = source.readString();
276 flags = source.readInt();
277 serialNumber = source.readInt();
278 creationTime = source.readLong();
279 lastLoggedInTime = source.readLong();
280 lastLoggedInFingerprint = source.readString();
281 partial = source.readInt() != 0;
282 profileGroupId = source.readInt();
283 guestToRemove = source.readInt() != 0;
284 restrictedProfileParentId = source.readInt();