Search in sources :

Example 46 with AccountManager

use of android.accounts.AccountManager in project apps-android-commons by commons-app.

the class CommonsApplication method revalidateAuthToken.

public Boolean revalidateAuthToken() {
    AccountManager accountManager = AccountManager.get(this);
    Account curAccount = getCurrentAccount();
    if (curAccount == null) {
        // This should never happen
        return false;
    }
    accountManager.invalidateAuthToken(AccountUtil.accountType(), getMWApi().getAuthCookie());
    try {
        String authCookie = accountManager.blockingGetAuthToken(curAccount, "", false);
        getMWApi().setAuthCookie(authCookie);
        return true;
    } catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Account(android.accounts.Account) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) AccountManager(android.accounts.AccountManager) IOException(java.io.IOException)

Example 47 with AccountManager

use of android.accounts.AccountManager in project apps-android-commons by commons-app.

the class CommonsApplication method clearApplicationData.

public void clearApplicationData(Context context) {
    File cacheDirectory = context.getCacheDir();
    File applicationDirectory = new File(cacheDirectory.getParent());
    if (applicationDirectory.exists()) {
        String[] fileNames = applicationDirectory.list();
        for (String fileName : fileNames) {
            if (!fileName.equals("lib")) {
                FileUtils.deleteFile(new File(applicationDirectory, fileName));
            }
        }
    }
    AccountManager accountManager = AccountManager.get(this);
    Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
    for (int index = 0; index < allAccounts.length; index++) {
        accountManager.removeAccount(allAccounts[index], null, null);
    }
    //TODO: fix preference manager 
    PreferenceManager.getDefaultSharedPreferences(getInstance()).edit().clear().commit();
    SharedPreferences preferences = context.getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
    preferences.edit().clear().commit();
    context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
    preferences.edit().putBoolean("firstrun", false).apply();
    updateAllDatabases();
    currentAccount = null;
}
Also used : Account(android.accounts.Account) SharedPreferences(android.content.SharedPreferences) AccountManager(android.accounts.AccountManager) File(java.io.File)

Example 48 with AccountManager

use of android.accounts.AccountManager in project ChatExchange by HueToYou.

the class Authenticator method getAuthToken.

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
    AccountManager accountManager = AccountManager.get(mContext);
    String authToken = accountManager.peekAuthToken(account, authTokenType);
    if (!authToken.isEmpty()) {
        Bundle bundle = new Bundle();
        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
        bundle.putString(AccountManager.KEY_AUTHTOKEN, authToken);
        return bundle;
    }
    return newAccount(response);
}
Also used : Bundle(android.os.Bundle) AccountManager(android.accounts.AccountManager)

Example 49 with AccountManager

use of android.accounts.AccountManager in project android_frameworks_base by crdroidandroid.

the class BugreportProgressService method findSendToAccount.

/**
     * Find the best matching {@link Account} based on build properties.
     */
private static Account findSendToAccount(Context context) {
    final AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
    if (!preferredDomain.startsWith("@")) {
        preferredDomain = "@" + preferredDomain;
    }
    final Account[] accounts;
    try {
        accounts = am.getAccounts();
    } catch (RuntimeException e) {
        Log.e(TAG, "Could not get accounts for preferred domain " + preferredDomain, e);
        return null;
    }
    if (DEBUG)
        Log.d(TAG, "Number of accounts: " + accounts.length);
    Account foundAccount = null;
    for (Account account : accounts) {
        if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
            if (!preferredDomain.isEmpty()) {
                // looking
                if (account.name.endsWith(preferredDomain)) {
                    return account;
                } else {
                    foundAccount = account;
                }
            // if we don't have a preferred domain, just return since it looks like
            // an email address
            } else {
                return account;
            }
        }
    }
    return foundAccount;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 50 with AccountManager

use of android.accounts.AccountManager in project android_frameworks_base by DirtyUnicorns.

the class BugreportProgressService method findSendToAccount.

/**
     * Find the best matching {@link Account} based on build properties.
     */
private static Account findSendToAccount(Context context) {
    final AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
    if (!preferredDomain.startsWith("@")) {
        preferredDomain = "@" + preferredDomain;
    }
    final Account[] accounts;
    try {
        accounts = am.getAccounts();
    } catch (RuntimeException e) {
        Log.e(TAG, "Could not get accounts for preferred domain " + preferredDomain, e);
        return null;
    }
    if (DEBUG)
        Log.d(TAG, "Number of accounts: " + accounts.length);
    Account foundAccount = null;
    for (Account account : accounts) {
        if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
            if (!preferredDomain.isEmpty()) {
                // looking
                if (account.name.endsWith(preferredDomain)) {
                    return account;
                } else {
                    foundAccount = account;
                }
            // if we don't have a preferred domain, just return since it looks like
            // an email address
            } else {
                return account;
            }
        }
    }
    return foundAccount;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Aggregations

AccountManager (android.accounts.AccountManager)105 Account (android.accounts.Account)76 Bundle (android.os.Bundle)14 IOException (java.io.IOException)11 Intent (android.content.Intent)10 OperationCanceledException (android.accounts.OperationCanceledException)7 AuthenticatorException (android.accounts.AuthenticatorException)5 View (android.view.View)5 TextView (android.widget.TextView)5 HashSet (java.util.HashSet)5 SharedPreferences (android.content.SharedPreferences)4 AccountManagerCallback (android.accounts.AccountManagerCallback)3 Paint (android.graphics.Paint)3 JSONException (org.json.JSONException)3 AccountsException (android.accounts.AccountsException)2 TargetApi (android.annotation.TargetApi)2 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 OperationApplicationException (android.content.OperationApplicationException)2