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 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 import android.os.SystemProperties; 22 import android.os.UserHandle; 23 24 /** 25 * Per-user information. 26 * @hide 27 */ 28 public class UserInfo implements Parcelable { 29 30 /** 8 bits for user type */ 31 public static final int FLAG_MASK_USER_TYPE = 0x000000FF; 32 33 /** 34 * *************************** NOTE *************************** 35 * These flag values CAN NOT CHANGE because they are written 36 * directly to storage. 37 */ 38 39 /** 40 * Primary user. Only one user can have this flag set. Meaning of this 41 * flag TBD. 42 */ 43 public static final int FLAG_PRIMARY = 0x00000001; 44 45 /** 46 * User with administrative privileges. Such a user can create and 47 * delete users. 48 */ 49 public static final int FLAG_ADMIN = 0x00000002; 50 51 /** 52 * Indicates a guest user that may be transient. 53 */ 54 public static final int FLAG_GUEST = 0x00000004; 55 56 /** 57 * Indicates the user has restrictions in privileges, in addition to those for normal users. 58 * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts. 59 */ 60 public static final int FLAG_RESTRICTED = 0x00000008; 61 62 /** 63 * Indicates that this user has gone through its first-time initialization. 64 */ 65 public static final int FLAG_INITIALIZED = 0x00000010; 66 67 /** 68 * Indicates that this user is a profile of another user, for example holding a users 69 * corporate data. 70 */ 71 public static final int FLAG_MANAGED_PROFILE = 0x00000020; 72 73 /** 74 * Indicates that this user is disabled. 75 */ 76 public static final int FLAG_DISABLED = 0x00000040; 77 78 79 public static final int NO_PROFILE_GROUP_ID = -1; 80 81 public int id; 82 public int serialNumber; 83 public String name; 84 public String iconPath; 85 public int flags; 86 public long creationTime; 87 public long lastLoggedInTime; 88 public int profileGroupId; 89 90 /** User is only partially created. */ 91 public boolean partial; 92 public boolean guestToRemove; 93 UserInfo(int id, String name, int flags)94 public UserInfo(int id, String name, int flags) { 95 this(id, name, null, flags); 96 } 97 UserInfo(int id, String name, String iconPath, int flags)98 public UserInfo(int id, String name, String iconPath, int flags) { 99 this.id = id; 100 this.name = name; 101 this.flags = flags; 102 this.iconPath = iconPath; 103 this.profileGroupId = NO_PROFILE_GROUP_ID; 104 } 105 isPrimary()106 public boolean isPrimary() { 107 return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; 108 } 109 isAdmin()110 public boolean isAdmin() { 111 return (flags & FLAG_ADMIN) == FLAG_ADMIN; 112 } 113 isGuest()114 public boolean isGuest() { 115 return (flags & FLAG_GUEST) == FLAG_GUEST; 116 } 117 isRestricted()118 public boolean isRestricted() { 119 return (flags & FLAG_RESTRICTED) == FLAG_RESTRICTED; 120 } 121 isManagedProfile()122 public boolean isManagedProfile() { 123 return (flags & FLAG_MANAGED_PROFILE) == FLAG_MANAGED_PROFILE; 124 } 125 isEnabled()126 public boolean isEnabled() { 127 return (flags & FLAG_DISABLED) != FLAG_DISABLED; 128 } 129 130 /** 131 * @return true if this user can be switched to. 132 **/ supportsSwitchTo()133 public boolean supportsSwitchTo() { 134 // TODO remove fw.show_hidden_users when we have finished developing managed profiles. 135 return !isManagedProfile() || SystemProperties.getBoolean("fw.show_hidden_users", false); 136 } 137 UserInfo()138 public UserInfo() { 139 } 140 UserInfo(UserInfo orig)141 public UserInfo(UserInfo orig) { 142 name = orig.name; 143 iconPath = orig.iconPath; 144 id = orig.id; 145 flags = orig.flags; 146 serialNumber = orig.serialNumber; 147 creationTime = orig.creationTime; 148 lastLoggedInTime = orig.lastLoggedInTime; 149 partial = orig.partial; 150 profileGroupId = orig.profileGroupId; 151 guestToRemove = orig.guestToRemove; 152 } 153 getUserHandle()154 public UserHandle getUserHandle() { 155 return new UserHandle(id); 156 } 157 158 @Override toString()159 public String toString() { 160 return "UserInfo{" + id + ":" + name + ":" + Integer.toHexString(flags) + "}"; 161 } 162 describeContents()163 public int describeContents() { 164 return 0; 165 } 166 writeToParcel(Parcel dest, int parcelableFlags)167 public void writeToParcel(Parcel dest, int parcelableFlags) { 168 dest.writeInt(id); 169 dest.writeString(name); 170 dest.writeString(iconPath); 171 dest.writeInt(flags); 172 dest.writeInt(serialNumber); 173 dest.writeLong(creationTime); 174 dest.writeLong(lastLoggedInTime); 175 dest.writeInt(partial ? 1 : 0); 176 dest.writeInt(profileGroupId); 177 dest.writeInt(guestToRemove ? 1 : 0); 178 } 179 180 public static final Parcelable.Creator<UserInfo> CREATOR 181 = new Parcelable.Creator<UserInfo>() { 182 public UserInfo createFromParcel(Parcel source) { 183 return new UserInfo(source); 184 } 185 public UserInfo[] newArray(int size) { 186 return new UserInfo[size]; 187 } 188 }; 189 UserInfo(Parcel source)190 private UserInfo(Parcel source) { 191 id = source.readInt(); 192 name = source.readString(); 193 iconPath = source.readString(); 194 flags = source.readInt(); 195 serialNumber = source.readInt(); 196 creationTime = source.readLong(); 197 lastLoggedInTime = source.readLong(); 198 partial = source.readInt() != 0; 199 profileGroupId = source.readInt(); 200 guestToRemove = source.readInt() != 0; 201 } 202 } 203