• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.pm.verify.domain;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.os.UserHandle;
27 import android.util.ArrayMap;
28 
29 import com.android.internal.util.DataClass;
30 import com.android.internal.util.Parcelling;
31 
32 import java.util.Map;
33 import java.util.UUID;
34 
35 /**
36  * Contains the user selection state for a package. This means all web HTTP(S) domains declared by a
37  * package in its manifest, whether or not they were marked for auto verification.
38  * <p>
39  * Applications should use {@link #getHostToStateMap()} if necessary to
40  * check if/how they are verified for a domain, which is required starting from platform
41  * {@link android.os.Build.VERSION_CODES#S} in order to open {@link Intent}s which declare
42  * {@link Intent#CATEGORY_BROWSABLE} or no category and also match against
43  * {@link Intent#CATEGORY_DEFAULT} {@link android.content.IntentFilter}s, either through an
44  * explicit declaration of {@link Intent#CATEGORY_DEFAULT} or through the use of
45  * {@link android.content.pm.PackageManager#MATCH_DEFAULT_ONLY}, which is usually added for the
46  * caller when using {@link Context#startActivity(Intent)} and similar.
47  * <p>
48  * By default, all apps are allowed to automatically open links for the above case for domains that
49  * they've successfully verified against. This is reflected by {@link #isLinkHandlingAllowed()}.
50  * The user can decide to disable this, disallowing the application from opening all links. Note
51  * that the toggle affects <b>all</b> links and is not based on the verification state of the
52  * domains.
53  * <p>
54  * Assuming the toggle is enabled, the user can also select additional unverified domains to grant
55  * to the application to open, which is reflected in {@link #getHostToStateMap()}. But only a single
56  * application can be approved for a domain unless the applications are both approved. If another
57  * application is approved, the user will not be allowed to enable the domain.
58  */
59 @SuppressWarnings("DefaultAnnotationParam")
60 @DataClass(genAidl = true, genHiddenConstructor = true, genParcelable = true, genToString = true,
61         genEqualsHashCode = true, genHiddenConstDefs = true)
62 public final class DomainVerificationUserState implements Parcelable {
63 
64     /**
65      * The domain is unverified and unselected, and the application is unable to open web links
66      * that resolve to the domain.
67      */
68     public static final int DOMAIN_STATE_NONE = 0;
69 
70     /**
71      * The domain has been selected by the user. This may be reset to {@link #DOMAIN_STATE_NONE} if
72      * another application is selected or verified for the same domain.
73      */
74     public static final int DOMAIN_STATE_SELECTED = 1;
75 
76     /**
77      * The domain has been previously verified by the domain verification agent.
78      */
79     public static final int DOMAIN_STATE_VERIFIED = 2;
80 
81     /**
82      * @see DomainVerificationInfo#getIdentifier
83      */
84     @NonNull
85     @DataClass.ParcelWith(Parcelling.BuiltIn.ForUUID.class)
86     private final UUID mIdentifier;
87 
88     /**
89      * The package name that this data corresponds to.
90      */
91     @NonNull
92     private final String mPackageName;
93 
94     /**
95      * The user that this data corresponds to.
96      */
97     @NonNull
98     private final UserHandle mUser;
99 
100     /**
101      * Whether or not this package is allowed to open links.
102      */
103     @NonNull
104     private final boolean mLinkHandlingAllowed;
105 
106     /**
107      * Mapping of domain host to state, as defined by {@link DomainState}.
108      */
109     @NonNull
110     private final Map<String, Integer> mHostToStateMap;
111 
parcelHostToStateMap(Parcel dest, @SuppressWarnings("unused") int flags)112     private void parcelHostToStateMap(Parcel dest, @SuppressWarnings("unused") int flags) {
113         DomainVerificationUtils.writeHostMap(dest, mHostToStateMap);
114     }
115 
116     @NonNull
unparcelHostToStateMap(Parcel in)117     private Map<String, Integer> unparcelHostToStateMap(Parcel in) {
118         return DomainVerificationUtils.readHostMap(in, new ArrayMap<>(),
119                 DomainVerificationUserState.class.getClassLoader());
120     }
121 
122     /**
123      * @see DomainVerificationInfo#getIdentifier
124      * @hide
125      */
126     @SystemApi
getIdentifier()127     public @NonNull UUID getIdentifier() {
128         return mIdentifier;
129     }
130 
131 
132 
133     // Code below generated by codegen v1.0.22.
134     //
135     // DO NOT MODIFY!
136     // CHECKSTYLE:OFF Generated code
137     //
138     // To regenerate run:
139     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/verify/domain/DomainVerificationUserState.java
140     //
141     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
142     //   Settings > Editor > Code Style > Formatter Control
143     //@formatter:off
144 
145 
146     /** @hide */
147     @android.annotation.IntDef(prefix = "DOMAIN_STATE_", value = {
148         DOMAIN_STATE_NONE,
149         DOMAIN_STATE_SELECTED,
150         DOMAIN_STATE_VERIFIED
151     })
152     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
153     @DataClass.Generated.Member
154     public @interface DomainState {}
155 
156     /** @hide */
157     @DataClass.Generated.Member
domainStateToString(@omainState int value)158     public static String domainStateToString(@DomainState int value) {
159         switch (value) {
160             case DOMAIN_STATE_NONE:
161                     return "DOMAIN_STATE_NONE";
162             case DOMAIN_STATE_SELECTED:
163                     return "DOMAIN_STATE_SELECTED";
164             case DOMAIN_STATE_VERIFIED:
165                     return "DOMAIN_STATE_VERIFIED";
166             default: return Integer.toHexString(value);
167         }
168     }
169 
170     /**
171      * Creates a new DomainVerificationUserState.
172      *
173      * @param packageName
174      *   The package name that this data corresponds to.
175      * @param user
176      *   The user that this data corresponds to.
177      * @param linkHandlingAllowed
178      *   Whether or not this package is allowed to open links.
179      * @param hostToStateMap
180      *   Mapping of domain host to state, as defined by {@link DomainState}.
181      * @hide
182      */
183     @DataClass.Generated.Member
DomainVerificationUserState( @onNull UUID identifier, @NonNull String packageName, @NonNull UserHandle user, @NonNull boolean linkHandlingAllowed, @NonNull Map<String,Integer> hostToStateMap)184     public DomainVerificationUserState(
185             @NonNull UUID identifier,
186             @NonNull String packageName,
187             @NonNull UserHandle user,
188             @NonNull boolean linkHandlingAllowed,
189             @NonNull Map<String,Integer> hostToStateMap) {
190         this.mIdentifier = identifier;
191         com.android.internal.util.AnnotationValidations.validate(
192                 NonNull.class, null, mIdentifier);
193         this.mPackageName = packageName;
194         com.android.internal.util.AnnotationValidations.validate(
195                 NonNull.class, null, mPackageName);
196         this.mUser = user;
197         com.android.internal.util.AnnotationValidations.validate(
198                 NonNull.class, null, mUser);
199         this.mLinkHandlingAllowed = linkHandlingAllowed;
200         com.android.internal.util.AnnotationValidations.validate(
201                 NonNull.class, null, mLinkHandlingAllowed);
202         this.mHostToStateMap = hostToStateMap;
203         com.android.internal.util.AnnotationValidations.validate(
204                 NonNull.class, null, mHostToStateMap);
205 
206         // onConstructed(); // You can define this method to get a callback
207     }
208 
209     /**
210      * The package name that this data corresponds to.
211      */
212     @DataClass.Generated.Member
getPackageName()213     public @NonNull String getPackageName() {
214         return mPackageName;
215     }
216 
217     /**
218      * The user that this data corresponds to.
219      */
220     @DataClass.Generated.Member
getUser()221     public @NonNull UserHandle getUser() {
222         return mUser;
223     }
224 
225     /**
226      * Whether or not this package is allowed to open links.
227      */
228     @DataClass.Generated.Member
isLinkHandlingAllowed()229     public @NonNull boolean isLinkHandlingAllowed() {
230         return mLinkHandlingAllowed;
231     }
232 
233     /**
234      * Mapping of domain host to state, as defined by {@link DomainState}.
235      */
236     @DataClass.Generated.Member
getHostToStateMap()237     public @NonNull Map<String,Integer> getHostToStateMap() {
238         return mHostToStateMap;
239     }
240 
241     @Override
242     @DataClass.Generated.Member
toString()243     public String toString() {
244         // You can override field toString logic by defining methods like:
245         // String fieldNameToString() { ... }
246 
247         return "DomainVerificationUserState { " +
248                 "identifier = " + mIdentifier + ", " +
249                 "packageName = " + mPackageName + ", " +
250                 "user = " + mUser + ", " +
251                 "linkHandlingAllowed = " + mLinkHandlingAllowed + ", " +
252                 "hostToStateMap = " + mHostToStateMap +
253         " }";
254     }
255 
256     @Override
257     @DataClass.Generated.Member
equals(@ullable Object o)258     public boolean equals(@Nullable Object o) {
259         // You can override field equality logic by defining either of the methods like:
260         // boolean fieldNameEquals(DomainVerificationUserState other) { ... }
261         // boolean fieldNameEquals(FieldType otherValue) { ... }
262 
263         if (this == o) return true;
264         if (o == null || getClass() != o.getClass()) return false;
265         @SuppressWarnings("unchecked")
266         DomainVerificationUserState that = (DomainVerificationUserState) o;
267         //noinspection PointlessBooleanExpression
268         return true
269                 && java.util.Objects.equals(mIdentifier, that.mIdentifier)
270                 && java.util.Objects.equals(mPackageName, that.mPackageName)
271                 && java.util.Objects.equals(mUser, that.mUser)
272                 && mLinkHandlingAllowed == that.mLinkHandlingAllowed
273                 && java.util.Objects.equals(mHostToStateMap, that.mHostToStateMap);
274     }
275 
276     @Override
277     @DataClass.Generated.Member
hashCode()278     public int hashCode() {
279         // You can override field hashCode logic by defining methods like:
280         // int fieldNameHashCode() { ... }
281 
282         int _hash = 1;
283         _hash = 31 * _hash + java.util.Objects.hashCode(mIdentifier);
284         _hash = 31 * _hash + java.util.Objects.hashCode(mPackageName);
285         _hash = 31 * _hash + java.util.Objects.hashCode(mUser);
286         _hash = 31 * _hash + Boolean.hashCode(mLinkHandlingAllowed);
287         _hash = 31 * _hash + java.util.Objects.hashCode(mHostToStateMap);
288         return _hash;
289     }
290 
291     @DataClass.Generated.Member
292     static Parcelling<UUID> sParcellingForIdentifier =
293             Parcelling.Cache.get(
294                     Parcelling.BuiltIn.ForUUID.class);
295     static {
296         if (sParcellingForIdentifier == null) {
297             sParcellingForIdentifier = Parcelling.Cache.put(
298                     new Parcelling.BuiltIn.ForUUID());
299         }
300     }
301 
302     @Override
303     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)304     public void writeToParcel(@NonNull Parcel dest, int flags) {
305         // You can override field parcelling by defining methods like:
306         // void parcelFieldName(Parcel dest, int flags) { ... }
307 
308         byte flg = 0;
309         if (mLinkHandlingAllowed) flg |= 0x8;
310         dest.writeByte(flg);
311         sParcellingForIdentifier.parcel(mIdentifier, dest, flags);
312         dest.writeString(mPackageName);
313         dest.writeTypedObject(mUser, flags);
314         parcelHostToStateMap(dest, flags);
315     }
316 
317     @Override
318     @DataClass.Generated.Member
describeContents()319     public int describeContents() { return 0; }
320 
321     /** @hide */
322     @SuppressWarnings({"unchecked", "RedundantCast"})
323     @DataClass.Generated.Member
DomainVerificationUserState(@onNull Parcel in)324     /* package-private */ DomainVerificationUserState(@NonNull Parcel in) {
325         // You can override field unparcelling by defining methods like:
326         // static FieldType unparcelFieldName(Parcel in) { ... }
327 
328         byte flg = in.readByte();
329         boolean linkHandlingAllowed = (flg & 0x8) != 0;
330         UUID identifier = sParcellingForIdentifier.unparcel(in);
331         String packageName = in.readString();
332         UserHandle user = (UserHandle) in.readTypedObject(UserHandle.CREATOR);
333         Map<String,Integer> hostToStateMap = unparcelHostToStateMap(in);
334 
335         this.mIdentifier = identifier;
336         com.android.internal.util.AnnotationValidations.validate(
337                 NonNull.class, null, mIdentifier);
338         this.mPackageName = packageName;
339         com.android.internal.util.AnnotationValidations.validate(
340                 NonNull.class, null, mPackageName);
341         this.mUser = user;
342         com.android.internal.util.AnnotationValidations.validate(
343                 NonNull.class, null, mUser);
344         this.mLinkHandlingAllowed = linkHandlingAllowed;
345         com.android.internal.util.AnnotationValidations.validate(
346                 NonNull.class, null, mLinkHandlingAllowed);
347         this.mHostToStateMap = hostToStateMap;
348         com.android.internal.util.AnnotationValidations.validate(
349                 NonNull.class, null, mHostToStateMap);
350 
351         // onConstructed(); // You can define this method to get a callback
352     }
353 
354     @DataClass.Generated.Member
355     public static final @NonNull Parcelable.Creator<DomainVerificationUserState> CREATOR
356             = new Parcelable.Creator<DomainVerificationUserState>() {
357         @Override
358         public DomainVerificationUserState[] newArray(int size) {
359             return new DomainVerificationUserState[size];
360         }
361 
362         @Override
363         public DomainVerificationUserState createFromParcel(@NonNull Parcel in) {
364             return new DomainVerificationUserState(in);
365         }
366     };
367 
368     @DataClass.Generated(
369             time = 1614721840152L,
370             codegenVersion = "1.0.22",
371             sourceFile = "frameworks/base/core/java/android/content/pm/verify/domain/DomainVerificationUserState.java",
372             inputSignatures = "public static final  int DOMAIN_STATE_NONE\npublic static final  int DOMAIN_STATE_SELECTED\npublic static final  int DOMAIN_STATE_VERIFIED\nprivate final @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForUUID.class) java.util.UUID mIdentifier\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull android.os.UserHandle mUser\nprivate final @android.annotation.NonNull boolean mLinkHandlingAllowed\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.Integer> mHostToStateMap\nprivate  void parcelHostToStateMap(android.os.Parcel,int)\nprivate @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.Integer> unparcelHostToStateMap(android.os.Parcel)\npublic @android.annotation.SystemApi @android.annotation.NonNull java.util.UUID getIdentifier()\nclass DomainVerificationUserState extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=true, genHiddenConstructor=true, genParcelable=true, genToString=true, genEqualsHashCode=true, genHiddenConstDefs=true)")
373     @Deprecated
__metadata()374     private void __metadata() {}
375 
376 
377     //@formatter:on
378     // End of generated code
379 
380 }
381