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.annotation.Nullable; 21 import android.os.Bundle; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.internal.util.Preconditions; 26 27 /** 28 * Request for beginning a create credential request. 29 * 30 * See {@link BeginCreateCredentialResponse} for the counterpart response 31 */ 32 public final class BeginCreateCredentialRequest implements Parcelable { 33 private final @Nullable CallingAppInfo mCallingAppInfo; 34 private final @NonNull String mType; 35 private final @NonNull Bundle mData; 36 37 /** 38 * Constructs a new instance. 39 * 40 * @throws IllegalArgumentException If {@code callingAppInfo}, or {@code type} string is 41 * null or empty. 42 * @throws NullPointerException If {@code data} is null. 43 */ BeginCreateCredentialRequest(@onNull String type, @NonNull Bundle data, @Nullable CallingAppInfo callingAppInfo)44 public BeginCreateCredentialRequest(@NonNull String type, @NonNull Bundle data, 45 @Nullable CallingAppInfo callingAppInfo) { 46 mType = Preconditions.checkStringNotEmpty(type, 47 "type must not be null or empty"); 48 Bundle dataCopy = new Bundle(); 49 dataCopy.putAll(data); 50 mData = dataCopy; 51 mCallingAppInfo = callingAppInfo; 52 } 53 54 /** 55 * Constructs a new instance without {@link CallingAppInfo}. 56 * 57 * @throws IllegalArgumentException If {{@code type} string is 58 * null or empty. 59 * @throws NullPointerException If {@code data} is null. 60 */ BeginCreateCredentialRequest(@onNull String type, @NonNull Bundle data)61 public BeginCreateCredentialRequest(@NonNull String type, @NonNull Bundle data) { 62 this(type, data, /*callingAppInfo=*/null); 63 } 64 BeginCreateCredentialRequest(@onNull Parcel in)65 private BeginCreateCredentialRequest(@NonNull Parcel in) { 66 mCallingAppInfo = in.readTypedObject(CallingAppInfo.CREATOR); 67 mType = in.readString8(); 68 mData = in.readBundle(Bundle.class.getClassLoader()); 69 } 70 71 public static final @NonNull Creator<BeginCreateCredentialRequest> CREATOR = 72 new Creator<BeginCreateCredentialRequest>() { 73 @Override 74 public BeginCreateCredentialRequest createFromParcel(@NonNull Parcel in) { 75 return new BeginCreateCredentialRequest(in); 76 } 77 78 @Override 79 public BeginCreateCredentialRequest[] newArray(int size) { 80 return new BeginCreateCredentialRequest[size]; 81 } 82 }; 83 84 @Override describeContents()85 public int describeContents() { 86 return 0; 87 } 88 89 @Override writeToParcel(@onNull Parcel dest, int flags)90 public void writeToParcel(@NonNull Parcel dest, int flags) { 91 dest.writeTypedObject(mCallingAppInfo, flags); 92 dest.writeString8(mType); 93 dest.writeBundle(mData); 94 } 95 96 /** 97 * Returns the info pertaining to the calling app. 98 * 99 * This value can be null when this instance is set on a {@link BeginGetCredentialRequest} or 100 * a {@link BeginCreateCredentialRequest} if the caller of the API does not wish to propagate 101 * this information to a credential provider. 102 */ 103 @Nullable getCallingAppInfo()104 public CallingAppInfo getCallingAppInfo() { 105 return mCallingAppInfo; 106 } 107 108 /** Returns the type of the credential to be created. */ 109 @NonNull getType()110 public String getType() { 111 return mType; 112 } 113 114 /** Returns the data to be used while resolving the credential to create. */ 115 @NonNull getData()116 public Bundle getData() { 117 return mData; 118 } 119 } 120