Home | History | Annotate | Download | only in signin
      1 // Copyright 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 package org.chromium.sync.signin;
      6 
      7 import android.accounts.Account;
      8 import android.accounts.AccountManager;
      9 import android.accounts.AccountManagerCallback;
     10 import android.accounts.AccountManagerFuture;
     11 import android.accounts.AuthenticatorDescription;
     12 import android.accounts.AuthenticatorException;
     13 import android.accounts.OperationCanceledException;
     14 import android.app.Activity;
     15 import android.content.Context;
     16 import android.os.Bundle;
     17 import android.os.Handler;
     18 
     19 import java.io.IOException;
     20 
     21 /**
     22  * Default implementation of {@link AccountManagerDelegate} which delegates all calls to the
     23  * Android account manager.
     24  */
     25 public class SystemAccountManagerDelegate implements AccountManagerDelegate {
     26 
     27     private final AccountManager mAccountManager;
     28 
     29     public SystemAccountManagerDelegate(Context context) {
     30         mAccountManager = AccountManager.get(context.getApplicationContext());
     31     }
     32 
     33     @Override
     34     public Account[] getAccountsByType(String type) {
     35         return mAccountManager.getAccountsByType(type);
     36     }
     37 
     38     @Override
     39     public AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
     40             boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler) {
     41         return mAccountManager.getAuthToken(account, authTokenType, null, notifyAuthFailure,
     42                 callback, handler);
     43     }
     44 
     45     @Override
     46     public AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
     47             Bundle options, Activity activity, AccountManagerCallback<Bundle> callback,
     48             Handler handler) {
     49         return mAccountManager.getAuthToken(account, authTokenType, options, activity, callback,
     50                 handler);
     51     }
     52 
     53     @Override
     54     public void invalidateAuthToken(String accountType, String authToken) {
     55         mAccountManager.invalidateAuthToken(accountType, authToken);
     56     }
     57 
     58     @Override
     59     public String blockingGetAuthToken(Account account, String authTokenType,
     60                                        boolean notifyAuthFailure)
     61             throws OperationCanceledException, IOException, AuthenticatorException {
     62         return mAccountManager.blockingGetAuthToken(account, authTokenType, notifyAuthFailure);
     63     }
     64 
     65     @Override
     66     public Account[] getAccounts() {
     67         return mAccountManager.getAccounts();
     68     }
     69 
     70     @Override
     71     public boolean addAccountExplicitly(Account account, String password, Bundle userdata) {
     72         return mAccountManager.addAccountExplicitly(account, password, userdata);
     73     }
     74 
     75     @Override
     76     public AccountManagerFuture<Boolean> removeAccount(Account account,
     77             AccountManagerCallback<Boolean> callback, Handler handler) {
     78         return mAccountManager.removeAccount(account, callback, handler);
     79     }
     80 
     81     @Override
     82     public String getPassword(Account account) {
     83         return mAccountManager.getPassword(account);
     84     }
     85 
     86     @Override
     87     public void setPassword(Account account, String password) {
     88         mAccountManager.setPassword(account, password);
     89     }
     90 
     91     @Override
     92     public void clearPassword(Account account) {
     93         mAccountManager.clearPassword(account);
     94     }
     95 
     96     @Override
     97     public AccountManagerFuture<Bundle> confirmCredentials(Account account, Bundle bundle,
     98             Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
     99         return mAccountManager.confirmCredentials(account, bundle, activity, callback, handler);
    100     }
    101 
    102     @Override
    103     public String peekAuthToken(Account account, String authTokenType) {
    104         return mAccountManager.peekAuthToken(account, authTokenType);
    105     }
    106 
    107     @Override
    108     public AuthenticatorDescription[] getAuthenticatorTypes() {
    109         return mAccountManager.getAuthenticatorTypes();
    110     }
    111 }
    112