From 6d6da715c54a58a7f05bd4fa2997e84529219d32 Mon Sep 17 00:00:00 2001 From: Helen Qin Date: Wed, 28 Sep 2022 21:36:57 +0000 Subject: [PATCH] Define the Request and Provider Info as part of the UI protocol. The CredMan selector UI will expect request/provider info from the launching intent. ProviderInfo contains metadata and entry info for a single provider. RequestInfo contains metadata about the app request that initiated this ui flow. Test: deployed locally Bug: 247855226 Change-Id: I3348ec582920d7d8019b272b8fc2b3c2d48404c6 --- .../android/credentials/ui/ProviderData.java | 81 +++++++++++++++++++ .../android/credentials/ui/RequestInfo.java | 79 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 core/java/android/credentials/ui/ProviderData.java create mode 100644 core/java/android/credentials/ui/RequestInfo.java diff --git a/core/java/android/credentials/ui/ProviderData.java b/core/java/android/credentials/ui/ProviderData.java new file mode 100644 index 0000000000000..49e5e49c2450e --- /dev/null +++ b/core/java/android/credentials/ui/ProviderData.java @@ -0,0 +1,81 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.credentials.ui; + +import android.annotation.NonNull; +import android.os.Parcel; +import android.os.Parcelable; + +import com.android.internal.util.AnnotationValidations; + +/** + * Holds metadata and credential entries for a single provider. + * + * @hide + */ +public class ProviderData implements Parcelable { + + /** + * The intent extra key for the list of {@code ProviderData} when launching the UX + * activities. + */ + public static final String EXTRA_PROVIDER_DATA_LIST = + "android.credentials.ui.extra.PROVIDER_DATA_LIST"; + + // TODO: add entry data. + + @NonNull + private final String mPackageName; + + public ProviderData(@NonNull String packageName) { + mPackageName = packageName; + } + + /** Returns the provider package name. */ + @NonNull + public String getPackageName() { + return mPackageName; + } + + protected ProviderData(@NonNull Parcel in) { + String packageName = in.readString8(); + mPackageName = packageName; + AnnotationValidations.validate(NonNull.class, null, mPackageName); + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString8(mPackageName); + } + + @Override + public int describeContents() { + return 0; + } + + public static final @NonNull Creator CREATOR = new Creator() { + @Override + public ProviderData createFromParcel(@NonNull Parcel in) { + return new ProviderData(in); + } + + @Override + public ProviderData[] newArray(int size) { + return new ProviderData[size]; + } + }; +} diff --git a/core/java/android/credentials/ui/RequestInfo.java b/core/java/android/credentials/ui/RequestInfo.java new file mode 100644 index 0000000000000..8af923e162589 --- /dev/null +++ b/core/java/android/credentials/ui/RequestInfo.java @@ -0,0 +1,79 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.credentials.ui; + +import android.annotation.NonNull; +import android.os.IBinder; +import android.os.Parcel; +import android.os.Parcelable; + +import com.android.internal.util.AnnotationValidations; + +/** + * Contains information about the request that initiated this UX flow. + * + * @hide + */ +public class RequestInfo implements Parcelable { + + /** + * The intent extra key for the {@code RequestInfo} object when launching the UX + * activities. + */ + public static final String EXTRA_REQUEST_INFO = "android.credentials.ui.extra.REQUEST_INFO"; + + @NonNull + private final IBinder mToken; + + public RequestInfo(@NonNull IBinder token) { + mToken = token; + } + + /** Returns the request token matching the user request. */ + @NonNull + public IBinder getToken() { + return mToken; + } + + protected RequestInfo(@NonNull Parcel in) { + IBinder token = in.readStrongBinder(); + mToken = token; + AnnotationValidations.validate(NonNull.class, null, mToken); + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeStrongBinder(mToken); + } + + @Override + public int describeContents() { + return 0; + } + + public static final @NonNull Creator CREATOR = new Creator() { + @Override + public RequestInfo createFromParcel(@NonNull Parcel in) { + return new RequestInfo(in); + } + + @Override + public RequestInfo[] newArray(int size) { + return new RequestInfo[size]; + } + }; +}