1 /* 2 * Copyright (C) 2013 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.provider.cts.contacts.account; 18 19 import android.accounts.AbstractAccountAuthenticator; 20 import android.accounts.Account; 21 import android.accounts.AccountAuthenticatorResponse; 22 import android.accounts.AccountManager; 23 import android.accounts.NetworkErrorException; 24 import android.content.Context; 25 import android.os.Bundle; 26 27 /** 28 * Account authenticator with 1 hard coded account. 29 * 30 * Also adds the account to the account manager on instantiation. 31 */ 32 public class StaticAccountAuthenticator extends AbstractAccountAuthenticator { 33 34 public static final String NAME = "test_account_name"; 35 public static final String TYPE = "com.android.cts.contactsprovider"; 36 public static final Account ACCOUNT_1 = new Account("cp account 1", TYPE); 37 38 private static final String LABEL = "test_auth_token_label"; 39 private static final String TOKEN = "asdlkjfslkjfdklj"; 40 41 private static Bundle sAccountBundle; 42 static { 43 sAccountBundle = new Bundle(); sAccountBundle.putString(AccountManager.KEY_ACCOUNT_NAME, NAME)44 sAccountBundle.putString(AccountManager.KEY_ACCOUNT_NAME, NAME); sAccountBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, TYPE)45 sAccountBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, TYPE); sAccountBundle.putString(AccountManager.KEY_AUTHTOKEN, TOKEN)46 sAccountBundle.putString(AccountManager.KEY_AUTHTOKEN, TOKEN); 47 } 48 createResultBundle()49 private static Bundle createResultBundle() { 50 return sAccountBundle; 51 } 52 StaticAccountAuthenticator(Context context)53 public StaticAccountAuthenticator(Context context) { 54 super(context); 55 } 56 57 @Override editProperties(AccountAuthenticatorResponse response, String accountType)58 public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { 59 return createResultBundle(); 60 } 61 62 @Override addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options)63 public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, 64 String authTokenType, String[] requiredFeatures, Bundle options) 65 throws NetworkErrorException { 66 return createResultBundle(); 67 } 68 69 @Override confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)70 public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, 71 Bundle options) throws NetworkErrorException { 72 Bundle result = new Bundle(); 73 result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); 74 return result; 75 } 76 77 @Override getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)78 public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, 79 String authTokenType, Bundle options) throws NetworkErrorException { 80 return createResultBundle(); 81 } 82 83 @Override getAuthTokenLabel(String authTokenType)84 public String getAuthTokenLabel(String authTokenType) { 85 return LABEL; 86 } 87 88 @Override updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)89 public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, 90 String authTokenType, Bundle options) throws NetworkErrorException { 91 return createResultBundle(); 92 } 93 94 @Override hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)95 public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, 96 String[] features) throws NetworkErrorException { 97 Bundle result = new Bundle(); 98 result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); 99 return result; 100 } 101 102 } 103