1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.credentials; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.CancellationSignal; 22 import android.os.OutcomeReceiver; 23 24 import com.android.internal.util.Preconditions; 25 26 import java.util.concurrent.Executor; 27 28 /** 29 * Represents an error encountered during the 30 * {@link CredentialManager#clearCredentialState(ClearCredentialStateRequest, 31 * CancellationSignal, Executor, OutcomeReceiver)} operation. 32 */ 33 public class ClearCredentialStateException extends Exception { 34 /** 35 * The error type value for when the given operation failed due to an unknown reason. 36 */ 37 @NonNull 38 public static final String TYPE_UNKNOWN = 39 "android.credentials.ClearCredentialStateException.TYPE_UNKNOWN"; 40 41 @NonNull 42 private final String mType; 43 44 /** Returns the specific exception type. */ 45 @NonNull getType()46 public String getType() { 47 return mType; 48 } 49 50 /** 51 * Constructs a {@link ClearCredentialStateException}. 52 * 53 * @throws IllegalArgumentException If type is empty. 54 */ ClearCredentialStateException(@onNull String type, @Nullable String message)55 public ClearCredentialStateException(@NonNull String type, @Nullable String message) { 56 this(type, message, null); 57 } 58 59 /** 60 * Constructs a {@link ClearCredentialStateException}. 61 * 62 * @throws IllegalArgumentException If type is empty. 63 */ ClearCredentialStateException( @onNull String type, @Nullable String message, @Nullable Throwable cause)64 public ClearCredentialStateException( 65 @NonNull String type, @Nullable String message, @Nullable Throwable cause) { 66 super(message, cause); 67 this.mType = Preconditions.checkStringNotEmpty(type, 68 "type must not be empty"); 69 } 70 71 /** 72 * Constructs a {@link ClearCredentialStateException}. 73 * 74 * @throws IllegalArgumentException If type is empty. 75 */ ClearCredentialStateException(@onNull String type, @Nullable Throwable cause)76 public ClearCredentialStateException(@NonNull String type, @Nullable Throwable cause) { 77 this(type, null, cause); 78 } 79 80 /** 81 * Constructs a {@link ClearCredentialStateException}. 82 * 83 * @throws IllegalArgumentException If type is empty. 84 */ ClearCredentialStateException(@onNull String type)85 public ClearCredentialStateException(@NonNull String type) { 86 this(type, null, null); 87 } 88 } 89