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.app.PendingIntent; 21 import android.app.slice.Slice; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * An entry to be shown on the UI. This entry represents remote execution of a get/create flow 27 * whereby credentials are retrieved from, or stored to a remote device. 28 * 29 * <p>If user selects this entry, the corresponding {@link PendingIntent} set on the 30 * {@code slice} as a {@link androidx.slice.core.SliceAction} will get invoked. 31 * Once the resulting activity fulfills the required user engagement, 32 * the {@link android.app.Activity} result should be set to {@link android.app.Activity#RESULT_OK}, 33 * and the result of the operation must be set as the activity result. 34 * 35 * For a get flow, invoked through {@link CredentialProviderService#onBeginGetCredential}, 36 * providers must set a {@link android.credentials.GetCredentialResponse} on the activity result, 37 * against the key {@link CredentialProviderService#EXTRA_GET_CREDENTIAL_RESPONSE}. 38 * 39 * For a creates flow, invoked through {@link CredentialProviderService#onBeginCreateCredential}, 40 * providers must set a {@link android.credentials.CreateCredentialResponse} on the activity 41 * result against the ket {@link CredentialProviderService#EXTRA_CREATE_CREDENTIAL_RESPONSE}. 42 */ 43 public final class RemoteEntry implements Parcelable { 44 private final @NonNull Slice mSlice; 45 RemoteEntry(@onNull Parcel in)46 private RemoteEntry(@NonNull Parcel in) { 47 mSlice = in.readTypedObject(Slice.CREATOR); 48 } 49 50 @NonNull 51 public static final Creator<RemoteEntry> CREATOR = new Creator<RemoteEntry>() { 52 @Override 53 public RemoteEntry createFromParcel(@NonNull Parcel in) { 54 return new RemoteEntry(in); 55 } 56 57 @Override 58 public RemoteEntry[] newArray(int size) { 59 return new RemoteEntry[size]; 60 } 61 }; 62 63 @Override describeContents()64 public int describeContents() { 65 return 0; 66 } 67 68 @Override writeToParcel(@onNull Parcel dest, int flags)69 public void writeToParcel(@NonNull Parcel dest, int flags) { 70 dest.writeTypedObject(mSlice, flags); 71 } 72 73 /** 74 * Constructs a RemoteEntry to be displayed on the UI. 75 * 76 * @param slice the slice containing the metadata to be shown on the UI, must be constructed 77 * through the {@link androidx.credentials.provider} Jetpack library; 78 * If constructed manually, the {@code slice} object must 79 * contain the non-null properties of the 80 * {@link androidx.credentials.provider.RemoteEntry} class populated as slice items 81 * against specific hints as used in the class's {@code toSlice} method, 82 * since the Android System uses this library to parse the {@code slice} and 83 * extract the required attributes 84 */ RemoteEntry( @onNull Slice slice)85 public RemoteEntry( 86 @NonNull Slice slice) { 87 this.mSlice = slice; 88 com.android.internal.util.AnnotationValidations.validate( 89 NonNull.class, null, mSlice); 90 } 91 92 /** Returns the content to be displayed with this remote entry on the UI. */ 93 @NonNull getSlice()94 public Slice getSlice() { 95 return mSlice; 96 } 97 } 98