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 /**
27  * Represents an error encountered during the {@link
28  * CredentialManager#setEnabledProviders(CancellationSignal Executor, OutcomeReceiver)} operation.
29  *
30  * @hide
31  */
32 public class SetEnabledProvidersException extends Exception {
33 
34     @NonNull private final String mType;
35 
36     /** Returns the specific exception type. */
37     @NonNull
getType()38     public String getType() {
39         return mType;
40     }
41 
42     /**
43      * Constructs a {@link SetEnabledProvidersException}.
44      *
45      * @throws IllegalArgumentException If type is empty.
46      */
SetEnabledProvidersException(@onNull String type, @Nullable String message)47     public SetEnabledProvidersException(@NonNull String type, @Nullable String message) {
48         this(type, message, null);
49     }
50 
51     /**
52      * Constructs a {@link SetEnabledProvidersException}.
53      *
54      * @throws IllegalArgumentException If type is empty.
55      */
SetEnabledProvidersException( @onNull String type, @Nullable String message, @Nullable Throwable cause)56     public SetEnabledProvidersException(
57             @NonNull String type, @Nullable String message, @Nullable Throwable cause) {
58         super(message, cause);
59         this.mType =
60                 Preconditions.checkStringNotEmpty(type, "type must not be empty");
61     }
62 
63     /**
64      * Constructs a {@link SetEnabledProvidersException}.
65      *
66      * @throws IllegalArgumentException If type is empty.
67      */
SetEnabledProvidersException(@onNull String type, @Nullable Throwable cause)68     public SetEnabledProvidersException(@NonNull String type, @Nullable Throwable cause) {
69         this(type, null, cause);
70     }
71 
72     /**
73      * Constructs a {@link SetEnabledProvidersException}.
74      *
75      * @throws IllegalArgumentException If type is empty.
76      */
SetEnabledProvidersException(@onNull String type)77     public SetEnabledProvidersException(@NonNull String type) {
78         this(type, null, null);
79     }
80 }
81