1 /* 2 * Copyright 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.credentials; 18 19 import static java.util.Objects.requireNonNull; 20 21 import android.annotation.Hide; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.os.Bundle; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 28 import com.android.internal.util.AnnotationValidations; 29 import com.android.internal.util.Preconditions; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 /** 35 * A request to retrieve a list of candidate credentials against the list of credential 36 * options 37 * 38 * @hide 39 */ 40 @Hide 41 public final class GetCandidateCredentialsRequest implements Parcelable { 42 43 /** 44 * The list of credential requests. 45 */ 46 @NonNull 47 private final List<CredentialOption> mCredentialOptions; 48 49 /** 50 * The top request level data. 51 */ 52 @NonNull 53 private final Bundle mData; 54 55 /** 56 * The origin of the calling app. Callers of this special API (e.g. browsers) 57 * can set this origin for an app different from their own, to be able to get credentials 58 * on behalf of that app. 59 */ 60 @Nullable 61 private String mOrigin; 62 63 /** 64 * Returns the list of credential options to be requested. 65 */ 66 @NonNull getCredentialOptions()67 public List<CredentialOption> getCredentialOptions() { 68 return mCredentialOptions; 69 } 70 71 /** 72 * Returns the top request level data. 73 */ 74 @NonNull getData()75 public Bundle getData() { 76 return mData; 77 } 78 79 /** 80 * Returns the origin of the calling app if set otherwise returns null. 81 */ 82 @Nullable getOrigin()83 public String getOrigin() { 84 return mOrigin; 85 } 86 87 @Override writeToParcel(@onNull Parcel dest, int flags)88 public void writeToParcel(@NonNull Parcel dest, int flags) { 89 dest.writeTypedList(mCredentialOptions, flags); 90 dest.writeBundle(mData); 91 dest.writeString8(mOrigin); 92 } 93 94 @Override describeContents()95 public int describeContents() { 96 return 0; 97 } 98 99 @Override toString()100 public String toString() { 101 return "GetCandidateCredentialsRequest {credentialOption=" + mCredentialOptions 102 + ", data=" + mData 103 + ", origin=" + mOrigin 104 + "}"; 105 } 106 GetCandidateCredentialsRequest(@onNull List<CredentialOption> credentialOptions, @NonNull Bundle data, String origin)107 private GetCandidateCredentialsRequest(@NonNull List<CredentialOption> credentialOptions, 108 @NonNull Bundle data, String origin) { 109 Preconditions.checkCollectionNotEmpty( 110 credentialOptions, 111 /*valueName=*/ "credentialOptions"); 112 Preconditions.checkCollectionElementsNotNull( 113 credentialOptions, 114 /*valueName=*/ "credentialOptions"); 115 mCredentialOptions = credentialOptions; 116 mData = requireNonNull(data, 117 "data must not be null"); 118 mOrigin = origin; 119 } 120 GetCandidateCredentialsRequest(@onNull Parcel in)121 private GetCandidateCredentialsRequest(@NonNull Parcel in) { 122 List<CredentialOption> credentialOptions = new ArrayList<CredentialOption>(); 123 in.readTypedList(credentialOptions, CredentialOption.CREATOR); 124 mCredentialOptions = credentialOptions; 125 AnnotationValidations.validate(NonNull.class, null, mCredentialOptions); 126 127 Bundle data = in.readBundle(); 128 mData = data; 129 AnnotationValidations.validate(NonNull.class, null, mData); 130 131 mOrigin = in.readString8(); 132 } 133 134 @NonNull 135 public static final Creator<GetCandidateCredentialsRequest> CREATOR = 136 new Creator<>() { 137 @Override 138 public GetCandidateCredentialsRequest[] newArray(int size) { 139 return new GetCandidateCredentialsRequest[size]; 140 } 141 142 @Override 143 public GetCandidateCredentialsRequest createFromParcel(@NonNull Parcel in) { 144 return new GetCandidateCredentialsRequest(in); 145 } 146 }; 147 } 148