1 /*
2  * Copyright (C) 2022 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.service.credentials;
18 
19 import android.annotation.NonNull;
20 import android.os.Bundle;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import com.android.internal.util.Preconditions;
25 
26 import java.util.Objects;
27 
28 /**
29  * Request for creating a credential.
30  */
31 public final class CreateCredentialRequest implements Parcelable {
32     private final @NonNull CallingAppInfo mCallingAppInfo;
33     private final @NonNull String mType;
34     private final @NonNull Bundle mData;
35 
36     /**
37      * Constructs a new instance.
38      *
39      * @throws IllegalArgumentException If {@code callingAppInfo}, or {@code type} string is
40      * null or empty.
41      * @throws NullPointerException If {@code data} is null.
42      */
CreateCredentialRequest(@onNull CallingAppInfo callingAppInfo, @NonNull String type, @NonNull Bundle data)43     public CreateCredentialRequest(@NonNull CallingAppInfo callingAppInfo,
44             @NonNull String type, @NonNull Bundle data) {
45         mCallingAppInfo = Objects.requireNonNull(callingAppInfo,
46                 "callingAppInfo must not be null");
47         mType = Preconditions.checkStringNotEmpty(type,
48                 "type must not be null or empty");
49         mData = Objects.requireNonNull(data, "data must not be null");
50     }
51 
CreateCredentialRequest(@onNull Parcel in)52     private CreateCredentialRequest(@NonNull Parcel in) {
53         mCallingAppInfo = in.readTypedObject(CallingAppInfo.CREATOR);
54         mType = in.readString8();
55         mData = in.readTypedObject(Bundle.CREATOR);
56     }
57 
58     public static final @NonNull Creator<CreateCredentialRequest> CREATOR =
59             new Creator<CreateCredentialRequest>() {
60                 @Override
61                 public CreateCredentialRequest createFromParcel(@NonNull Parcel in) {
62                     return new CreateCredentialRequest(in);
63                 }
64 
65                 @Override
66                 public CreateCredentialRequest[] newArray(int size) {
67                     return new CreateCredentialRequest[size];
68                 }
69             };
70 
71     @Override
describeContents()72     public int describeContents() {
73         return 0;
74     }
75 
76     @Override
writeToParcel(@onNull Parcel dest, int flags)77     public void writeToParcel(@NonNull Parcel dest, int flags) {
78         dest.writeTypedObject(mCallingAppInfo, flags);
79         dest.writeString8(mType);
80         dest.writeTypedObject(mData, flags);
81     }
82 
83     /** Returns info pertaining to the calling app. */
84     @NonNull
getCallingAppInfo()85     public CallingAppInfo getCallingAppInfo() {
86         return mCallingAppInfo;
87     }
88 
89     /** Returns the type of the credential to be created. */
90     @NonNull
getType()91     public String getType() {
92         return mType;
93     }
94 
95     /** Returns the data to be used while creating the credential. */
96     @NonNull
getData()97     public Bundle getData() {
98         return mData;
99     }
100 }
101