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