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.NonNull; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.internal.util.AnnotationValidations; 26 27 /** 28 * A response object that encapsulates the credential successfully retrieved from the user. 29 */ 30 public final class GetCredentialResponse implements Parcelable { 31 32 /** 33 * The credential that can be used to authenticate the user. 34 */ 35 @NonNull 36 private final Credential mCredential; 37 38 /** 39 * Returns the credential that can be used to authenticate the user, or {@code null} if no 40 * credential is available. 41 */ 42 @NonNull getCredential()43 public Credential getCredential() { 44 return mCredential; 45 } 46 47 @Override writeToParcel(@onNull Parcel dest, int flags)48 public void writeToParcel(@NonNull Parcel dest, int flags) { 49 dest.writeTypedObject(mCredential, flags); 50 } 51 52 @Override describeContents()53 public int describeContents() { 54 return 0; 55 } 56 57 @Override toString()58 public String toString() { 59 return "GetCredentialResponse {" + "credential=" + mCredential + "}"; 60 } 61 62 /** 63 * Constructs a {@link GetCredentialResponse}. 64 * 65 * @param credential the credential successfully retrieved from the user. 66 */ GetCredentialResponse(@onNull Credential credential)67 public GetCredentialResponse(@NonNull Credential credential) { 68 mCredential = requireNonNull(credential, "credential must not be null"); 69 } 70 GetCredentialResponse(@onNull Parcel in)71 private GetCredentialResponse(@NonNull Parcel in) { 72 Credential credential = in.readTypedObject(Credential.CREATOR); 73 mCredential = credential; 74 AnnotationValidations.validate(NonNull.class, null, mCredential); 75 } 76 77 public static final @NonNull Parcelable.Creator<GetCredentialResponse> CREATOR = 78 new Parcelable.Creator<GetCredentialResponse>() { 79 @Override 80 public GetCredentialResponse[] newArray(int size) { 81 return new GetCredentialResponse[size]; 82 } 83 84 @Override 85 public GetCredentialResponse createFromParcel(@NonNull Parcel in) { 86 return new GetCredentialResponse(in); 87 } 88 }; 89 } 90