1 /* 2 * Copyright (C) 2020 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.verify.domain.models; 18 19 import android.annotation.NonNull; 20 import android.annotation.UserIdInt; 21 import android.util.ArraySet; 22 23 import com.android.internal.util.DataClass; 24 25 import java.util.Set; 26 27 /** 28 * Tracks which domains have been explicitly enabled by the user, allowing it to open that domain 29 * when a web URL Intent is sent and the application is the highest priority for that domain. 30 */ 31 @DataClass(genSetters = true, genEqualsHashCode = true, genToString = true, genBuilder = false) 32 public class DomainVerificationInternalUserState { 33 34 @UserIdInt 35 private final int mUserId; 36 37 /** List of domains which have been enabled by the user. **/ 38 @NonNull 39 private final ArraySet<String> mEnabledHosts; 40 41 /** 42 * Whether to allow this package to automatically open links by auto verification. 43 */ 44 private boolean mLinkHandlingAllowed = true; 45 DomainVerificationInternalUserState(@serIdInt int userId)46 public DomainVerificationInternalUserState(@UserIdInt int userId) { 47 mUserId = userId; 48 mEnabledHosts = new ArraySet<>(); 49 } 50 addHosts(@onNull ArraySet<String> newHosts)51 public DomainVerificationInternalUserState addHosts(@NonNull ArraySet<String> newHosts) { 52 mEnabledHosts.addAll(newHosts); 53 return this; 54 } 55 addHosts(@onNull Set<String> newHosts)56 public DomainVerificationInternalUserState addHosts(@NonNull Set<String> newHosts) { 57 mEnabledHosts.addAll(newHosts); 58 return this; 59 } 60 removeHost(String host)61 public DomainVerificationInternalUserState removeHost(String host) { 62 mEnabledHosts.remove(host); 63 return this; 64 } 65 removeHosts(@onNull ArraySet<String> newHosts)66 public DomainVerificationInternalUserState removeHosts(@NonNull ArraySet<String> newHosts) { 67 mEnabledHosts.removeAll(newHosts); 68 return this; 69 } 70 removeHosts(@onNull Set<String> newHosts)71 public DomainVerificationInternalUserState removeHosts(@NonNull Set<String> newHosts) { 72 mEnabledHosts.removeAll(newHosts); 73 return this; 74 } 75 retainHosts(@onNull Set<String> hosts)76 public DomainVerificationInternalUserState retainHosts(@NonNull Set<String> hosts) { 77 mEnabledHosts.retainAll(hosts); 78 return this; 79 } 80 81 82 83 // Code below generated by codegen v1.0.22. 84 // 85 // DO NOT MODIFY! 86 // CHECKSTYLE:OFF Generated code 87 // 88 // To regenerate run: 89 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationInternalUserState.java 90 // 91 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 92 // Settings > Editor > Code Style > Formatter Control 93 //@formatter:off 94 95 96 /** 97 * Creates a new DomainVerificationInternalUserState. 98 * 99 * @param enabledHosts 100 * List of domains which have been enabled by the user. * 101 * @param linkHandlingAllowed 102 * Whether to allow this package to automatically open links by auto verification. 103 */ 104 @DataClass.Generated.Member DomainVerificationInternalUserState( @serIdInt int userId, @NonNull ArraySet<String> enabledHosts, boolean linkHandlingAllowed)105 public DomainVerificationInternalUserState( 106 @UserIdInt int userId, 107 @NonNull ArraySet<String> enabledHosts, 108 boolean linkHandlingAllowed) { 109 this.mUserId = userId; 110 com.android.internal.util.AnnotationValidations.validate( 111 UserIdInt.class, null, mUserId); 112 this.mEnabledHosts = enabledHosts; 113 com.android.internal.util.AnnotationValidations.validate( 114 NonNull.class, null, mEnabledHosts); 115 this.mLinkHandlingAllowed = linkHandlingAllowed; 116 117 // onConstructed(); // You can define this method to get a callback 118 } 119 120 @DataClass.Generated.Member getUserId()121 public @UserIdInt int getUserId() { 122 return mUserId; 123 } 124 125 /** 126 * List of domains which have been enabled by the user. * 127 */ 128 @DataClass.Generated.Member getEnabledHosts()129 public @NonNull ArraySet<String> getEnabledHosts() { 130 return mEnabledHosts; 131 } 132 133 /** 134 * Whether to allow this package to automatically open links by auto verification. 135 */ 136 @DataClass.Generated.Member isLinkHandlingAllowed()137 public boolean isLinkHandlingAllowed() { 138 return mLinkHandlingAllowed; 139 } 140 141 /** 142 * Whether to allow this package to automatically open links by auto verification. 143 */ 144 @DataClass.Generated.Member setLinkHandlingAllowed( boolean value)145 public @NonNull DomainVerificationInternalUserState setLinkHandlingAllowed( boolean value) { 146 mLinkHandlingAllowed = value; 147 return this; 148 } 149 150 @Override 151 @DataClass.Generated.Member toString()152 public String toString() { 153 // You can override field toString logic by defining methods like: 154 // String fieldNameToString() { ... } 155 156 return "DomainVerificationInternalUserState { " + 157 "userId = " + mUserId + ", " + 158 "enabledHosts = " + mEnabledHosts + ", " + 159 "linkHandlingAllowed = " + mLinkHandlingAllowed + 160 " }"; 161 } 162 163 @Override 164 @DataClass.Generated.Member equals(@ndroid.annotation.Nullable Object o)165 public boolean equals(@android.annotation.Nullable Object o) { 166 // You can override field equality logic by defining either of the methods like: 167 // boolean fieldNameEquals(DomainVerificationInternalUserState other) { ... } 168 // boolean fieldNameEquals(FieldType otherValue) { ... } 169 170 if (this == o) return true; 171 if (o == null || getClass() != o.getClass()) return false; 172 @SuppressWarnings("unchecked") 173 DomainVerificationInternalUserState that = (DomainVerificationInternalUserState) o; 174 //noinspection PointlessBooleanExpression 175 return true 176 && mUserId == that.mUserId 177 && java.util.Objects.equals(mEnabledHosts, that.mEnabledHosts) 178 && mLinkHandlingAllowed == that.mLinkHandlingAllowed; 179 } 180 181 @Override 182 @DataClass.Generated.Member hashCode()183 public int hashCode() { 184 // You can override field hashCode logic by defining methods like: 185 // int fieldNameHashCode() { ... } 186 187 int _hash = 1; 188 _hash = 31 * _hash + mUserId; 189 _hash = 31 * _hash + java.util.Objects.hashCode(mEnabledHosts); 190 _hash = 31 * _hash + Boolean.hashCode(mLinkHandlingAllowed); 191 return _hash; 192 } 193 194 @DataClass.Generated( 195 time = 1614714563905L, 196 codegenVersion = "1.0.22", 197 sourceFile = "frameworks/base/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationInternalUserState.java", 198 inputSignatures = "private final @android.annotation.UserIdInt int mUserId\nprivate final @android.annotation.NonNull android.util.ArraySet<java.lang.String> mEnabledHosts\nprivate boolean mLinkHandlingAllowed\npublic com.android.server.pm.verify.domain.models.DomainVerificationInternalUserState addHosts(android.util.ArraySet<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationInternalUserState addHosts(java.util.Set<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationInternalUserState removeHost(java.lang.String)\npublic com.android.server.pm.verify.domain.models.DomainVerificationInternalUserState removeHosts(android.util.ArraySet<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationInternalUserState removeHosts(java.util.Set<java.lang.String>)\nclass DomainVerificationInternalUserState extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genSetters=true, genEqualsHashCode=true, genToString=true, genBuilder=false)") 199 @Deprecated __metadata()200 private void __metadata() {} 201 202 203 //@formatter:on 204 // End of generated code 205 206 } 207