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.selection;
18 
19 import static android.credentials.flags.Flags.FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED;
20 
21 import android.annotation.FlaggedApi;
22 import android.annotation.NonNull;
23 import android.annotation.SuppressLint;
24 import android.annotation.TestApi;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 
28 import com.android.internal.util.AnnotationValidations;
29 
30 /**
31  * Super class for data structures that hold metadata and credential entries for a single provider.
32  *
33  * @hide
34  */
35 @TestApi
36 @FlaggedApi(FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED)
37 @SuppressLint({"ParcelCreator", "ParcelNotFinal"})
38 public abstract class ProviderData implements Parcelable {
39 
40     /**
41      * The intent extra key for the list of {@code ProviderData} from active providers when
42      * launching the UX activities.
43      */
44     public static final String EXTRA_ENABLED_PROVIDER_DATA_LIST =
45             "android.credentials.selection.extra.ENABLED_PROVIDER_DATA_LIST";
46     /**
47      * The intent extra key for the list of {@code ProviderData} from disabled providers when
48      * launching the UX activities.
49      */
50     public static final String EXTRA_DISABLED_PROVIDER_DATA_LIST =
51             "android.credentials.selection.extra.DISABLED_PROVIDER_DATA_LIST";
52 
53     @NonNull
54     private final String mProviderFlattenedComponentName;
55 
ProviderData( @onNull String providerFlattenedComponentName)56     public ProviderData(
57             @NonNull String providerFlattenedComponentName) {
58         mProviderFlattenedComponentName = providerFlattenedComponentName;
59     }
60 
61     /**
62      * Returns provider component name.
63      * It also serves as the unique identifier for this provider.
64      */
65     @NonNull
getProviderFlattenedComponentName()66     public String getProviderFlattenedComponentName() {
67         return mProviderFlattenedComponentName;
68     }
69 
70     @SuppressLint("ParcelConstructor") // Test API only. This is never intended to be officially
71     // exposed. Instead proper final wrapper classes are defined (e.g.
72     // {@code GetCredentialProviderInfo}).
ProviderData(@onNull Parcel in)73     protected ProviderData(@NonNull Parcel in) {
74         String providerFlattenedComponentName = in.readString8();
75         mProviderFlattenedComponentName = providerFlattenedComponentName;
76         AnnotationValidations.validate(NonNull.class, null, mProviderFlattenedComponentName);
77     }
78 
79     @Override
writeToParcel(@onNull Parcel dest, int flags)80     public void writeToParcel(@NonNull Parcel dest, int flags) {
81         dest.writeString8(mProviderFlattenedComponentName);
82     }
83 
84     @Override
describeContents()85     public int describeContents() {
86         return 0;
87     }
88 }
89