Home | History | Annotate | Download | only in accounts
      1 /*
      2  * Copyright (C) 2014 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.inputmethod.latin.accounts;
     18 
     19 import android.accounts.Account;
     20 import android.accounts.AccountManager;
     21 import android.accounts.AccountManagerCallback;
     22 import android.accounts.AccountManagerFuture;
     23 import android.accounts.AuthenticatorException;
     24 import android.accounts.OperationCanceledException;
     25 import android.content.Context;
     26 import android.os.Bundle;
     27 import android.os.Handler;
     28 
     29 import java.io.IOException;
     30 
     31 /**
     32  * Utility class that handles generation/invalidation of auth tokens in the app.
     33  */
     34 public class AuthUtils {
     35     private final AccountManager mAccountManager;
     36 
     37     public AuthUtils(Context context) {
     38         mAccountManager = AccountManager.get(context);
     39     }
     40 
     41     /**
     42      * @see AccountManager#invalidateAuthToken(String, String)
     43      */
     44     public void invalidateAuthToken(final String accountType, final String authToken) {
     45         mAccountManager.invalidateAuthToken(accountType, authToken);
     46     }
     47 
     48     /**
     49      * @see AccountManager#getAuthToken(
     50      *              Account, String, Bundle, boolean, AccountManagerCallback, Handler)
     51      */
     52     public AccountManagerFuture<Bundle> getAuthToken(final Account account,
     53             final String authTokenType, final Bundle options, final boolean notifyAuthFailure,
     54             final AccountManagerCallback<Bundle> callback, final Handler handler) {
     55         return mAccountManager.getAuthToken(account, authTokenType, options, notifyAuthFailure,
     56                 callback, handler);
     57     }
     58 
     59     /**
     60      * @see AccountManager#blockingGetAuthToken(Account, String, boolean)
     61      */
     62     public String blockingGetAuthToken(final Account account, final String authTokenType,
     63             final boolean notifyAuthFailure) throws OperationCanceledException,
     64             AuthenticatorException, IOException {
     65         return mAccountManager.blockingGetAuthToken(account, authTokenType, notifyAuthFailure);
     66     }
     67 }
     68