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

Commit fe4de436 authored by Reema Bajwa's avatar Reema Bajwa
Browse files

Handling all UI event codes and exposing new type constant

This change exposes a new type constant for CreateCredentialException :TYPE_NO_CREATE_OPTIONS. To be used when the provider does not return any options for create in the query phase.

Test: built locally
API-Coverage-Bug: 247549381

Change-Id: I031348d0f16238371a64e9548fdebc06cd9715f9
parent 124299c8
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -13465,7 +13465,7 @@ package android.credentials {
    ctor public CreateCredentialException(@NonNull String);
    method @NonNull public String getType();
    field @NonNull public static final String TYPE_INTERRUPTED = "android.credentials.CreateCredentialException.TYPE_INTERRUPTED";
    field @NonNull public static final String TYPE_NO_CREDENTIAL = "android.credentials.CreateCredentialException.TYPE_NO_CREDENTIAL";
    field @NonNull public static final String TYPE_NO_CREATE_OPTIONS = "android.credentials.CreateCredentialException.TYPE_NO_CREATE_OPTIONS";
    field @NonNull public static final String TYPE_UNKNOWN = "android.credentials.CreateCredentialException.TYPE_UNKNOWN";
    field @NonNull public static final String TYPE_USER_CANCELED = "android.credentials.CreateCredentialException.TYPE_USER_CANCELED";
  }
@@ -40242,6 +40242,7 @@ package android.service.credentials {
  }
  public final class BeginCreateCredentialResponse implements android.os.Parcelable {
    ctor public BeginCreateCredentialResponse();
    method public int describeContents();
    method @NonNull public java.util.List<android.service.credentials.CreateEntry> getCreateEntries();
    method @Nullable public android.service.credentials.CreateEntry getRemoteCreateEntry();
@@ -40283,6 +40284,7 @@ package android.service.credentials {
  }
  public final class BeginGetCredentialResponse implements android.os.Parcelable {
    ctor public BeginGetCredentialResponse();
    method public int describeContents();
    method @NonNull public java.util.List<android.service.credentials.Action> getActions();
    method @NonNull public java.util.List<android.service.credentials.Action> getAuthenticationActions();
+4 −4
Original line number Diff line number Diff line
@@ -40,13 +40,13 @@ public class CreateCredentialException extends Exception {
            "android.credentials.CreateCredentialException.TYPE_UNKNOWN";

    /**
     * The error type value for when no credential is available for the given {@link
     * CredentialManager#createCredential(CreateCredentialRequest, Activity,
     * The error type value for when no create options are available from any provider(s),
     * for the given {@link CredentialManager#createCredential(CreateCredentialRequest, Activity,
     * CancellationSignal, Executor, OutcomeReceiver)} request.
     */
    @NonNull
    public static final String TYPE_NO_CREDENTIAL =
            "android.credentials.CreateCredentialException.TYPE_NO_CREDENTIAL";
    public static final String TYPE_NO_CREATE_OPTIONS =
            "android.credentials.CreateCredentialException.TYPE_NO_CREATE_OPTIONS";
    /**
     * The error type value for when the user intentionally cancelled the request.
     *
+8 −5
Original line number Diff line number Diff line
@@ -34,6 +34,14 @@ public final class BeginCreateCredentialResponse implements Parcelable {
    private final @NonNull List<CreateEntry> mCreateEntries;
    private final @Nullable CreateEntry mRemoteCreateEntry;

    /**
     * Creates an empty response instance, to be used when there are no {@link CreateEntry}
     * to return.
     */
    public BeginCreateCredentialResponse() {
        this(/*createEntries=*/new ArrayList<>(), /*remoteCreateEntry=*/null);
    }

    private BeginCreateCredentialResponse(@NonNull Parcel in) {
        List<CreateEntry> createEntries = new ArrayList<>();
        in.readTypedList(createEntries, CreateEntry.CREATOR);
@@ -137,13 +145,8 @@ public final class BeginCreateCredentialResponse implements Parcelable {

        /**
         * Builds a new instance of {@link BeginCreateCredentialResponse}.
         *
         * @throws NullPointerException If {@code createEntries} is null.
         * @throws IllegalArgumentException If {@code createEntries} is empty.
         */
        public @NonNull BeginCreateCredentialResponse build() {
            Preconditions.checkCollectionNotEmpty(mCreateEntries, "createEntries must "
                    + "not be null, or empty");
            return new BeginCreateCredentialResponse(mCreateEntries, mRemoteCreateEntry);
        }
    }
+11 −8
Original line number Diff line number Diff line
@@ -44,6 +44,17 @@ public final class BeginGetCredentialResponse implements Parcelable {
    /** Remote credential entry to get the response from a different device. */
    private final @Nullable CredentialEntry mRemoteCredentialEntry;

    /**
     * Creates an empty response instance, to be used when there are no {@link CredentialEntry},
     * or {@link Action} to return.
     */
    public BeginGetCredentialResponse() {
        this(/*credentialEntries=*/new ArrayList<>(),
                /*authenticationActions=*/new ArrayList<>(),
                /*actions=*/new ArrayList<>(),
                /*remoteCredentialEntry=*/null);
    }

    private BeginGetCredentialResponse(@NonNull List<CredentialEntry> credentialEntries,
            @NonNull List<Action> authenticationEntries, @NonNull List<Action> actions,
            @Nullable CredentialEntry remoteCredentialEntry) {
@@ -243,16 +254,8 @@ public final class BeginGetCredentialResponse implements Parcelable {

        /**
         * Builds a {@link BeginGetCredentialResponse} instance.
         *
         * @throws IllegalStateException if {@code credentialEntries}, {@code actions}
         *                               and {@code remoteCredentialEntry} are all null or empty.
         */
        public @NonNull BeginGetCredentialResponse build() {
            if (mCredentialEntries.isEmpty() && mActions.isEmpty()
                    && mRemoteCredentialEntry == null && mAuthenticationEntries.isEmpty()) {
                throw new IllegalStateException("must set either an authentication, "
                        + "credential, action or remote entry");
            }
            return new BeginGetCredentialResponse(mCredentialEntries, mAuthenticationEntries,
                    mActions, mRemoteCredentialEntry);
        }
+9 −3
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
        if (response != null) {
            respondToClientWithResponseAndFinish(response);
        } else {
            respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREDENTIAL,
            respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREATE_OPTIONS,
                    "Invalid response");
        }
    }
@@ -119,6 +119,12 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
        }
    }

    @Override
    public void onUiSelectorInvocationFailure() {
        respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREATE_OPTIONS,
                "No create options available.");
    }

    private void respondToClientWithResponseAndFinish(CreateCredentialResponse response) {
        Log.i(TAG, "respondToClientWithResponseAndFinish");
        if (isSessionCancelled()) {
@@ -166,8 +172,8 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
                Log.i(TAG, "in onProviderStatusChanged - isUiInvocationNeeded");
                getProviderDataAndInitiateUi();
            } else {
                respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREDENTIAL,
                        "No credentials available");
                respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREATE_OPTIONS,
                        "No create options available.");
            }
        }
    }
Loading