Home | History | Annotate | Download | only in pm
      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 
     77     public UserInfo(int id, String name, int flags) {
     78         this(id, name, null, flags);
     79     }
     80 
     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 
     88     public boolean isPrimary() {
     89         return (flags & FLAG_PRIMARY) == FLAG_PRIMARY;
     90     }
     91 
     92     public boolean isAdmin() {
     93         return (flags & FLAG_ADMIN) == FLAG_ADMIN;
     94     }
     95 
     96     public boolean isGuest() {
     97         return (flags & FLAG_GUEST) == FLAG_GUEST;
     98     }
     99 
    100     public boolean isRestricted() {
    101         return (flags & FLAG_RESTRICTED) == FLAG_RESTRICTED;
    102     }
    103 
    104     public UserInfo() {
    105     }
    106 
    107     public UserInfo(UserInfo orig) {
    108         name = orig.name;
    109         iconPath = orig.iconPath;
    110         id = orig.id;
    111         flags = orig.flags;
    112         serialNumber = orig.serialNumber;
    113         creationTime = orig.creationTime;
    114         lastLoggedInTime = orig.lastLoggedInTime;
    115         partial = orig.partial;
    116     }
    117 
    118     public UserHandle getUserHandle() {
    119         return new UserHandle(id);
    120     }
    121 
    122     @Override
    123     public String toString() {
    124         return "UserInfo{" + id + ":" + name + ":" + Integer.toHexString(flags) + "}";
    125     }
    126 
    127     public int describeContents() {
    128         return 0;
    129     }
    130 
    131     public void writeToParcel(Parcel dest, int parcelableFlags) {
    132         dest.writeInt(id);
    133         dest.writeString(name);
    134         dest.writeString(iconPath);
    135         dest.writeInt(flags);
    136         dest.writeInt(serialNumber);
    137         dest.writeLong(creationTime);
    138         dest.writeLong(lastLoggedInTime);
    139         dest.writeInt(partial ? 1 : 0);
    140     }
    141 
    142     public static final Parcelable.Creator<UserInfo> CREATOR
    143             = new Parcelable.Creator<UserInfo>() {
    144         public UserInfo createFromParcel(Parcel source) {
    145             return new UserInfo(source);
    146         }
    147         public UserInfo[] newArray(int size) {
    148             return new UserInfo[size];
    149         }
    150     };
    151 
    152     private UserInfo(Parcel source) {
    153         id = source.readInt();
    154         name = source.readString();
    155         iconPath = source.readString();
    156         flags = source.readInt();
    157         serialNumber = source.readInt();
    158         creationTime = source.readLong();
    159         lastLoggedInTime = source.readLong();
    160         partial = source.readInt() != 0;
    161     }
    162 }
    163