Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2010 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.content.cts;
     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 public class MockAccountAuthenticator extends AbstractAccountAuthenticator {
     28 
     29     private static MockAccountAuthenticator sMockAuthenticator = null;
     30     public static final String ACCOUNT_NAME = "android.content.cts.account.name";
     31     public static final String ACCOUNT_TYPE = "android.content.cts.account.type";
     32     public static final String ACCOUNT_PASSWORD = "android.content.cts.account.password";
     33     public static final String AUTH_TOKEN = "mockAuthToken";
     34     public static final String AUTH_TOKEN_LABEL = "mockAuthTokenLabel";
     35 
     36     public MockAccountAuthenticator(Context context) {
     37         super(context);
     38     }
     39 
     40     private Bundle createResultBundle() {
     41         Bundle result = new Bundle();
     42         result.putString(AccountManager.KEY_ACCOUNT_NAME, ACCOUNT_NAME);
     43         result.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCOUNT_TYPE);
     44         result.putString(AccountManager.KEY_AUTHTOKEN, AUTH_TOKEN);
     45 
     46         return result;
     47     }
     48 
     49     @Override
     50     public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
     51             String authTokenType, String[] requiredFeatures, Bundle options)
     52             throws NetworkErrorException {
     53         return createResultBundle();
     54     }
     55 
     56     @Override
     57     public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
     58         return createResultBundle();
     59     }
     60 
     61     @Override
     62     public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account,
     63             String authTokenType, Bundle options) throws NetworkErrorException {
     64         return createResultBundle();
     65     }
     66 
     67     @Override
     68     public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account,
     69             Bundle options) throws NetworkErrorException {
     70 
     71         Bundle result = new Bundle();
     72         result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
     73         return result;
     74     }
     75 
     76     @Override
     77     public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
     78             String authTokenType, Bundle options) throws NetworkErrorException {
     79         return createResultBundle();
     80     }
     81 
     82     @Override
     83     public String getAuthTokenLabel(String authTokenType) {
     84         return AUTH_TOKEN_LABEL;
     85     }
     86 
     87     @Override
     88     public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account,
     89             String[] features) throws NetworkErrorException {
     90 
     91         Bundle result = new Bundle();
     92         result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
     93         return result;
     94     }
     95 
     96     public static synchronized MockAccountAuthenticator getMockAuthenticator(Context context) {
     97         if (null == sMockAuthenticator) {
     98             sMockAuthenticator = new MockAccountAuthenticator(context);
     99         }
    100         return sMockAuthenticator;
    101     }
    102 
    103 }
    104