diff options
| author | 2022-12-09 01:03:24 +0000 | |
|---|---|---|
| committer | 2022-12-09 01:03:24 +0000 | |
| commit | 7924b40e85e1f8a1dca0c97c93a7cceab4c0811c (patch) | |
| tree | 048398b2456a65063f9ef7c2388b46951d9b0c12 | |
| parent | 7bf3850002545494865e791fe4107be7a13ea415 (diff) | |
| parent | 9fdabcdf3a43e25f9672add35bb2869bf187ea6e (diff) | |
Merge "Update the Exception data structures."
9 files changed, 273 insertions, 90 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index da0bd8db2b78..9a2c75fe490a 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -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 { diff --git a/core/java/android/credentials/ClearCredentialStateException.java b/core/java/android/credentials/ClearCredentialStateException.java new file mode 100644 index 000000000000..a6b76a783fc4 --- /dev/null +++ b/core/java/android/credentials/ClearCredentialStateException.java @@ -0,0 +1,76 @@ +/* + * 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); + } +} diff --git a/core/java/android/credentials/CreateCredentialException.java b/core/java/android/credentials/CreateCredentialException.java new file mode 100644 index 000000000000..87af20883091 --- /dev/null +++ b/core/java/android/credentials/CreateCredentialException.java @@ -0,0 +1,77 @@ +/* + * 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); + } +} diff --git a/core/java/android/credentials/CredentialManager.java b/core/java/android/credentials/CredentialManager.java index 1efac6c2f332..c011949ec6d4 100644 --- a/core/java/android/credentials/CredentialManager.java +++ b/core/java/android/credentials/CredentialManager.java @@ -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))); } } } diff --git a/core/java/android/credentials/CredentialManagerException.java b/core/java/android/credentials/CredentialManagerException.java deleted file mode 100644 index 8369649fe686..000000000000 --- a/core/java/android/credentials/CredentialManagerException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.Nullable; - -/** Exception class for CredentialManager operations. */ -public class CredentialManagerException extends Exception { - /** Indicates that an unknown error was encountered. */ - public static final int ERROR_UNKNOWN = 0; - - /** - * The given CredentialManager operation is cancelled by the user. - * - * @hide - */ - public static final int ERROR_USER_CANCELLED = 1; - - /** - * No appropriate provider is found to support the target credential type(s). - * - * @hide - */ - 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 CredentialManagerException( - int errorCode, @Nullable String message, @Nullable Throwable cause) { - super(message, cause); - this.errorCode = errorCode; - } - - public CredentialManagerException(int errorCode, @Nullable Throwable cause) { - super(cause); - this.errorCode = errorCode; - } - - public CredentialManagerException(int errorCode) { - super(); - this.errorCode = errorCode; - } -} diff --git a/core/java/android/credentials/GetCredentialException.java b/core/java/android/credentials/GetCredentialException.java new file mode 100644 index 000000000000..4d80237b006a --- /dev/null +++ b/core/java/android/credentials/GetCredentialException.java @@ -0,0 +1,77 @@ +/* + * 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#executeGetCredential(GetCredentialRequest, + * Activity, CancellationSignal, Executor, OutcomeReceiver)} operation. + */ +public class GetCredentialException extends Exception { + + @NonNull + public final String errorType; + + /** + * Constructs a {@link GetCredentialException}. + * + * @throws IllegalArgumentException If errorType is empty. + */ + public GetCredentialException(@NonNull String errorType, @Nullable String message) { + this(errorType, message, null); + } + + /** + * 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.errorType = Preconditions.checkStringNotEmpty(errorType, + "errorType must not be empty"); + } + + /** + * Constructs a {@link GetCredentialException}. + * + * @throws IllegalArgumentException If errorType is empty. + */ + public GetCredentialException(@NonNull String errorType, @Nullable Throwable cause) { + this(errorType, null, cause); + } + + /** + * Constructs a {@link GetCredentialException}. + * + * @throws IllegalArgumentException If errorType is empty. + */ + public GetCredentialException(@NonNull String errorType) { + this(errorType, null, null); + } +} diff --git a/core/java/android/credentials/IClearCredentialStateCallback.aidl b/core/java/android/credentials/IClearCredentialStateCallback.aidl index f8b7ae440680..e18e08716729 100644 --- a/core/java/android/credentials/IClearCredentialStateCallback.aidl +++ b/core/java/android/credentials/IClearCredentialStateCallback.aidl @@ -23,5 +23,5 @@ package android.credentials; */ interface IClearCredentialStateCallback { oneway void onSuccess(); - oneway void onError(int errorCode, String message); + oneway void onError(String errorType, String message); }
\ No newline at end of file diff --git a/core/java/android/credentials/ICreateCredentialCallback.aidl b/core/java/android/credentials/ICreateCredentialCallback.aidl index 87fd36fe78f4..f6890a94bc19 100644 --- a/core/java/android/credentials/ICreateCredentialCallback.aidl +++ b/core/java/android/credentials/ICreateCredentialCallback.aidl @@ -27,5 +27,5 @@ import android.credentials.CreateCredentialResponse; interface ICreateCredentialCallback { oneway void onPendingIntent(in PendingIntent pendingIntent); oneway void onResponse(in CreateCredentialResponse response); - oneway void onError(int errorCode, String message); + oneway void onError(String errorType, String message); }
\ No newline at end of file diff --git a/core/java/android/credentials/IGetCredentialCallback.aidl b/core/java/android/credentials/IGetCredentialCallback.aidl index da152bad2da9..6d1182aec7bf 100644 --- a/core/java/android/credentials/IGetCredentialCallback.aidl +++ b/core/java/android/credentials/IGetCredentialCallback.aidl @@ -27,5 +27,5 @@ import android.credentials.GetCredentialResponse; interface IGetCredentialCallback { oneway void onPendingIntent(in PendingIntent pendingIntent); oneway void onResponse(in GetCredentialResponse response); - oneway void onError(int errorCode, String message); + oneway void onError(String errorType, String message); }
\ No newline at end of file |