• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 com.android.server.pm;
18 
19 import android.annotation.ColorRes;
20 import android.annotation.DrawableRes;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.annotation.StringRes;
24 import android.content.pm.UserInfo;
25 import android.content.pm.UserInfo.UserInfoFlag;
26 import android.content.res.Resources;
27 import android.os.Bundle;
28 import android.os.UserManager;
29 
30 import com.android.internal.util.Preconditions;
31 import com.android.server.BundleUtils;
32 
33 import java.io.PrintWriter;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37 
38 /**
39  * Contains the details about a multiuser "user type", such as a
40  * {@link UserManager#USER_TYPE_PROFILE_MANAGED}.
41  *
42  * Tests are located in UserManagerServiceUserTypeTest.java.
43  * @hide
44  */
45 public final class UserTypeDetails {
46 
47     /** Indicates that there is no limit to the number of users allowed. */
48     public static final int UNLIMITED_NUMBER_OF_USERS = -1;
49 
50     /** Name of the user type, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}. */
51     private final @NonNull String mName;
52 
53     // TODO(b/142482943): Currently unused. Hook this up.
54     private final boolean mEnabled;
55 
56     // TODO(b/142482943): Currently unused and not set. Hook this up.
57     private final int mLabel;
58 
59     /**
60      * Maximum number of this user type allowed on the device.
61      * Use {@link #UNLIMITED_NUMBER_OF_USERS} to indicate that there is no hard limit.
62      */
63     private final int mMaxAllowed;
64 
65     /**
66      * Maximum number of this user type allowed per parent (for user types, like profiles, that
67      * have parents).
68      * Use {@link #UNLIMITED_NUMBER_OF_USERS} to indicate that there is no hard limit.
69      */
70     // TODO(b/142482943): Should this also apply to restricted profiles?
71     private final int mMaxAllowedPerParent;
72 
73     // TODO(b/143784345): Update doc when we clean up UserInfo.
74     /** The {@link UserInfo.UserInfoFlag} representing the base type of this user. */
75     private final @UserInfoFlag int mBaseType;
76 
77     // TODO(b/143784345): Update doc/name when we clean up UserInfo.
78     /** The {@link UserInfo.UserInfoFlag}s that all users of this type will automatically have. */
79     private final @UserInfoFlag int mDefaultUserInfoPropertyFlags;
80 
81     /**
82      * List of User Restrictions to apply by default to newly created users of this type.
83      * <p>Does not apply to SYSTEM users (since they are not formally created); for them use
84      * {@link com.android.internal.R.array#config_defaultFirstUserRestrictions} instead.
85      * The Bundle is of the form used by {@link UserRestrictionsUtils}.
86      */
87     private final @Nullable Bundle mDefaultRestrictions;
88 
89     /**
90      * List of {@link android.provider.Settings.System} to apply by default to newly created users
91      * of this type.
92      */
93     private final @Nullable Bundle mDefaultSystemSettings;
94 
95     /**
96      * List of {@link android.provider.Settings.Secure} to apply by default to newly created users
97      * of this type.
98      */
99     private final @Nullable Bundle mDefaultSecureSettings;
100 
101     /**
102      * List of {@link DefaultCrossProfileIntentFilter} to allow by default for newly created
103      * profiles.
104      */
105     private final @Nullable List<DefaultCrossProfileIntentFilter> mDefaultCrossProfileIntentFilters;
106 
107 
108     // Fields for profiles only, controlling the nature of their badges.
109     // All badge information should be set if {@link #hasBadge()} is true.
110 
111     /** Resource ID of the badge put on icons. */
112     private @DrawableRes final int mIconBadge;
113     /** Resource ID of the badge. Should be set if mIconBadge is set. */
114     private @DrawableRes final int mBadgePlain;
115     /** Resource ID of the badge without a background. Should be set if mIconBadge is set. */
116     private @DrawableRes final int mBadgeNoBackground;
117 
118     /**
119      * Resource ID ({@link StringRes}) of the of the labels to describe badged apps; should be the
120      * same format as com.android.internal.R.color.profile_badge_1. These are used for accessibility
121      * services.
122      *
123      * <p>This is an array because, in general, there may be multiple users of the same user type.
124      * In this case, the user is indexed according to its {@link UserInfo#profileBadge}.
125      *
126      * <p>Must be set if mIconBadge is set.
127      */
128     private final @Nullable int[] mBadgeLabels;
129 
130     /**
131      * Resource ID ({@link ColorRes}) of the colors badge put on icons.
132      * (The value is a resource ID referring to the color; it is not the color value itself).
133      *
134      * <p>This is an array because, in general, there may be multiple users of the same user type.
135      * In this case, the user is indexed according to its {@link UserInfo#profileBadge}.
136      *
137      * <p>Must be set if mIconBadge is set.
138      */
139     private final @Nullable int[] mBadgeColors;
140 
141     /**
142      * Resource ID ({@link ColorRes}) of the colors badge put on icons when in dark theme.
143      * (The value is a resource ID referring to the color; it is not the color value itself).
144      *
145      * <p>This is an array because, in general, there may be multiple users of the same user type.
146      * In this case, the user is indexed according to its {@link UserInfo#profileBadge}.
147      *
148      * <p>Must be set if mIconBadge is set.
149      */
150     private final @Nullable int[] mDarkThemeBadgeColors;
151 
152     /**
153      * Denotes if the user shares media with its parent user.
154      *
155      * <p> Default value is false
156      */
157     private final boolean mIsMediaSharedWithParent;
158 
UserTypeDetails(@onNull String name, boolean enabled, int maxAllowed, @UserInfoFlag int baseType, @UserInfoFlag int defaultUserInfoPropertyFlags, int label, int maxAllowedPerParent, int iconBadge, int badgePlain, int badgeNoBackground, @Nullable int[] badgeLabels, @Nullable int[] badgeColors, @Nullable int[] darkThemeBadgeColors, @Nullable Bundle defaultRestrictions, @Nullable Bundle defaultSystemSettings, @Nullable Bundle defaultSecureSettings, @Nullable List<DefaultCrossProfileIntentFilter> defaultCrossProfileIntentFilters, boolean isMediaSharedWithParent)159     private UserTypeDetails(@NonNull String name, boolean enabled, int maxAllowed,
160             @UserInfoFlag int baseType, @UserInfoFlag int defaultUserInfoPropertyFlags, int label,
161             int maxAllowedPerParent,
162             int iconBadge, int badgePlain, int badgeNoBackground,
163             @Nullable int[] badgeLabels, @Nullable int[] badgeColors,
164             @Nullable int[] darkThemeBadgeColors,
165             @Nullable Bundle defaultRestrictions,
166             @Nullable Bundle defaultSystemSettings,
167             @Nullable Bundle defaultSecureSettings,
168             @Nullable List<DefaultCrossProfileIntentFilter> defaultCrossProfileIntentFilters,
169             boolean isMediaSharedWithParent) {
170         this.mName = name;
171         this.mEnabled = enabled;
172         this.mMaxAllowed = maxAllowed;
173         this.mMaxAllowedPerParent = maxAllowedPerParent;
174         this.mBaseType = baseType;
175         this.mDefaultUserInfoPropertyFlags = defaultUserInfoPropertyFlags;
176         this.mDefaultRestrictions = defaultRestrictions;
177         this.mDefaultSystemSettings = defaultSystemSettings;
178         this.mDefaultSecureSettings = defaultSecureSettings;
179         this.mDefaultCrossProfileIntentFilters = defaultCrossProfileIntentFilters;
180 
181         this.mIconBadge = iconBadge;
182         this.mBadgePlain = badgePlain;
183         this.mBadgeNoBackground = badgeNoBackground;
184         this.mLabel = label;
185         this.mBadgeLabels = badgeLabels;
186         this.mBadgeColors = badgeColors;
187         this.mDarkThemeBadgeColors = darkThemeBadgeColors;
188         this.mIsMediaSharedWithParent = isMediaSharedWithParent;
189     }
190 
191     /**
192      * Returns the name of the user type, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}.
193      */
getName()194     public String getName() {
195         return mName;
196     }
197 
198     // TODO(b/142482943) Hook this up or delete it.
isEnabled()199     public boolean isEnabled() {
200         return mEnabled;
201     }
202 
203     /**
204      * Returns the maximum number of this user type allowed on the device.
205      * <p>Returns {@link #UNLIMITED_NUMBER_OF_USERS} to indicate that there is no hard limit.
206      */
getMaxAllowed()207     public int getMaxAllowed() {
208         return mMaxAllowed;
209     }
210 
211     /**
212      * Returns the maximum number of this user type allowed per parent (for user types, like
213      * profiles, that have parents).
214      * Under certain circumstances (such as after a change-user-type) the max value can actually
215      * be exceeded: this is allowed in order to keep the device in a usable state.
216      * An error is logged in {@link UserManagerService#upgradeProfileToTypeLU}
217      * <p>Returns {@link #UNLIMITED_NUMBER_OF_USERS} to indicate that there is no hard limit.
218      */
getMaxAllowedPerParent()219     public int getMaxAllowedPerParent() {
220         return mMaxAllowedPerParent;
221     }
222 
223     // TODO(b/143784345): Update comment when UserInfo is reorganized.
224     /** The {@link UserInfo.UserInfoFlag}s that all users of this type will automatically have. */
getDefaultUserInfoFlags()225     public int getDefaultUserInfoFlags() {
226         return mDefaultUserInfoPropertyFlags | mBaseType;
227     }
228 
229     // TODO(b/142482943) Hook this up; it is currently unused.
getLabel()230     public int getLabel() {
231         return mLabel;
232     }
233 
234     /** Returns whether users of this user type should be badged. */
hasBadge()235     public boolean hasBadge() {
236         return mIconBadge != Resources.ID_NULL;
237     }
238 
239     /** Resource ID of the badge to put on icons. */
getIconBadge()240     public @DrawableRes int getIconBadge() {
241         return mIconBadge;
242     }
243 
244     /** Resource ID of the badge. Used for {@link UserManager#getUserBadgeResId(int)}. */
getBadgePlain()245     public @DrawableRes int getBadgePlain() {
246         return mBadgePlain;
247     }
248 
249     /** Resource ID of the badge without a background. */
getBadgeNoBackground()250     public @DrawableRes int getBadgeNoBackground() {
251         return mBadgeNoBackground;
252     }
253 
254     /**
255      * Returns the Resource ID of the badgeIndexth badge label, where the badgeIndex is expected
256      * to be the {@link UserInfo#profileBadge} of the user.
257      * If badgeIndex exceeds the number of labels, returns the label for the highest index.
258      */
getBadgeLabel(int badgeIndex)259     public @StringRes int getBadgeLabel(int badgeIndex) {
260         if (mBadgeLabels == null || mBadgeLabels.length == 0 || badgeIndex < 0) {
261             return Resources.ID_NULL;
262         }
263         return mBadgeLabels[Math.min(badgeIndex, mBadgeLabels.length - 1)];
264     }
265 
266     /**
267      * Returns the Resource ID of the badgeIndexth badge color, where the badgeIndex is expected
268      * to be the {@link UserInfo#profileBadge} of the user.
269      * If badgeIndex exceeds the number of colors, returns the color for the highest index.
270      */
getBadgeColor(int badgeIndex)271     public @ColorRes int getBadgeColor(int badgeIndex) {
272         if (mBadgeColors == null || mBadgeColors.length == 0 || badgeIndex < 0) {
273             return Resources.ID_NULL;
274         }
275         return mBadgeColors[Math.min(badgeIndex, mBadgeColors.length - 1)];
276     }
277 
278     /**
279      * Returns the Resource ID of the badgeIndexth dark theme badge color, where the badgeIndex is
280      * expected to be the {@link UserInfo#profileBadge} of the user.
281      * If dark theme badge colors haven't been set, use the light theme badge color.
282      * If badgeIndex exceeds the number of colors, returns the color for the highest index.
283      */
getDarkThemeBadgeColor(int badgeIndex)284     public @ColorRes int getDarkThemeBadgeColor(int badgeIndex) {
285         if (mDarkThemeBadgeColors == null || mDarkThemeBadgeColors.length == 0 || badgeIndex < 0) {
286             return getBadgeColor(badgeIndex);
287         }
288         return mDarkThemeBadgeColors[Math.min(badgeIndex, mDarkThemeBadgeColors.length - 1)];
289     }
290 
isProfile()291     public boolean isProfile() {
292         return (mBaseType & UserInfo.FLAG_PROFILE) != 0;
293     }
294 
isFull()295     public boolean isFull() {
296         return (mBaseType & UserInfo.FLAG_FULL) != 0;
297     }
298 
isSystem()299     public boolean isSystem() {
300         return (mBaseType & UserInfo.FLAG_SYSTEM) != 0;
301     }
302 
303     /**
304      * Returns true if the user has shared media with parent user or false otherwise.
305      */
isMediaSharedWithParent()306     public boolean isMediaSharedWithParent() {
307         return mIsMediaSharedWithParent;
308     }
309 
310     /** Returns a {@link Bundle} representing the default user restrictions. */
getDefaultRestrictions()311     @NonNull Bundle getDefaultRestrictions() {
312         return BundleUtils.clone(mDefaultRestrictions);
313     }
314 
315     /** Adds the default user restrictions to the given bundle of restrictions. */
addDefaultRestrictionsTo(@onNull Bundle currentRestrictions)316     public void addDefaultRestrictionsTo(@NonNull Bundle currentRestrictions) {
317         UserRestrictionsUtils.merge(currentRestrictions, mDefaultRestrictions);
318     }
319 
320     /** Returns a {@link Bundle} representing the default system settings. */
getDefaultSystemSettings()321     @NonNull Bundle getDefaultSystemSettings() {
322         return BundleUtils.clone(mDefaultSystemSettings);
323     }
324 
325     /** Returns a {@link Bundle} representing the default secure settings. */
getDefaultSecureSettings()326     @NonNull Bundle getDefaultSecureSettings() {
327         return BundleUtils.clone(mDefaultSecureSettings);
328     }
329 
330     /** Returns a list of default cross profile intent filters. */
getDefaultCrossProfileIntentFilters()331     @NonNull List<DefaultCrossProfileIntentFilter> getDefaultCrossProfileIntentFilters() {
332         return mDefaultCrossProfileIntentFilters != null
333                 ? new ArrayList<>(mDefaultCrossProfileIntentFilters)
334                 : Collections.emptyList();
335     }
336 
337     /** Dumps details of the UserTypeDetails. Do not parse this. */
dump(PrintWriter pw, String prefix)338     public void dump(PrintWriter pw, String prefix) {
339         pw.print(prefix); pw.print("mName: "); pw.println(mName);
340         pw.print(prefix); pw.print("mBaseType: "); pw.println(UserInfo.flagsToString(mBaseType));
341         pw.print(prefix); pw.print("mEnabled: "); pw.println(mEnabled);
342         pw.print(prefix); pw.print("mMaxAllowed: "); pw.println(mMaxAllowed);
343         pw.print(prefix); pw.print("mMaxAllowedPerParent: "); pw.println(mMaxAllowedPerParent);
344         pw.print(prefix); pw.print("mDefaultUserInfoFlags: ");
345         pw.println(UserInfo.flagsToString(mDefaultUserInfoPropertyFlags));
346         pw.print(prefix); pw.print("mLabel: "); pw.println(mLabel);
347 
348         final String restrictionsPrefix = prefix + "    ";
349         if (isSystem()) {
350             pw.print(prefix); pw.println("config_defaultFirstUserRestrictions: ");
351             try {
352                 final Bundle restrictions = new Bundle();
353                 final String[] defaultFirstUserRestrictions = Resources.getSystem().getStringArray(
354                         com.android.internal.R.array.config_defaultFirstUserRestrictions);
355                 for (String userRestriction : defaultFirstUserRestrictions) {
356                     if (UserRestrictionsUtils.isValidRestriction(userRestriction)) {
357                         restrictions.putBoolean(userRestriction, true);
358                     }
359                 }
360                 UserRestrictionsUtils.dumpRestrictions(pw, restrictionsPrefix, restrictions);
361             } catch (Resources.NotFoundException e) {
362                 pw.print(restrictionsPrefix); pw.println("none - resource not found");
363             }
364         } else {
365             pw.print(prefix); pw.println("mDefaultRestrictions: ");
366             UserRestrictionsUtils.dumpRestrictions(pw, restrictionsPrefix, mDefaultRestrictions);
367         }
368 
369         pw.print(prefix); pw.print("mIconBadge: "); pw.println(mIconBadge);
370         pw.print(prefix); pw.print("mBadgePlain: "); pw.println(mBadgePlain);
371         pw.print(prefix); pw.print("mBadgeNoBackground: "); pw.println(mBadgeNoBackground);
372         pw.print(prefix); pw.print("mBadgeLabels.length: ");
373         pw.println(mBadgeLabels != null ? mBadgeLabels.length : "0(null)");
374         pw.print(prefix); pw.print("mBadgeColors.length: ");
375         pw.println(mBadgeColors != null ? mBadgeColors.length : "0(null)");
376         pw.print(prefix); pw.print("mDarkThemeBadgeColors.length: ");
377         pw.println(mDarkThemeBadgeColors != null ? mDarkThemeBadgeColors.length : "0(null)");
378     }
379 
380     /** Builder for a {@link UserTypeDetails}; see that class for documentation. */
381     public static final class Builder {
382         // UserTypeDetails properties and their default values.
383         private String mName; // This MUST be explicitly set.
384         private int mBaseType; // This MUST be explicitly set.
385         private int mMaxAllowed = UNLIMITED_NUMBER_OF_USERS;
386         private int mMaxAllowedPerParent = UNLIMITED_NUMBER_OF_USERS;
387         private int mDefaultUserInfoPropertyFlags = 0;
388         private @Nullable Bundle mDefaultRestrictions = null;
389         private @Nullable Bundle mDefaultSystemSettings = null;
390         private @Nullable Bundle mDefaultSecureSettings = null;
391         private @Nullable List<DefaultCrossProfileIntentFilter> mDefaultCrossProfileIntentFilters =
392                 null;
393         private boolean mEnabled = true;
394         private int mLabel = Resources.ID_NULL;
395         private @Nullable int[] mBadgeLabels = null;
396         private @Nullable int[] mBadgeColors = null;
397         private @Nullable int[] mDarkThemeBadgeColors = null;
398         private @DrawableRes int mIconBadge = Resources.ID_NULL;
399         private @DrawableRes int mBadgePlain = Resources.ID_NULL;
400         private @DrawableRes int mBadgeNoBackground = Resources.ID_NULL;
401         private boolean mIsMediaSharedWithParent = false;
402 
setName(String name)403         public Builder setName(String name) {
404             mName = name;
405             return this;
406         }
407 
setEnabled(boolean enabled)408         public Builder setEnabled(boolean enabled) {
409             mEnabled = enabled;
410             return this;
411         }
412 
setMaxAllowed(int maxAllowed)413         public Builder setMaxAllowed(int maxAllowed) {
414             mMaxAllowed = maxAllowed;
415             return this;
416         }
417 
setMaxAllowedPerParent(int maxAllowedPerParent)418         public Builder setMaxAllowedPerParent(int maxAllowedPerParent) {
419             mMaxAllowedPerParent = maxAllowedPerParent;
420             return this;
421         }
422 
setBaseType(@serInfoFlag int baseType)423         public Builder setBaseType(@UserInfoFlag int baseType) {
424             mBaseType = baseType;
425             return this;
426         }
427 
setDefaultUserInfoPropertyFlags(@serInfoFlag int flags)428         public Builder setDefaultUserInfoPropertyFlags(@UserInfoFlag int flags) {
429             mDefaultUserInfoPropertyFlags = flags;
430             return this;
431         }
432 
setBadgeLabels(@tringRes int ... badgeLabels)433         public Builder setBadgeLabels(@StringRes int ... badgeLabels) {
434             mBadgeLabels = badgeLabels;
435             return this;
436         }
437 
setBadgeColors(@olorRes int ... badgeColors)438         public Builder setBadgeColors(@ColorRes int ... badgeColors) {
439             mBadgeColors = badgeColors;
440             return this;
441         }
442 
443         /**
444          * The badge colors when the badge is on a dark background.
445          */
setDarkThemeBadgeColors(@olorRes int ... darkThemeBadgeColors)446         public Builder setDarkThemeBadgeColors(@ColorRes int ... darkThemeBadgeColors) {
447             mDarkThemeBadgeColors = darkThemeBadgeColors;
448             return this;
449         }
450 
setIconBadge(@rawableRes int badgeIcon)451         public Builder setIconBadge(@DrawableRes int badgeIcon) {
452             mIconBadge = badgeIcon;
453             return this;
454         }
455 
setBadgePlain(@rawableRes int badgePlain)456         public Builder setBadgePlain(@DrawableRes int badgePlain) {
457             mBadgePlain = badgePlain;
458             return this;
459         }
460 
setBadgeNoBackground(@rawableRes int badgeNoBackground)461         public Builder setBadgeNoBackground(@DrawableRes int badgeNoBackground) {
462             mBadgeNoBackground = badgeNoBackground;
463             return this;
464         }
465 
setLabel(int label)466         public Builder setLabel(int label) {
467             mLabel = label;
468             return this;
469         }
470 
setDefaultRestrictions(@ullable Bundle restrictions)471         public Builder setDefaultRestrictions(@Nullable Bundle restrictions) {
472             mDefaultRestrictions = restrictions;
473             return this;
474         }
475 
setDefaultSystemSettings(@ullable Bundle settings)476         public Builder setDefaultSystemSettings(@Nullable Bundle settings) {
477             mDefaultSystemSettings = settings;
478             return this;
479         }
480 
setDefaultSecureSettings(@ullable Bundle settings)481         public Builder setDefaultSecureSettings(@Nullable Bundle settings) {
482             mDefaultSecureSettings = settings;
483             return this;
484         }
485 
setDefaultCrossProfileIntentFilters( @ullable List<DefaultCrossProfileIntentFilter> intentFilters)486         public Builder setDefaultCrossProfileIntentFilters(
487                 @Nullable List<DefaultCrossProfileIntentFilter> intentFilters) {
488             mDefaultCrossProfileIntentFilters = intentFilters;
489             return this;
490         }
491 
492         /**
493          * Sets shared media property for the user.
494          * @param isMediaSharedWithParent the value to be set, true or false
495          */
setIsMediaSharedWithParent(boolean isMediaSharedWithParent)496         public Builder setIsMediaSharedWithParent(boolean isMediaSharedWithParent) {
497             mIsMediaSharedWithParent = isMediaSharedWithParent;
498             return this;
499         }
500 
getBaseType()501         @UserInfoFlag int getBaseType() {
502             return mBaseType;
503         }
504 
createUserTypeDetails()505         public UserTypeDetails createUserTypeDetails() {
506             Preconditions.checkArgument(mName != null,
507                     "Cannot create a UserTypeDetails with no name.");
508             Preconditions.checkArgument(hasValidBaseType(),
509                     "UserTypeDetails " + mName + " has invalid baseType: " + mBaseType);
510             Preconditions.checkArgument(hasValidPropertyFlags(),
511                     "UserTypeDetails " + mName + " has invalid flags: "
512                             + Integer.toHexString(mDefaultUserInfoPropertyFlags));
513             if (hasBadge()) {
514                 Preconditions.checkArgument(mBadgeLabels != null && mBadgeLabels.length != 0,
515                         "UserTypeDetails " + mName + " has badge but no badgeLabels.");
516                 Preconditions.checkArgument(mBadgeColors != null && mBadgeColors.length != 0,
517                         "UserTypeDetails " + mName + " has badge but no badgeColors.");
518             }
519             if (!isProfile()) {
520                 Preconditions.checkArgument(mDefaultCrossProfileIntentFilters == null
521                                 || mDefaultCrossProfileIntentFilters.isEmpty(),
522                         "UserTypeDetails %s has a non empty "
523                                 + "defaultCrossProfileIntentFilters", mName);
524             }
525             return new UserTypeDetails(mName, mEnabled, mMaxAllowed, mBaseType,
526                     mDefaultUserInfoPropertyFlags, mLabel, mMaxAllowedPerParent,
527                     mIconBadge, mBadgePlain, mBadgeNoBackground, mBadgeLabels, mBadgeColors,
528                     mDarkThemeBadgeColors == null ? mBadgeColors : mDarkThemeBadgeColors,
529                     mDefaultRestrictions, mDefaultSystemSettings, mDefaultSecureSettings,
530                     mDefaultCrossProfileIntentFilters, mIsMediaSharedWithParent);
531         }
532 
hasBadge()533         private boolean hasBadge() {
534             return mIconBadge != Resources.ID_NULL;
535         }
536 
isProfile()537         private boolean isProfile() {
538             return (mBaseType & UserInfo.FLAG_PROFILE) != 0;
539         }
540 
541         // TODO(b/143784345): Refactor this when we clean up UserInfo.
hasValidBaseType()542         private boolean hasValidBaseType() {
543             return mBaseType == UserInfo.FLAG_FULL
544                     || mBaseType == UserInfo.FLAG_PROFILE
545                     || mBaseType == UserInfo.FLAG_SYSTEM
546                     || mBaseType == (UserInfo.FLAG_FULL | UserInfo.FLAG_SYSTEM);
547         }
548 
549         // TODO(b/143784345): Refactor this when we clean up UserInfo.
hasValidPropertyFlags()550         private boolean hasValidPropertyFlags() {
551             final int forbiddenMask =
552                     UserInfo.FLAG_PRIMARY |
553                     UserInfo.FLAG_ADMIN |
554                     UserInfo.FLAG_INITIALIZED |
555                     UserInfo.FLAG_QUIET_MODE |
556                     UserInfo.FLAG_FULL |
557                     UserInfo.FLAG_SYSTEM |
558                     UserInfo.FLAG_PROFILE;
559             return (mDefaultUserInfoPropertyFlags & forbiddenMask) == 0;
560         }
561     }
562 
563     /**
564      * Returns whether the user type is a managed profile
565      * (i.e. {@link UserManager#USER_TYPE_PROFILE_MANAGED}).
566      */
isManagedProfile()567     public boolean isManagedProfile() {
568         return UserManager.isUserTypeManagedProfile(mName);
569     }
570 }
571