Example usage for android.accounts OperationCanceledException toString

List of usage examples for android.accounts OperationCanceledException toString

Introduction

In this page you can find the example usage for android.accounts OperationCanceledException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

public static String refreshAuthToken(Activity activity, String token, String name, String googleApi) {
    String authToken = null;/* w  w  w .j  a v a2 s . c o m*/
    final Account account;
    AccountManagerFuture<Bundle> accountFuture;

    account = new Account(name, GOOGLE_ACCOUNT_TYPE);
    try {
        // invalidate the retrieved token and get a fresh one
        AccountManager.get(activity).invalidateAuthToken(GOOGLE_ACCOUNT_TYPE, token);
        accountFuture = AccountManager.get(activity).getAuthToken(account, googleApi, null, activity, null,
                null);
        authToken = accountFuture.getResult().get(AccountManager.KEY_AUTHTOKEN).toString();
    } catch (OperationCanceledException e) {
        Log.e(TAG, e.toString());
    } catch (AuthenticatorException e) {
        Log.e(TAG, e.toString());
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    }
    return authToken;
}

From source file:Main.java

public static String getAuthToken(Activity activity, String name, String googleApi) {
    String authToken = null;/*www  .  ja  v a  2  s. com*/
    final Account account;
    AccountManagerFuture<Bundle> accountFuture;

    account = new Account(name, GOOGLE_ACCOUNT_TYPE);
    accountFuture = AccountManager.get(activity).getAuthToken(account, googleApi, null, activity, null, null);

    try {
        authToken = accountFuture.getResult().get(AccountManager.KEY_AUTHTOKEN).toString();
        // invalidate the retrieved token and get a fresh one
        AccountManager.get(activity).invalidateAuthToken(GOOGLE_ACCOUNT_TYPE, authToken);
        accountFuture = AccountManager.get(activity).getAuthToken(account, googleApi, null, activity, null,
                null);
        authToken = accountFuture.getResult().get(AccountManager.KEY_AUTHTOKEN).toString();
    } catch (OperationCanceledException e) {
        Log.e(TAG, e.toString());
    } catch (AuthenticatorException e) {
        Log.e(TAG, e.toString());
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    }
    return authToken;
}

From source file:com.android.exchange.SyncManager.java

/**
 * Compare our account list (obtained from EmailProvider) with the account list owned by
 * AccountManager.  If there are any orphans (an account in one list without a corresponding
 * account in the other list), delete the orphan, as these must remain in sync.
 *
 * Note that the duplication of account information is caused by the Email application's
 * incomplete integration with AccountManager.
 *
 * This function may not be called from the main/UI thread, because it makes blocking calls
 * into the account manager./*ww  w  .j  a  v  a2  s  . c  o m*/
 *
 * @param context The context in which to operate
 * @param cachedEasAccounts the exchange provider accounts to work from
 * @param accountManagerAccounts The account manager accounts to work from
 * @param blockExternalChanges FOR TESTING ONLY - block backups, security changes, etc.
 * @param resolver the content resolver for making provider updates (injected for testability)
 */
/* package */ static void reconcileAccountsWithAccountManager(Context context, List<Account> cachedEasAccounts,
        android.accounts.Account[] accountManagerAccounts, boolean blockExternalChanges,
        ContentResolver resolver) {
    // First, look through our cached EAS Accounts (from EmailProvider) to make sure there's a
    // corresponding AccountManager account
    boolean accountsDeleted = false;
    for (Account providerAccount : cachedEasAccounts) {
        String providerAccountName = providerAccount.mEmailAddress;
        boolean found = false;
        for (android.accounts.Account accountManagerAccount : accountManagerAccounts) {
            if (accountManagerAccount.name.equalsIgnoreCase(providerAccountName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            if ((providerAccount.mFlags & Account.FLAGS_INCOMPLETE) != 0) {
                log("Account reconciler noticed incomplete account; ignoring");
                continue;
            }
            // This account has been deleted in the AccountManager!
            alwaysLog("Account deleted in AccountManager; deleting from provider: " + providerAccountName);
            // TODO This will orphan downloaded attachments; need to handle this
            resolver.delete(ContentUris.withAppendedId(Account.CONTENT_URI, providerAccount.mId), null, null);
            accountsDeleted = true;
        }
    }
    // Now, look through AccountManager accounts to make sure we have a corresponding cached EAS
    // account from EmailProvider
    for (android.accounts.Account accountManagerAccount : accountManagerAccounts) {
        String accountManagerAccountName = accountManagerAccount.name;
        boolean found = false;
        for (Account cachedEasAccount : cachedEasAccounts) {
            if (cachedEasAccount.mEmailAddress.equalsIgnoreCase(accountManagerAccountName)) {
                found = true;
            }
        }
        if (!found) {
            // This account has been deleted from the EmailProvider database
            alwaysLog("Account deleted from provider; deleting from AccountManager: "
                    + accountManagerAccountName);
            // Delete the account
            AccountManagerFuture<Boolean> blockingResult = AccountManager.get(context)
                    .removeAccount(accountManagerAccount, null, null);
            try {
                // Note: All of the potential errors from removeAccount() are simply logged
                // here, as there is nothing to actually do about them.
                blockingResult.getResult();
            } catch (OperationCanceledException e) {
                Log.w(Email.LOG_TAG, e.toString());
            } catch (AuthenticatorException e) {
                Log.w(Email.LOG_TAG, e.toString());
            } catch (IOException e) {
                Log.w(Email.LOG_TAG, e.toString());
            }
            accountsDeleted = true;
        }
    }
    // If we changed the list of accounts, refresh the backup & security settings
    if (!blockExternalChanges && accountsDeleted) {
        AccountBackupRestore.backupAccounts(context);
        SecurityPolicy.getInstance(context).reducePolicies();
        Email.setNotifyUiAccountsChanged(true);
    }
}