Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba1ffac7 authored by Omer Ozer's avatar Omer Ozer
Browse files

Add CredentialDescription unhiding API.

Bug: 260629338
API-Coverage-Bug: 265212839
Test: CTS tests
Change-Id: Id0362bca190dd04768d9d46bfa58e9eab95da872
parent ac6cd614
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -13345,10 +13345,22 @@ package android.credentials {
    field @NonNull public static final String TYPE_PASSWORD_CREDENTIAL = "android.credentials.TYPE_PASSWORD_CREDENTIAL";
  }
  public final class CredentialDescription implements android.os.Parcelable {
    ctor public CredentialDescription(@NonNull String, @NonNull String, @NonNull java.util.List<android.service.credentials.CredentialEntry>);
    method public int describeContents();
    method @NonNull public java.util.List<android.service.credentials.CredentialEntry> getCredentialEntries();
    method @NonNull public String getFlattenedRequestString();
    method @NonNull public String getType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.CredentialDescription> CREATOR;
  }
  public final class CredentialManager {
    method public void clearCredentialState(@NonNull android.credentials.ClearCredentialStateRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.ClearCredentialStateException>);
    method public void createCredential(@NonNull android.credentials.CreateCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CreateCredentialException>);
    method public void getCredential(@NonNull android.credentials.GetCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.GetCredentialException>);
    method public void registerCredentialDescription(@NonNull android.credentials.RegisterCredentialDescriptionRequest);
    method public void unregisterCredentialDescription(@NonNull android.credentials.UnregisterCredentialDescriptionRequest);
  }
  public class GetCredentialException extends java.lang.Exception {
@@ -13372,6 +13384,7 @@ package android.credentials {
    method public boolean isSystemProviderRequired();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.GetCredentialOption> CREATOR;
    field public static final String FLATTENED_REQUEST = "android.credentials.GetCredentialOption.FLATTENED_REQUEST_STRING";
  }
  public final class GetCredentialRequest implements android.os.Parcelable {
@@ -13397,6 +13410,24 @@ package android.credentials {
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.GetCredentialResponse> CREATOR;
  }
  public final class RegisterCredentialDescriptionRequest implements android.os.Parcelable {
    ctor public RegisterCredentialDescriptionRequest(@NonNull android.credentials.CredentialDescription);
    ctor public RegisterCredentialDescriptionRequest(@NonNull java.util.Set<android.credentials.CredentialDescription>);
    method public int describeContents();
    method @NonNull public java.util.Set<android.credentials.CredentialDescription> getCredentialDescriptions();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.RegisterCredentialDescriptionRequest> CREATOR;
  }
  public final class UnregisterCredentialDescriptionRequest implements android.os.Parcelable {
    ctor public UnregisterCredentialDescriptionRequest(@NonNull android.credentials.CredentialDescription);
    ctor public UnregisterCredentialDescriptionRequest(@NonNull java.util.List<android.credentials.CredentialDescription>);
    method public int describeContents();
    method @NonNull public java.util.List<android.credentials.CredentialDescription> getCredentialDescriptions();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.UnregisterCredentialDescriptionRequest> CREATOR;
  }
}
package android.database {
+0 −53
Original line number Diff line number Diff line
@@ -975,59 +975,6 @@ package android.content.rollback {

}

package android.credentials {

  public final class CredentialDescription implements android.os.Parcelable {
    ctor public CredentialDescription(@NonNull String, @NonNull String, @NonNull java.util.List<android.service.credentials.CredentialEntry>);
    method public int describeContents();
    method @NonNull public java.util.List<android.service.credentials.CredentialEntry> getCredentialEntries();
    method @NonNull public String getFlattenedRequestString();
    method @NonNull public String getType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.CredentialDescription> CREATOR;
  }

  public final class CredentialManager {
    method public void registerCredentialDescription(@NonNull android.credentials.RegisterCredentialDescriptionRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.RegisterCredentialDescriptionException>);
    method public void unRegisterCredentialDescription(@NonNull android.credentials.UnregisterCredentialDescriptionRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.UnregisterCredentialDescriptionException>);
  }

  public class RegisterCredentialDescriptionException extends java.lang.Exception {
    ctor public RegisterCredentialDescriptionException(@NonNull String, @Nullable String);
    ctor public RegisterCredentialDescriptionException(@NonNull String, @Nullable String, @Nullable Throwable);
    ctor public RegisterCredentialDescriptionException(@NonNull String, @Nullable Throwable);
    ctor public RegisterCredentialDescriptionException(@NonNull String);
    field @NonNull public final String errorType;
  }

  public final class RegisterCredentialDescriptionRequest implements android.os.Parcelable {
    ctor public RegisterCredentialDescriptionRequest(@NonNull android.credentials.CredentialDescription);
    ctor public RegisterCredentialDescriptionRequest(@NonNull java.util.List<android.credentials.CredentialDescription>);
    method public int describeContents();
    method @NonNull public java.util.List<android.credentials.CredentialDescription> getCredentialDescriptions();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.RegisterCredentialDescriptionRequest> CREATOR;
    field public static final String FLATTENED_REQUEST_STRING_KEY = "flattened_request_string";
  }

  public class UnregisterCredentialDescriptionException extends java.lang.Exception {
    ctor public UnregisterCredentialDescriptionException(@NonNull String, @Nullable String);
    ctor public UnregisterCredentialDescriptionException(@NonNull String, @Nullable String, @Nullable Throwable);
    ctor public UnregisterCredentialDescriptionException(@NonNull String, @Nullable Throwable);
    ctor public UnregisterCredentialDescriptionException(@NonNull String);
    field @NonNull public final String errorType;
  }

  public final class UnregisterCredentialDescriptionRequest implements android.os.Parcelable {
    ctor public UnregisterCredentialDescriptionRequest(@NonNull android.credentials.CredentialDescription);
    method public int describeContents();
    method @NonNull public android.credentials.CredentialDescription getCredentialDescription();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.UnregisterCredentialDescriptionRequest> CREATOR;
  }

}

package android.credentials.ui {

  public final class CreateCredentialProviderData extends android.credentials.ui.ProviderData implements android.os.Parcelable {
+5 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.credentials;

import android.annotation.NonNull;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.service.credentials.CredentialEntry;
@@ -31,9 +30,7 @@ import java.util.Objects;

/**
 * Represents the type and contained data fields of a {@link Credential}.
 * @hide
 */
@TestApi
public final class CredentialDescription implements Parcelable {

    /**
@@ -59,8 +56,11 @@ public final class CredentialDescription implements Parcelable {
     *
     * @param type the type of the credential returned.
     * @param flattenedRequestString flattened JSON string that will be matched with requests.
     * @param credentialEntries a list of {@link  CredentialEntry}s that have been returned
     *                          to the developer upon credential creation.
     * @param credentialEntries a list of {@link CredentialEntry}s that are to be shown on the
     *                          account selector if a credential matches with this description.
     *                          Each entry contains information to be displayed within an
     *                          entry on the UI, as well as a {@link android.app.PendingIntent}
     *                          that will be invoked if the user selects this entry.
     *
     * @throws IllegalArgumentException If type is empty.
     */
+18 −105
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
@@ -315,52 +314,36 @@ public final class CredentialManager {

    /**
     * Registers a {@link CredentialDescription} for an actively provisioned {@link Credential}
     * a CredentialProvider has. This registry will then be used by
     * {@link #executeGetCredential(GetCredentialRequest, Activity,
            * CancellationSignal, Executor, OutcomeReceiver)} to determine where to
     * fetch the requested {@link Credential} from.
     *
     * a CredentialProvider has. This registry will then be used to determine where to
     * fetch the requested {@link Credential} from. Not all credential types will be supported.
     * The distinction will be made by the JetPack layer. For the types that are supported,
     * JetPack will add a new key-value pair into {@link GetCredentialRequest}. These will not
     * be persistent on the device. The Credential Providers will need to call this API again
     * upon device reboot.
     *
     * @param request the request data
     * @param cancellationSignal an optional signal that allows for cancelling this call
     * @param executor the callback will take place on this {@link Executor}
     * @param callback the callback invoked when the request succeeds or fails
     *
     * @throws {@link  UnsupportedOperationException} if the feature has not been enabled.
     * @throws {@link  com.android.server.credentials.NonCredentialProviderCallerException}
     * if the calling package name is not also listed as a Credential Provider.
     * @throws {@link  IllegalArgumentException} if the calling Credential Provider can not handle
     * one or more of the Credential Types that are sent for registration.
     *
     * @hide
     */
    @TestApi
    public void registerCredentialDescription(
            @NonNull RegisterCredentialDescriptionRequest request,
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<Void, RegisterCredentialDescriptionException> callback) {
            @NonNull RegisterCredentialDescriptionRequest request) {

        if (!isCredentialDescriptionApiEnabled()) {
            throw new UnsupportedOperationException("This API is not currently supported.");
        }

        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

        if (cancellationSignal != null && cancellationSignal.isCanceled()) {
            Log.w(TAG, "executeCreateCredential already canceled");
            return;
        }
        requireNonNull(request, "request must not be null");

        ICancellationSignal cancelRemote = null;
        try {
            cancelRemote = mService.registerCredentialDescription(request,
                    new RegisterCredentialDescriptionTransport(executor, callback),
                    mContext.getOpPackageName());
            mService.registerCredentialDescription(request, mContext.getOpPackageName());
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }

        if (cancellationSignal != null && cancelRemote != null) {
            cancellationSignal.setRemote(cancelRemote);
        }
    }


@@ -370,45 +353,25 @@ public final class CredentialManager {
     *
     *
     * @param request the request data
     * @param cancellationSignal an optional signal that allows for cancelling this call
     * @param executor the callback will take place on this {@link Executor}
     * @param callback the callback invoked when the request succeeds or fails
     *
     * @throws {@link  UnsupportedOperationException} if the feature has not been enabled.
     *
     * @hide
     */
    @TestApi
    public void unRegisterCredentialDescription(
            @NonNull UnregisterCredentialDescriptionRequest request,
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<Void, UnregisterCredentialDescriptionException> callback) {
    public void unregisterCredentialDescription(
            @NonNull UnregisterCredentialDescriptionRequest request) {

        if (!isCredentialDescriptionApiEnabled()) {
            throw new UnsupportedOperationException("This API is not currently supported.");
        }

        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

        if (cancellationSignal != null && cancellationSignal.isCanceled()) {
            Log.w(TAG, "executeCreateCredential already canceled");
            return;
        }
        requireNonNull(request, "request must not be null");

        ICancellationSignal cancelRemote = null;
        try {
            cancelRemote = mService.unRegisterCredentialDescription(request,
                    new UnregisterCredentialDescriptionTransport(executor, callback),
                    mContext.getOpPackageName());
            mService.unregisterCredentialDescription(request, mContext.getOpPackageName());
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }

        if (cancellationSignal != null && cancelRemote != null) {
            cancellationSignal.setRemote(cancelRemote);
        }
    }

    private static class GetCredentialTransport extends IGetCredentialCallback.Stub {
@@ -572,54 +535,4 @@ public final class CredentialManager {
                    () -> mCallback.onError(new SetEnabledProvidersException(errorType, message)));
        }
    }

    private static class RegisterCredentialDescriptionTransport
            extends IRegisterCredentialDescriptionCallback.Stub {

        private final Executor mExecutor;
        private final OutcomeReceiver<Void, RegisterCredentialDescriptionException> mCallback;

        private RegisterCredentialDescriptionTransport(Executor executor,
                OutcomeReceiver<Void, RegisterCredentialDescriptionException> callback) {
            mExecutor = executor;
            mCallback = callback;
        }

        @Override
        public void onResponse() {
            mCallback.onResult(null);
        }

        @Override
        public void onError(String errorCode, String message) {
            mExecutor.execute(
                    () -> mCallback.onError(new RegisterCredentialDescriptionException(errorCode,
                            message)));
        }
    }

    private static class UnregisterCredentialDescriptionTransport
            extends IUnregisterCredentialDescriptionCallback.Stub {

        private final Executor mExecutor;
        private final OutcomeReceiver<Void, UnregisterCredentialDescriptionException> mCallback;

        private UnregisterCredentialDescriptionTransport(Executor executor,
                OutcomeReceiver<Void, UnregisterCredentialDescriptionException> callback) {
            mExecutor = executor;
            mCallback = callback;
        }

        @Override
        public void onResponse() {
            mCallback.onResult(null);
        }

        @Override
        public void onError(String errorCode, String message) {
            mExecutor.execute(
                    () -> mCallback.onError(new UnregisterCredentialDescriptionException(errorCode,
                            message)));
        }
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,14 @@ import com.android.internal.util.Preconditions;
 */
public final class GetCredentialOption implements Parcelable {

    /**
     * Bundle key to the flattened version of the JSON request string. Framework will use this key
     * to determine which types of Credentials will utilize Credential Registry when filtering
     * Credential Providers to ping.
     */
    public static final String FLATTENED_REQUEST = "android.credentials"
            + ".GetCredentialOption.FLATTENED_REQUEST_STRING";

    /**
     * The requested credential type.
     */
Loading