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