From d2014fe4199e708358d70b5c929e10c6b75f0c61 Mon Sep 17 00:00:00 2001 From: Reema Bajwa Date: Wed, 7 Dec 2022 02:10:25 +0000 Subject: [PATCH] Add class for holding information about calling app This CallingAppInfo class contains calling app package and app signature. Since Credential manager pings multiple providers, this is a performance optimization so that each provider does not need to query app signatures separately. Test: Built & deployed locally Bug: 253155222 API-Coverage-Bug: 247549381 Change-Id: Iec580a252c4f27b92d02fe5c50e1085ee23f8f4b --- core/api/current.txt | 9 ++ .../service/credentials/CallingAppInfo.java | 99 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 core/java/android/service/credentials/CallingAppInfo.java diff --git a/core/api/current.txt b/core/api/current.txt index 85ae6a149d311..dde664b275208 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -39573,6 +39573,15 @@ package android.service.credentials { field @NonNull public static final android.os.Parcelable.Creator CREATOR; } + public final class CallingAppInfo implements android.os.Parcelable { + ctor public CallingAppInfo(@NonNull String, @NonNull java.util.Set); + method public int describeContents(); + method @NonNull public String getPackageName(); + method @NonNull public java.util.Set getSignatures(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + public final class CreateCredentialRequest implements android.os.Parcelable { ctor public CreateCredentialRequest(@NonNull String, @NonNull String, @NonNull android.os.Bundle); method public int describeContents(); diff --git a/core/java/android/service/credentials/CallingAppInfo.java b/core/java/android/service/credentials/CallingAppInfo.java new file mode 100644 index 0000000000000..1914a247548b8 --- /dev/null +++ b/core/java/android/service/credentials/CallingAppInfo.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 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.service.credentials; + +import android.annotation.NonNull; +import android.content.pm.Signature; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.ArraySet; + +import com.android.internal.util.AnnotationValidations; +import com.android.internal.util.Preconditions; + +import java.util.Objects; +import java.util.Set; + +/** + * Information pertaining to the calling application, including the package name and a list of + * app signatures. + */ +public final class CallingAppInfo implements Parcelable { + @NonNull private final String mPackageName; + @NonNull private final Set mSignatures; + + /** + * Constructs a new instance. + * + * @throws IllegalArgumentException If {@code packageName} is null or empty. + * @throws NullPointerException If {@code signatures} is null. + */ + public CallingAppInfo(@NonNull String packageName, + @NonNull Set signatures) { + mPackageName = Preconditions.checkStringNotEmpty(packageName, + "packageName must not be null or empty"); + mSignatures = Objects.requireNonNull(signatures); + } + + private CallingAppInfo(@NonNull Parcel in) { + final ClassLoader boot = Object.class.getClassLoader(); + mPackageName = in.readString8(); + ArraySet signatures = (ArraySet) in.readArraySet(boot); + mSignatures = signatures == null ? new ArraySet<>() : signatures; + } + + public static final @NonNull Creator CREATOR = new Creator() { + @Override + public CallingAppInfo createFromParcel(Parcel in) { + return new CallingAppInfo(in); + } + + @Override + public CallingAppInfo[] newArray(int size) { + return new CallingAppInfo[size]; + } + }; + + /** Returns the package name of the source of this info. */ + @NonNull public String getPackageName() { + return mPackageName; + } + + /** Returns the Set of signatures belonging to the app */ + @NonNull public Set getSignatures() { + return mSignatures; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString8(mPackageName); + dest.writeArraySet(new ArraySet<>(mSignatures)); + } + + @Override + public String toString() { + return "CallingAppInfo {" + + "packageName= " + mPackageName + + ", No. of signatures: " + mSignatures.size() + + " }"; + } +}