UserInfo.java revision 920ace0bbc2d4133dbec991d2636c99a57d6245e
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
17package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.os.UserHandle;
22
23/**
24 * Per-user information.
25 * @hide
26 */
27public 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    public UserInfo(int id, String name, int flags) {
75        this(id, name, null, flags);
76    }
77
78    public UserInfo(int id, String name, String iconPath, int flags) {
79        this.id = id;
80        this.name = name;
81        this.flags = flags;
82        this.iconPath = iconPath;
83    }
84
85    public boolean isPrimary() {
86        return (flags & FLAG_PRIMARY) == FLAG_PRIMARY;
87    }
88
89    public boolean isAdmin() {
90        return (flags & FLAG_ADMIN) == FLAG_ADMIN;
91    }
92
93    public boolean isGuest() {
94        return (flags & FLAG_GUEST) == FLAG_GUEST;
95    }
96
97    public UserInfo() {
98    }
99
100    public UserInfo(UserInfo orig) {
101        name = orig.name;
102        iconPath = orig.iconPath;
103        id = orig.id;
104        flags = orig.flags;
105        serialNumber = orig.serialNumber;
106        creationTime = orig.creationTime;
107        lastLoggedInTime = orig.lastLoggedInTime;
108    }
109
110    public UserHandle getUserHandle() {
111        return new UserHandle(id);
112    }
113
114    @Override
115    public String toString() {
116        return "UserInfo{" + id + ":" + name + ":" + Integer.toHexString(flags) + "}";
117    }
118
119    public int describeContents() {
120        return 0;
121    }
122
123    public void writeToParcel(Parcel dest, int parcelableFlags) {
124        dest.writeInt(id);
125        dest.writeString(name);
126        dest.writeString(iconPath);
127        dest.writeInt(flags);
128        dest.writeInt(serialNumber);
129        dest.writeLong(creationTime);
130        dest.writeLong(lastLoggedInTime);
131    }
132
133    public static final Parcelable.Creator<UserInfo> CREATOR
134            = new Parcelable.Creator<UserInfo>() {
135        public UserInfo createFromParcel(Parcel source) {
136            return new UserInfo(source);
137        }
138        public UserInfo[] newArray(int size) {
139            return new UserInfo[size];
140        }
141    };
142
143    private UserInfo(Parcel source) {
144        id = source.readInt();
145        name = source.readString();
146        iconPath = source.readString();
147        flags = source.readInt();
148        serialNumber = source.readInt();
149        creationTime = source.readLong();
150        lastLoggedInTime = source.readLong();
151    }
152}
153