• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.UserHandle;
22 
23 /**
24  * Per-user information.
25  * @hide
26  */
27 public class UserInfo implements Parcelable {
28 
29     /** 6 bits for user type */
30     public static final int FLAG_MASK_USER_TYPE = 0x0000003F;
31 
32     /**
33      * *************************** NOTE ***************************
34      * These flag values CAN NOT CHANGE because they are written
35      * directly to storage.
36      */
37 
38     /**
39      * Primary user. Only one user can have this flag set. Meaning of this
40      * flag TBD.
41      */
42     public static final int FLAG_PRIMARY = 0x00000001;
43 
44     /**
45      * User with administrative privileges. Such a user can create and
46      * delete users.
47      */
48     public static final int FLAG_ADMIN   = 0x00000002;
49 
50     /**
51      * Indicates a guest user that may be transient.
52      */
53     public static final int FLAG_GUEST   = 0x00000004;
54 
55     /**
56      * Indicates the user has restrictions in privileges, in addition to those for normal users.
57      * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts.
58      */
59     public static final int FLAG_RESTRICTED = 0x00000008;
60 
61     /**
62      * Indicates that this user has gone through its first-time initialization.
63      */
64     public static final int FLAG_INITIALIZED = 0x00000010;
65 
66     public int id;
67     public int serialNumber;
68     public String name;
69     public String iconPath;
70     public int flags;
71     public long creationTime;
72     public long lastLoggedInTime;
73 
74     /** User is only partially created. */
75     public boolean partial;
76 
UserInfo(int id, String name, int flags)77     public UserInfo(int id, String name, int flags) {
78         this(id, name, null, flags);
79     }
80 
UserInfo(int id, String name, String iconPath, int flags)81     public UserInfo(int id, String name, String iconPath, int flags) {
82         this.id = id;
83         this.name = name;
84         this.flags = flags;
85         this.iconPath = iconPath;
86     }
87 
isPrimary()88     public boolean isPrimary() {
89         return (flags & FLAG_PRIMARY) == FLAG_PRIMARY;
90     }
91 
isAdmin()92     public boolean isAdmin() {
93         return (flags & FLAG_ADMIN) == FLAG_ADMIN;
94     }
95 
isGuest()96     public boolean isGuest() {
97         return (flags & FLAG_GUEST) == FLAG_GUEST;
98     }
99 
UserInfo()100     public UserInfo() {
101     }
102 
UserInfo(UserInfo orig)103     public UserInfo(UserInfo orig) {
104         name = orig.name;
105         iconPath = orig.iconPath;
106         id = orig.id;
107         flags = orig.flags;
108         serialNumber = orig.serialNumber;
109         creationTime = orig.creationTime;
110         lastLoggedInTime = orig.lastLoggedInTime;
111         partial = orig.partial;
112     }
113 
getUserHandle()114     public UserHandle getUserHandle() {
115         return new UserHandle(id);
116     }
117 
118     @Override
toString()119     public String toString() {
120         return "UserInfo{" + id + ":" + name + ":" + Integer.toHexString(flags) + "}";
121     }
122 
describeContents()123     public int describeContents() {
124         return 0;
125     }
126 
writeToParcel(Parcel dest, int parcelableFlags)127     public void writeToParcel(Parcel dest, int parcelableFlags) {
128         dest.writeInt(id);
129         dest.writeString(name);
130         dest.writeString(iconPath);
131         dest.writeInt(flags);
132         dest.writeInt(serialNumber);
133         dest.writeLong(creationTime);
134         dest.writeLong(lastLoggedInTime);
135         dest.writeInt(partial ? 1 : 0);
136     }
137 
138     public static final Parcelable.Creator<UserInfo> CREATOR
139             = new Parcelable.Creator<UserInfo>() {
140         public UserInfo createFromParcel(Parcel source) {
141             return new UserInfo(source);
142         }
143         public UserInfo[] newArray(int size) {
144             return new UserInfo[size];
145         }
146     };
147 
UserInfo(Parcel source)148     private UserInfo(Parcel source) {
149         id = source.readInt();
150         name = source.readString();
151         iconPath = source.readString();
152         flags = source.readInt();
153         serialNumber = source.readInt();
154         creationTime = source.readLong();
155         lastLoggedInTime = source.readLong();
156         partial = source.readInt() != 0;
157     }
158 }
159