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

Commit 9fdabcdf authored by Helen Qin's avatar Helen Qin
Browse files

Update the Exception data structures.

1. Split into one exception per api.
2. Changed the error code into String error name.

Bug: 246564035
Bug: 253153445
CTS-Coverage-Bug: 246637346
Test: Local Build & Deployment
Change-Id: Ie2a24523599ea17b1cf638df114b843c69d2cf81
parent ee1e8fe7
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -13044,6 +13044,14 @@ package android.content.res.loader {
package android.credentials {
  public class ClearCredentialStateException extends java.lang.Exception {
    ctor public ClearCredentialStateException(@NonNull String, @Nullable String);
    ctor public ClearCredentialStateException(@NonNull String, @Nullable String, @Nullable Throwable);
    ctor public ClearCredentialStateException(@NonNull String, @Nullable Throwable);
    ctor public ClearCredentialStateException(@NonNull String);
    field @NonNull public final String errorType;
  }
  public final class ClearCredentialStateRequest implements android.os.Parcelable {
    ctor public ClearCredentialStateRequest(@NonNull android.os.Bundle);
    method public int describeContents();
@@ -13052,6 +13060,14 @@ package android.credentials {
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.ClearCredentialStateRequest> CREATOR;
  }
  public class CreateCredentialException extends java.lang.Exception {
    ctor public CreateCredentialException(@NonNull String, @Nullable String);
    ctor public CreateCredentialException(@NonNull String, @Nullable String, @Nullable Throwable);
    ctor public CreateCredentialException(@NonNull String, @Nullable Throwable);
    ctor public CreateCredentialException(@NonNull String);
    field @NonNull public final String errorType;
  }
  public final class CreateCredentialRequest implements android.os.Parcelable {
    ctor public CreateCredentialRequest(@NonNull String, @NonNull android.os.Bundle, @NonNull android.os.Bundle, boolean);
    method public int describeContents();
@@ -13081,18 +13097,17 @@ package android.credentials {
  }
  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.CredentialManagerException>);
    method public void executeCreateCredential(@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.CredentialManagerException>);
    method public void executeGetCredential(@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.CredentialManagerException>);
    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 executeCreateCredential(@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 executeGetCredential(@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>);
  }
  public class CredentialManagerException extends java.lang.Exception {
    ctor public CredentialManagerException(int, @Nullable String);
    ctor public CredentialManagerException(int, @Nullable String, @Nullable Throwable);
    ctor public CredentialManagerException(int, @Nullable Throwable);
    ctor public CredentialManagerException(int);
    field public static final int ERROR_UNKNOWN = 0; // 0x0
    field public final int errorCode;
  public class GetCredentialException extends java.lang.Exception {
    ctor public GetCredentialException(@NonNull String, @Nullable String);
    ctor public GetCredentialException(@NonNull String, @Nullable String, @Nullable Throwable);
    ctor public GetCredentialException(@NonNull String, @Nullable Throwable);
    ctor public GetCredentialException(@NonNull String);
    field @NonNull public final String errorType;
  }
  public final class GetCredentialOption implements android.os.Parcelable {
+76 −0
Original line number Diff line number Diff line
/*
 * 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;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.CancellationSignal;
import android.os.OutcomeReceiver;

import com.android.internal.util.Preconditions;

import java.util.concurrent.Executor;

/**
 * Represents an error encountered during the
 * {@link CredentialManager#clearCredentialState(ClearCredentialStateRequest,
 * CancellationSignal, Executor, OutcomeReceiver)} operation.
 */
public class ClearCredentialStateException extends Exception {

    @NonNull
    public final String errorType;

    /**
     * Constructs a {@link ClearCredentialStateException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ClearCredentialStateException(@NonNull String errorType, @Nullable String message) {
        this(errorType, message, null);
    }

    /**
     * Constructs a {@link ClearCredentialStateException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ClearCredentialStateException(
            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
        super(message, cause);
        this.errorType = Preconditions.checkStringNotEmpty(errorType,
                "errorType must not be empty");
    }

    /**
     * Constructs a {@link ClearCredentialStateException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ClearCredentialStateException(@NonNull String errorType, @Nullable Throwable cause) {
        this(errorType, null, cause);
    }

    /**
     * Constructs a {@link ClearCredentialStateException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ClearCredentialStateException(@NonNull String errorType) {
        this(errorType, null, null);
    }
}
+77 −0
Original line number Diff line number Diff line
/*
 * 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;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Activity;
import android.os.CancellationSignal;
import android.os.OutcomeReceiver;

import com.android.internal.util.Preconditions;

import java.util.concurrent.Executor;

/**
 * Represents an error encountered during the
 * {@link CredentialManager#executeCreateCredential(CreateCredentialRequest,
 * Activity, CancellationSignal, Executor, OutcomeReceiver)} operation.
 */
public class CreateCredentialException extends Exception {

    @NonNull
    public final String errorType;

    /**
     * Constructs a {@link CreateCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public CreateCredentialException(@NonNull String errorType, @Nullable String message) {
        this(errorType, message, null);
    }

    /**
     * Constructs a {@link CreateCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public CreateCredentialException(
            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
        super(message, cause);
        this.errorType = Preconditions.checkStringNotEmpty(errorType,
                "errorType must not be empty");
    }

    /**
     * Constructs a {@link CreateCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public CreateCredentialException(@NonNull String errorType, @Nullable Throwable cause) {
        this(errorType, null, cause);
    }

    /**
     * Constructs a {@link CreateCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public CreateCredentialException(@NonNull String errorType) {
        this(errorType, null, null);
    }
}
+15 −15
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public final class CredentialManager {
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<
                    GetCredentialResponse, CredentialManagerException> callback) {
                    GetCredentialResponse, GetCredentialException> callback) {
        requireNonNull(request, "request must not be null");
        requireNonNull(activity, "activity must not be null");
        requireNonNull(executor, "executor must not be null");
@@ -121,7 +121,7 @@ public final class CredentialManager {
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<
                    CreateCredentialResponse, CredentialManagerException> callback) {
                    CreateCredentialResponse, CreateCredentialException> callback) {
        requireNonNull(request, "request must not be null");
        requireNonNull(activity, "activity must not be null");
        requireNonNull(executor, "executor must not be null");
@@ -167,7 +167,7 @@ public final class CredentialManager {
            @NonNull ClearCredentialStateRequest request,
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<Void, CredentialManagerException> callback) {
            @NonNull OutcomeReceiver<Void, ClearCredentialStateException> callback) {
        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

@@ -196,10 +196,10 @@ public final class CredentialManager {
        private final Activity mActivity;
        private final Executor mExecutor;
        private final OutcomeReceiver<
                GetCredentialResponse, CredentialManagerException> mCallback;
                GetCredentialResponse, GetCredentialException> mCallback;

        private GetCredentialTransport(Activity activity, Executor executor,
                OutcomeReceiver<GetCredentialResponse, CredentialManagerException> callback) {
                OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
            mActivity = activity;
            mExecutor = executor;
            mCallback = callback;
@@ -222,9 +222,9 @@ public final class CredentialManager {
        }

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

@@ -234,10 +234,10 @@ public final class CredentialManager {
        private final Activity mActivity;
        private final Executor mExecutor;
        private final OutcomeReceiver<
                CreateCredentialResponse, CredentialManagerException> mCallback;
                CreateCredentialResponse, CreateCredentialException> mCallback;

        private CreateCredentialTransport(Activity activity, Executor executor,
                OutcomeReceiver<CreateCredentialResponse, CredentialManagerException> callback) {
                OutcomeReceiver<CreateCredentialResponse, CreateCredentialException> callback) {
            mActivity = activity;
            mExecutor = executor;
            mCallback = callback;
@@ -260,9 +260,9 @@ public final class CredentialManager {
        }

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

@@ -271,10 +271,10 @@ public final class CredentialManager {
        // TODO: listen for cancellation to release callback.

        private final Executor mExecutor;
        private final OutcomeReceiver<Void, CredentialManagerException> mCallback;
        private final OutcomeReceiver<Void, ClearCredentialStateException> mCallback;

        private ClearCredentialStateTransport(Executor executor,
                OutcomeReceiver<Void, CredentialManagerException> callback) {
                OutcomeReceiver<Void, ClearCredentialStateException> callback) {
            mExecutor = executor;
            mCallback = callback;
        }
@@ -285,9 +285,9 @@ public final class CredentialManager {
        }

        @Override
        public void onError(int errorCode, String message) {
        public void onError(String errorType, String message) {
            mExecutor.execute(
                    () -> mCallback.onError(new CredentialManagerException(errorCode, message)));
                    () -> mCallback.onError(new ClearCredentialStateException(errorType, message)));
        }
    }
}
+77 −0
Original line number Diff line number Diff line
@@ -16,47 +16,62 @@

package android.credentials;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Activity;
import android.os.CancellationSignal;
import android.os.OutcomeReceiver;

/** Exception class for CredentialManager operations. */
public class CredentialManagerException extends Exception {
    /** Indicates that an unknown error was encountered. */
    public static final int ERROR_UNKNOWN = 0;
import com.android.internal.util.Preconditions;

import java.util.concurrent.Executor;

/**
     * The given CredentialManager operation is cancelled by the user.
     *
     * @hide
 * Represents an error encountered during the
 * {@link CredentialManager#executeGetCredential(GetCredentialRequest,
 * Activity, CancellationSignal, Executor, OutcomeReceiver)} operation.
 */
    public static final int ERROR_USER_CANCELLED = 1;
public class GetCredentialException extends Exception {

    @NonNull
    public final String errorType;

    /**
     * No appropriate provider is found to support the target credential type(s).
     * Constructs a {@link GetCredentialException}.
     *
     * @hide
     * @throws IllegalArgumentException If errorType is empty.
     */
    public static final int ERROR_PROVIDER_NOT_FOUND = 2;

    public final int errorCode;

    public CredentialManagerException(int errorCode, @Nullable String message) {
        super(message);
        this.errorCode = errorCode;
    public GetCredentialException(@NonNull String errorType, @Nullable String message) {
        this(errorType, message, null);
    }

    public CredentialManagerException(
            int errorCode, @Nullable String message, @Nullable Throwable cause) {
    /**
     * Constructs a {@link GetCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public GetCredentialException(
            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.errorType = Preconditions.checkStringNotEmpty(errorType,
                "errorType must not be empty");
    }

    public CredentialManagerException(int errorCode, @Nullable Throwable cause) {
        super(cause);
        this.errorCode = errorCode;
    /**
     * Constructs a {@link GetCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public GetCredentialException(@NonNull String errorType, @Nullable Throwable cause) {
        this(errorType, null, cause);
    }

    public CredentialManagerException(int errorCode) {
        super();
        this.errorCode = errorCode;
    /**
     * Constructs a {@link GetCredentialException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public GetCredentialException(@NonNull String errorType) {
        this(errorType, null, null);
    }
}
Loading