• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 for CTS.
29  */
30 public class StaticAccountAuthenticator extends AbstractAccountAuthenticator {
31 
32     public static final String NAME = "test_account_name";
33     public static final String TYPE = "com.android.cts.contactsprovider";
34     public static final Account ACCOUNT_1 = new Account("cp account 1", TYPE);
35 
36     private static final String LABEL = "test_auth_token_label";
37     private static final String TOKEN = "asdlkjfslkjfdklj";
38 
39     private static Bundle sAccountBundle;
40     static {
41         sAccountBundle = new Bundle();
sAccountBundle.putString(AccountManager.KEY_ACCOUNT_NAME, NAME)42         sAccountBundle.putString(AccountManager.KEY_ACCOUNT_NAME, NAME);
sAccountBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, TYPE)43         sAccountBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, TYPE);
sAccountBundle.putString(AccountManager.KEY_AUTHTOKEN, TOKEN)44         sAccountBundle.putString(AccountManager.KEY_AUTHTOKEN, TOKEN);
45     }
46 
createResultBundle()47     private static Bundle createResultBundle() {
48         return sAccountBundle;
49     }
50 
StaticAccountAuthenticator(Context context)51     public StaticAccountAuthenticator(Context context) {
52         super(context);
53     }
54 
55     @Override
editProperties(AccountAuthenticatorResponse response, String accountType)56     public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
57         return createResultBundle();
58     }
59 
60     @Override
addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options)61     public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
62             String authTokenType, String[] requiredFeatures, Bundle options)
63             throws NetworkErrorException {
64         return createResultBundle();
65     }
66 
67     @Override
confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)68     public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account,
69             Bundle options) throws NetworkErrorException {
70         Bundle result = new Bundle();
71         result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
72         return result;
73     }
74 
75     @Override
getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)76     public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
77             String authTokenType, Bundle options) throws NetworkErrorException {
78         return createResultBundle();
79     }
80 
81     @Override
getAuthTokenLabel(String authTokenType)82     public String getAuthTokenLabel(String authTokenType) {
83         return LABEL;
84     }
85 
86     @Override
updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)87     public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account,
88             String authTokenType, Bundle options) throws NetworkErrorException {
89         return createResultBundle();
90     }
91 
92     @Override
hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)93     public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account,
94             String[] features) throws NetworkErrorException {
95         Bundle result = new Bundle();
96         result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
97         return result;
98     }
99 
100 }
101