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