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 36 @Implementation __constructor__(Context context, UserHandle userHandle, AuthenticatorHelper.OnAccountsUpdateListener listener)37 protected void __constructor__(Context context, UserHandle userHandle, 38 AuthenticatorHelper.OnAccountsUpdateListener listener) { 39 } 40 setEnabledAccount(String[] enabledAccount)41 public static void setEnabledAccount(String[] enabledAccount) { 42 sEnabledAccount = enabledAccount; 43 } 44 45 @Resetter reset()46 public static void reset() { 47 sEnabledAccount = TYPES; 48 } 49 50 @Implementation getEnabledAccountTypes()51 protected String[] getEnabledAccountTypes() { 52 return sEnabledAccount; 53 } 54 55 @Implementation getLabelForType(Context context, final String accountType)56 protected CharSequence getLabelForType(Context context, final String accountType) { 57 if (TextUtils.equals(accountType, TYPES[0])) { 58 return LABELS[0]; 59 } else if (TextUtils.equals(accountType, TYPES[1])) { 60 return LABELS[1]; 61 } else if (TextUtils.equals(accountType, TYPES[2])) { 62 return LABELS[2]; 63 } else if (TextUtils.equals(accountType, TYPES[3])) { 64 return LABELS[3]; 65 } 66 return null; 67 } 68 69 @Implementation getDrawableForType(Context context, final String accountType)70 protected Drawable getDrawableForType(Context context, final String accountType) { 71 return context.getPackageManager().getDefaultActivityIcon(); 72 } 73 getTypes()74 public static String[] getTypes() { 75 return TYPES; 76 } 77 getLabels()78 public static String[] getLabels() { 79 return LABELS; 80 } 81 } 82