• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.bedstead.nene.users;
18 
19 import java.util.Set;
20 
21 /**
22  * Represents information about an Android User type.
23  */
24 public final class UserType {
25 
26     public static final String SECONDARY_USER_TYPE_NAME = "android.os.usertype.full.SECONDARY";
27     public static final String SYSTEM_USER_TYPE_NAME = "android.os.usertype.full.SYSTEM";
28     public static final String MANAGED_PROFILE_TYPE_NAME = "android.os.usertype.profile.MANAGED";
29     public static final String CLONE_PROFILE_TYPE_NAME = "android.os.usertype.profile.CLONE";
30     public static final String USER_TYPE_FULL_GUEST = "android.os.usertype.full.GUEST";
31 
32     public static final int UNLIMITED = -1;
33 
34     /** Default base types. */
35     public static final class BaseType {
36         public static final String SYSTEM = "SYSTEM";
37         public static final String PROFILE = "PROFILE";
38         public static final String FULL = "FULL";
39     }
40 
41     static final class MutableUserType {
42         String mName;
43         Set<String> mBaseType;
44         Boolean mEnabled;
45         Integer mMaxAllowed;
46         Integer mMaxAllowedPerParent;
47     }
48 
49     private final MutableUserType mMutableUserType;
50 
UserType(MutableUserType mutableUserType)51     UserType(MutableUserType mutableUserType) {
52         mMutableUserType = mutableUserType;
53     }
54 
name()55     public String name() {
56         return mMutableUserType.mName;
57     }
58 
59     /** Get the base type(s) of this type. */
baseType()60     public Set<String> baseType() {
61         return mMutableUserType.mBaseType;
62     }
63 
enabled()64     public Boolean enabled() {
65         return mMutableUserType.mEnabled;
66     }
67 
68     /**
69      * The maximum number of this user type allowed on the device.
70      *
71      * <p>This value will be {@link #UNLIMITED} if there is no limit.
72      */
maxAllowed()73     public Integer maxAllowed() {
74         return mMutableUserType.mMaxAllowed;
75     }
76 
77     /**
78      * The maximum number of this user type allowed for a single parent profile
79      *
80      * <p>This value will be {@link #UNLIMITED} if there is no limit.
81      */
maxAllowedPerParent()82     public Integer maxAllowedPerParent() {
83         return mMutableUserType.mMaxAllowedPerParent;
84     }
85 
86     @Override
toString()87     public String toString() {
88         StringBuilder stringBuilder = new StringBuilder("UserType{");
89         stringBuilder.append("name=" + mMutableUserType.mName);
90         stringBuilder.append(", baseType=" + mMutableUserType.mBaseType);
91         stringBuilder.append(", enabled=" + mMutableUserType.mEnabled);
92         stringBuilder.append(", maxAllowed=" + mMutableUserType.mMaxAllowed);
93         stringBuilder.append(", maxAllowedPerParent=" + mMutableUserType.mMaxAllowedPerParent);
94         return stringBuilder.toString();
95     }
96 
97     @Override
hashCode()98     public int hashCode() {
99         return name().hashCode();
100     }
101 
102     @Override
equals(Object obj)103     public boolean equals(Object obj) {
104         if (obj == null || !(obj instanceof UserType)) {
105             return false;
106         }
107 
108         UserType other = (UserType) obj;
109         return other.name().equals(name());
110     }
111 }
112