• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.os.Bundle;
22 import android.os.Flags;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 import android.os.UserHandle;
26 import android.os.UserManager;
27 
28 /**
29  * The LauncherUserInfo object holds information about an Android user that is required to display
30  * the Launcher related UI elements specific to the user (like badges).
31  */
32 @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
33 public final class LauncherUserInfo implements Parcelable {
34 
35     /**
36      * A boolean extra indicating whether the private space entrypoint should be hidden when locked.
37      *
38      * @see #getUserConfig
39      */
40     @FlaggedApi(android.multiuser.Flags.FLAG_ADD_LAUNCHER_USER_CONFIG)
41     public static final String PRIVATE_SPACE_ENTRYPOINT_HIDDEN =
42             "private_space_entrypoint_hidden";
43 
44     private final String mUserType;
45 
46     // Serial number for the user, should be same as in the {@link UserInfo} object.
47     private final int mUserSerialNumber;
48 
49     // Additional configs for the user, e.g., whether to hide the private space entrypoint when
50     // locked.
51     private final Bundle mUserConfig;
52 
53 
54     /**
55      * Returns type of the user as defined in {@link UserManager}. e.g.,
56      * {@link UserManager.USER_TYPE_PROFILE_MANAGED} or {@link UserManager.USER_TYPE_PROFILE_ClONE}
57      * or {@link UserManager.USER_TYPE_PROFILE_PRIVATE}
58      *
59      * @return the userType for the user whose LauncherUserInfo this is
60      */
61     @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
62     @NonNull
getUserType()63     public String getUserType() {
64         return mUserType;
65     }
66 
67     /**
68      * Returns additional configs for this launcher user
69      *
70      * @see #PRIVATE_SPACE_ENTRYPOINT_HIDDEN
71      */
72     @FlaggedApi(android.multiuser.Flags.FLAG_ADD_LAUNCHER_USER_CONFIG)
73     @NonNull
getUserConfig()74     public Bundle getUserConfig() {
75         return mUserConfig;
76     }
77 
78     /**
79      * Returns serial number of user as returned by
80      * {@link UserManager#getSerialNumberForUser(UserHandle)}
81      *
82      * @return the serial number associated with the user
83      */
84     @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
getUserSerialNumber()85     public int getUserSerialNumber() {
86         return mUserSerialNumber;
87     }
88 
LauncherUserInfo(@onNull Parcel in)89     private LauncherUserInfo(@NonNull Parcel in) {
90         mUserType = in.readString16NoHelper();
91         mUserSerialNumber = in.readInt();
92         mUserConfig = in.readBundle(Bundle.class.getClassLoader());
93     }
94 
95     @Override
96     @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
writeToParcel(@onNull Parcel dest, int flags)97     public void writeToParcel(@NonNull Parcel dest, int flags) {
98         dest.writeString16NoHelper(mUserType);
99         dest.writeInt(mUserSerialNumber);
100         dest.writeBundle(mUserConfig);
101     }
102 
103     @Override
104     @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
describeContents()105     public int describeContents() {
106         return 0;
107     }
108 
109     @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
110     public static final @android.annotation.NonNull Creator<LauncherUserInfo> CREATOR =
111             new Creator<LauncherUserInfo>() {
112                 @Override
113                 public LauncherUserInfo createFromParcel(Parcel in) {
114                     return new LauncherUserInfo(in);
115                 }
116 
117                 @Override
118                 public LauncherUserInfo[] newArray(int size) {
119                     return new LauncherUserInfo[size];
120                 }
121             };
122 
123     /**
124      * @hide
125      */
126     public static final class Builder {
127         private final String mUserType;
128 
129         private final int mUserSerialNumber;
130         private final Bundle mUserConfig;
131 
132 
133         @FlaggedApi(android.multiuser.Flags.FLAG_ADD_LAUNCHER_USER_CONFIG)
Builder(@onNull String userType, int userSerialNumber, @NonNull Bundle config)134         public Builder(@NonNull String userType, int userSerialNumber, @NonNull Bundle config) {
135             this.mUserType = userType;
136             this.mUserSerialNumber = userSerialNumber;
137             this.mUserConfig = config;
138         }
139 
Builder(@onNull String userType, int userSerialNumber)140         public Builder(@NonNull String userType, int userSerialNumber) {
141             this.mUserType = userType;
142             this.mUserSerialNumber = userSerialNumber;
143             this.mUserConfig = new Bundle();
144         }
145 
146         /**
147          * Builds the LauncherUserInfo object
148          */
149         @NonNull
build()150         public LauncherUserInfo build() {
151             return new LauncherUserInfo(this.mUserType, this.mUserSerialNumber, this.mUserConfig);
152         }
153 
154     } // End builder
155 
LauncherUserInfo(@onNull String userType, int userSerialNumber, @NonNull Bundle config)156     private LauncherUserInfo(@NonNull String userType, int userSerialNumber,
157             @NonNull Bundle config) {
158         this.mUserType = userType;
159         this.mUserSerialNumber = userSerialNumber;
160         this.mUserConfig = config;
161     }
162 }
163