1 /*
2  * Copyright (C) 2019 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 com.android.settings.testutils.shadow;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.os.UserHandle;
22 import android.text.TextUtils;
23 
24 import com.android.settingslib.accounts.AuthenticatorHelper;
25 
26 import org.robolectric.annotation.Implementation;
27 import org.robolectric.annotation.Implements;
28 import org.robolectric.annotation.Resetter;
29 
30 @Implements(AuthenticatorHelper.class)
31 public class ShadowAuthenticationHelper {
32     static final String[] TYPES = {"type1", "type2", "type3", "type4"};
33     static final String[] LABELS = {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
34     private static String[] sEnabledAccount = TYPES;
35 
__constructor__(Context context, UserHandle userHandle, AuthenticatorHelper.OnAccountsUpdateListener listener)36     protected void __constructor__(Context context, UserHandle userHandle,
37             AuthenticatorHelper.OnAccountsUpdateListener listener) {
38     }
39 
setEnabledAccount(String[] enabledAccount)40     public static void setEnabledAccount(String[] enabledAccount) {
41         sEnabledAccount = enabledAccount;
42     }
43 
44     @Resetter
reset()45     public static void reset() {
46         sEnabledAccount = TYPES;
47     }
48 
49     @Implementation
getEnabledAccountTypes()50     protected String[] getEnabledAccountTypes() {
51         return sEnabledAccount;
52     }
53 
54     @Implementation
getLabelForType(Context context, final String accountType)55     protected CharSequence getLabelForType(Context context, final String accountType) {
56         if (TextUtils.equals(accountType, TYPES[0])) {
57             return LABELS[0];
58         } else if (TextUtils.equals(accountType, TYPES[1])) {
59             return LABELS[1];
60         } else if (TextUtils.equals(accountType, TYPES[2])) {
61             return LABELS[2];
62         } else if (TextUtils.equals(accountType, TYPES[3])) {
63             return LABELS[3];
64         }
65         return null;
66     }
67 
68     @Implementation
getDrawableForType(Context context, final String accountType)69     protected Drawable getDrawableForType(Context context, final String accountType) {
70         return context.getPackageManager().getDefaultActivityIcon();
71     }
72 
getTypes()73     public static String[] getTypes() {
74         return TYPES;
75     }
76 
getLabels()77     public static String[] getLabels() {
78         return LABELS;
79     }
80 }
81