1 /*
2  * Copyright (C) 2023 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.credentials;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import android.annotation.NonNull;
22 import android.content.ComponentName;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import com.android.internal.util.AnnotationValidations;
27 
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Set;
33 
34 
35 /**
36  * A request to register a {@link ComponentName} that contains an actively provisioned
37  * {@link Credential} represented by a {@link CredentialDescription}.
38  *
39  */
40 public final class RegisterCredentialDescriptionRequest implements Parcelable {
41 
42     @NonNull
43     private final List<CredentialDescription> mCredentialDescriptions;
44 
RegisterCredentialDescriptionRequest( @onNull CredentialDescription credentialDescription)45     public RegisterCredentialDescriptionRequest(
46             @NonNull CredentialDescription credentialDescription) {
47         mCredentialDescriptions = Arrays.asList(requireNonNull(credentialDescription));
48     }
49 
RegisterCredentialDescriptionRequest( @onNull Set<CredentialDescription> credentialDescriptions)50     public RegisterCredentialDescriptionRequest(
51             @NonNull Set<CredentialDescription> credentialDescriptions) {
52         mCredentialDescriptions = new ArrayList<>(requireNonNull(credentialDescriptions));
53     }
54 
RegisterCredentialDescriptionRequest(@onNull Parcel in)55     private RegisterCredentialDescriptionRequest(@NonNull Parcel in) {
56         List<CredentialDescription> credentialDescriptions = new ArrayList<>();
57         in.readTypedList(credentialDescriptions, CredentialDescription.CREATOR);
58 
59         mCredentialDescriptions = new ArrayList<>();
60         AnnotationValidations.validate(android.annotation.NonNull.class, null,
61                 credentialDescriptions);
62         mCredentialDescriptions.addAll(credentialDescriptions);
63     }
64 
65     public static final @NonNull Parcelable.Creator<RegisterCredentialDescriptionRequest> CREATOR =
66             new Parcelable.Creator<RegisterCredentialDescriptionRequest>() {
67                 @Override
68                 public RegisterCredentialDescriptionRequest createFromParcel(Parcel in) {
69                     return new RegisterCredentialDescriptionRequest(in);
70                 }
71 
72                 @Override
73                 public RegisterCredentialDescriptionRequest[] newArray(int size) {
74                     return new RegisterCredentialDescriptionRequest[size];
75                 }
76             };
77 
78     @Override
describeContents()79     public int describeContents() {
80         return 0;
81     }
82 
83     @Override
writeToParcel(@onNull Parcel dest, int flags)84     public void writeToParcel(@NonNull Parcel dest, int flags) {
85         dest.writeTypedList(mCredentialDescriptions, flags);
86     }
87 
88     @NonNull
getCredentialDescriptions()89     public Set<CredentialDescription> getCredentialDescriptions() {
90         return new HashSet<>(mCredentialDescriptions);
91     }
92 }
93