• 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.SystemApi;
21 import android.content.pm.PackageManager;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.util.ArrayMap;
25 
26 import com.android.internal.util.DataClass;
27 import com.android.internal.util.Parcelling;
28 
29 import java.util.Map;
30 import java.util.Set;
31 import java.util.UUID;
32 
33 /**
34  * Contains the state of all domains for a given package on device. Used by the domain verification
35  * agent to determine the domains declared by a package that need to be verified by comparing
36  * against the digital asset links response from the server hosting that domain.
37  * <p>
38  * These values for each domain can be modified through
39  * {@link DomainVerificationManager#setDomainVerificationStatus(UUID,
40  * Set, int)}.
41  *
42  * @hide
43  */
44 @SystemApi
45 @DataClass(genAidl = true, genHiddenConstructor = true, genParcelable = true, genToString = true,
46         genEqualsHashCode = true, genHiddenConstDefs = true)
47 public final class DomainVerificationInfo implements Parcelable {
48 
49     // Implementation note: the following states are OUTPUT only. Any value that is synonymous with
50     // a value in DomainVerificationState must be the EXACT same integer, so that state
51     // transformation does not have to occur when sending input into the system, assuming that the
52     // system only accepts those synonymous values. The public API values declared here are only
53     // used when exiting the system server to prepare this data object for consumption by the
54     // verification agent. These constants should only be referenced inside public API classes.
55     // The server must use DomainVerificationState.
56 
57     /**
58      * No response has been recorded by either the system or any verification agent.
59      */
60     public static final int STATE_NO_RESPONSE = DomainVerificationState.STATE_NO_RESPONSE;
61 
62     /**
63      * The domain has been explicitly verified.
64      */
65     public static final int STATE_SUCCESS = DomainVerificationState.STATE_SUCCESS;
66 
67     /**
68      * Indicates the host cannot be modified by the verification agent.
69      */
70     public static final int STATE_UNMODIFIABLE = 2;
71 
72     /**
73      * Indicates the host can be modified by the verification agent and is not considered verified.
74      */
75     public static final int STATE_MODIFIABLE_UNVERIFIED = 3;
76 
77     /**
78      * Indicates the host can be modified by the verification agent and is considered verified.
79      */
80     public static final int STATE_MODIFIABLE_VERIFIED = 4;
81 
82     /**
83      * The first available custom response code. This and any greater integer, along with {@link
84      * #STATE_SUCCESS} are the only values settable by the verification agent. All custom values
85      * will be treated as if the domain is unverified.
86      */
87     public static final int STATE_FIRST_VERIFIER_DEFINED =
88             DomainVerificationState.STATE_FIRST_VERIFIER_DEFINED;
89 
90     /**
91      * A domain verification ID for use in later API calls. This represents the snapshot of the
92      * domains for a package on device, and will be invalidated whenever the package changes.
93      * <p>
94      * An exception will be thrown at the next API call that receives the ID if it is no longer
95      * valid.
96      * <p>
97      * The caller may also be notified with a broadcast whenever a package and ID is invalidated, at
98      * which point it can use the package name to evict existing requests with an invalid set ID. If
99      * the caller wants to manually check if any IDs have been invalidate, the {@link
100      * PackageManager#getChangedPackages(int)} API will allow tracking the packages changed since
101      * the last query of this method, prompting the caller to re-query.
102      * <p>
103      * This allows the caller to arbitrarily grant or revoke domain verification status, through
104      * {@link DomainVerificationManager#setDomainVerificationStatus(UUID, Set, int)}.
105      */
106     @NonNull
107     @DataClass.ParcelWith(Parcelling.BuiltIn.ForUUID.class)
108     private final UUID mIdentifier;
109 
110     /**
111      * The package name that this data corresponds to.
112      */
113     @NonNull
114     private final String mPackageName;
115 
116     /**
117      * Map of host names to their current state. State is an integer, which defaults to {@link
118      * #STATE_NO_RESPONSE}. State can be modified by the domain verification agent (the intended
119      * consumer of this API), which can be equal to {@link #STATE_SUCCESS} when verified, or equal
120      * to or greater than {@link #STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
121      * <p>
122      * Hosts which cannot be edited will be assigned {@link #STATE_UNMODIFIABLE}. It is expected
123      * that the agent attempt to verify all domains that it can modify the state of.
124      */
125     @NonNull
126     private final Map<String, Integer> mHostToStateMap;
127 
parcelHostToStateMap(Parcel dest, @SuppressWarnings("unused") int flags)128     private void parcelHostToStateMap(Parcel dest, @SuppressWarnings("unused") int flags) {
129         DomainVerificationUtils.writeHostMap(dest, mHostToStateMap);
130     }
131 
unparcelHostToStateMap(Parcel in)132     private Map<String, Integer> unparcelHostToStateMap(Parcel in) {
133         return DomainVerificationUtils.readHostMap(in, new ArrayMap<>(),
134                 DomainVerificationUserState.class.getClassLoader());
135     }
136 
137 
138 
139     // Code below generated by codegen v1.0.22.
140     //
141     // DO NOT MODIFY!
142     // CHECKSTYLE:OFF Generated code
143     //
144     // To regenerate run:
145     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/verify/domain/DomainVerificationInfo.java
146     //
147     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
148     //   Settings > Editor > Code Style > Formatter Control
149     //@formatter:off
150 
151 
152     /** @hide */
153     @android.annotation.IntDef(prefix = "STATE_", value = {
154         STATE_NO_RESPONSE,
155         STATE_SUCCESS,
156         STATE_UNMODIFIABLE,
157         STATE_MODIFIABLE_UNVERIFIED,
158         STATE_MODIFIABLE_VERIFIED,
159         STATE_FIRST_VERIFIER_DEFINED
160     })
161     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
162     @DataClass.Generated.Member
163     public @interface State {}
164 
165     /** @hide */
166     @DataClass.Generated.Member
stateToString(@tate int value)167     public static String stateToString(@State int value) {
168         switch (value) {
169             case STATE_NO_RESPONSE:
170                     return "STATE_NO_RESPONSE";
171             case STATE_SUCCESS:
172                     return "STATE_SUCCESS";
173             case STATE_UNMODIFIABLE:
174                     return "STATE_UNMODIFIABLE";
175             case STATE_MODIFIABLE_UNVERIFIED:
176                     return "STATE_MODIFIABLE_UNVERIFIED";
177             case STATE_MODIFIABLE_VERIFIED:
178                     return "STATE_MODIFIABLE_VERIFIED";
179             case STATE_FIRST_VERIFIER_DEFINED:
180                     return "STATE_FIRST_VERIFIER_DEFINED";
181             default: return Integer.toHexString(value);
182         }
183     }
184 
185     /**
186      * Creates a new DomainVerificationInfo.
187      *
188      * @param identifier
189      *   A domain verification ID for use in later API calls. This represents the snapshot of the
190      *   domains for a package on device, and will be invalidated whenever the package changes.
191      *   <p>
192      *   An exception will be thrown at the next API call that receives the ID if it is no longer
193      *   valid.
194      *   <p>
195      *   The caller may also be notified with a broadcast whenever a package and ID is invalidated, at
196      *   which point it can use the package name to evict existing requests with an invalid set ID. If
197      *   the caller wants to manually check if any IDs have been invalidate, the {@link
198      *   PackageManager#getChangedPackages(int)} API will allow tracking the packages changed since
199      *   the last query of this method, prompting the caller to re-query.
200      *   <p>
201      *   This allows the caller to arbitrarily grant or revoke domain verification status, through
202      *   {@link DomainVerificationManager#setDomainVerificationStatus(UUID, Set, int)}.
203      * @param packageName
204      *   The package name that this data corresponds to.
205      * @param hostToStateMap
206      *   Map of host names to their current state. State is an integer, which defaults to {@link
207      *   #STATE_NO_RESPONSE}. State can be modified by the domain verification agent (the intended
208      *   consumer of this API), which can be equal to {@link #STATE_SUCCESS} when verified, or equal
209      *   to or greater than {@link #STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
210      *   <p>
211      *   Hosts which cannot be edited will be assigned {@link #STATE_UNMODIFIABLE}. It is expected
212      *   that the agent attempt to verify all domains that it can modify the state of.
213      * @hide
214      */
215     @DataClass.Generated.Member
DomainVerificationInfo( @onNull UUID identifier, @NonNull String packageName, @NonNull Map<String,Integer> hostToStateMap)216     public DomainVerificationInfo(
217             @NonNull UUID identifier,
218             @NonNull String packageName,
219             @NonNull Map<String,Integer> hostToStateMap) {
220         this.mIdentifier = identifier;
221         com.android.internal.util.AnnotationValidations.validate(
222                 NonNull.class, null, mIdentifier);
223         this.mPackageName = packageName;
224         com.android.internal.util.AnnotationValidations.validate(
225                 NonNull.class, null, mPackageName);
226         this.mHostToStateMap = hostToStateMap;
227         com.android.internal.util.AnnotationValidations.validate(
228                 NonNull.class, null, mHostToStateMap);
229 
230         // onConstructed(); // You can define this method to get a callback
231     }
232 
233     /**
234      * A domain verification ID for use in later API calls. This represents the snapshot of the
235      * domains for a package on device, and will be invalidated whenever the package changes.
236      * <p>
237      * An exception will be thrown at the next API call that receives the ID if it is no longer
238      * valid.
239      * <p>
240      * The caller may also be notified with a broadcast whenever a package and ID is invalidated, at
241      * which point it can use the package name to evict existing requests with an invalid set ID. If
242      * the caller wants to manually check if any IDs have been invalidate, the {@link
243      * PackageManager#getChangedPackages(int)} API will allow tracking the packages changed since
244      * the last query of this method, prompting the caller to re-query.
245      * <p>
246      * This allows the caller to arbitrarily grant or revoke domain verification status, through
247      * {@link DomainVerificationManager#setDomainVerificationStatus(UUID, Set, int)}.
248      */
249     @DataClass.Generated.Member
getIdentifier()250     public @NonNull UUID getIdentifier() {
251         return mIdentifier;
252     }
253 
254     /**
255      * The package name that this data corresponds to.
256      */
257     @DataClass.Generated.Member
getPackageName()258     public @NonNull String getPackageName() {
259         return mPackageName;
260     }
261 
262     /**
263      * Map of host names to their current state. State is an integer, which defaults to {@link
264      * #STATE_NO_RESPONSE}. State can be modified by the domain verification agent (the intended
265      * consumer of this API), which can be equal to {@link #STATE_SUCCESS} when verified, or equal
266      * to or greater than {@link #STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
267      * <p>
268      * Hosts which cannot be edited will be assigned {@link #STATE_UNMODIFIABLE}. It is expected
269      * that the agent attempt to verify all domains that it can modify the state of.
270      */
271     @DataClass.Generated.Member
getHostToStateMap()272     public @NonNull Map<String,Integer> getHostToStateMap() {
273         return mHostToStateMap;
274     }
275 
276     @Override
277     @DataClass.Generated.Member
toString()278     public String toString() {
279         // You can override field toString logic by defining methods like:
280         // String fieldNameToString() { ... }
281 
282         return "DomainVerificationInfo { " +
283                 "identifier = " + mIdentifier + ", " +
284                 "packageName = " + mPackageName + ", " +
285                 "hostToStateMap = " + mHostToStateMap +
286         " }";
287     }
288 
289     @Override
290     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)291     public boolean equals(@android.annotation.Nullable Object o) {
292         // You can override field equality logic by defining either of the methods like:
293         // boolean fieldNameEquals(DomainVerificationInfo other) { ... }
294         // boolean fieldNameEquals(FieldType otherValue) { ... }
295 
296         if (this == o) return true;
297         if (o == null || getClass() != o.getClass()) return false;
298         @SuppressWarnings("unchecked")
299         DomainVerificationInfo that = (DomainVerificationInfo) o;
300         //noinspection PointlessBooleanExpression
301         return true
302                 && java.util.Objects.equals(mIdentifier, that.mIdentifier)
303                 && java.util.Objects.equals(mPackageName, that.mPackageName)
304                 && java.util.Objects.equals(mHostToStateMap, that.mHostToStateMap);
305     }
306 
307     @Override
308     @DataClass.Generated.Member
hashCode()309     public int hashCode() {
310         // You can override field hashCode logic by defining methods like:
311         // int fieldNameHashCode() { ... }
312 
313         int _hash = 1;
314         _hash = 31 * _hash + java.util.Objects.hashCode(mIdentifier);
315         _hash = 31 * _hash + java.util.Objects.hashCode(mPackageName);
316         _hash = 31 * _hash + java.util.Objects.hashCode(mHostToStateMap);
317         return _hash;
318     }
319 
320     @DataClass.Generated.Member
321     static Parcelling<UUID> sParcellingForIdentifier =
322             Parcelling.Cache.get(
323                     Parcelling.BuiltIn.ForUUID.class);
324     static {
325         if (sParcellingForIdentifier == null) {
326             sParcellingForIdentifier = Parcelling.Cache.put(
327                     new Parcelling.BuiltIn.ForUUID());
328         }
329     }
330 
331     @Override
332     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)333     public void writeToParcel(@NonNull Parcel dest, int flags) {
334         // You can override field parcelling by defining methods like:
335         // void parcelFieldName(Parcel dest, int flags) { ... }
336 
337         sParcellingForIdentifier.parcel(mIdentifier, dest, flags);
338         dest.writeString(mPackageName);
339         parcelHostToStateMap(dest, flags);
340     }
341 
342     @Override
343     @DataClass.Generated.Member
describeContents()344     public int describeContents() { return 0; }
345 
346     /** @hide */
347     @SuppressWarnings({"unchecked", "RedundantCast"})
348     @DataClass.Generated.Member
DomainVerificationInfo(@onNull Parcel in)349     /* package-private */ DomainVerificationInfo(@NonNull Parcel in) {
350         // You can override field unparcelling by defining methods like:
351         // static FieldType unparcelFieldName(Parcel in) { ... }
352 
353         UUID identifier = sParcellingForIdentifier.unparcel(in);
354         String packageName = in.readString();
355         Map<String,Integer> hostToStateMap = unparcelHostToStateMap(in);
356 
357         this.mIdentifier = identifier;
358         com.android.internal.util.AnnotationValidations.validate(
359                 NonNull.class, null, mIdentifier);
360         this.mPackageName = packageName;
361         com.android.internal.util.AnnotationValidations.validate(
362                 NonNull.class, null, mPackageName);
363         this.mHostToStateMap = hostToStateMap;
364         com.android.internal.util.AnnotationValidations.validate(
365                 NonNull.class, null, mHostToStateMap);
366 
367         // onConstructed(); // You can define this method to get a callback
368     }
369 
370     @DataClass.Generated.Member
371     public static final @NonNull Parcelable.Creator<DomainVerificationInfo> CREATOR
372             = new Parcelable.Creator<DomainVerificationInfo>() {
373         @Override
374         public DomainVerificationInfo[] newArray(int size) {
375             return new DomainVerificationInfo[size];
376         }
377 
378         @Override
379         public DomainVerificationInfo createFromParcel(@NonNull Parcel in) {
380             return new DomainVerificationInfo(in);
381         }
382     };
383 
384     @DataClass.Generated(
385             time = 1615317187669L,
386             codegenVersion = "1.0.22",
387             sourceFile = "frameworks/base/core/java/android/content/pm/verify/domain/DomainVerificationInfo.java",
388             inputSignatures = "public static final  int STATE_NO_RESPONSE\npublic static final  int STATE_SUCCESS\npublic static final  int STATE_UNMODIFIABLE\npublic static final  int STATE_MODIFIABLE_UNVERIFIED\npublic static final  int STATE_MODIFIABLE_VERIFIED\npublic static final  int STATE_FIRST_VERIFIER_DEFINED\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 java.util.Map<java.lang.String,java.lang.Integer> mHostToStateMap\nprivate  void parcelHostToStateMap(android.os.Parcel,int)\nprivate  java.util.Map<java.lang.String,java.lang.Integer> unparcelHostToStateMap(android.os.Parcel)\nclass DomainVerificationInfo 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)")
389     @Deprecated
__metadata()390     private void __metadata() {}
391 
392 
393     //@formatter:on
394     // End of generated code
395 
396 }
397