Search in sources :

Example 1 with AccountManagerHelper

use of org.chromium.components.signin.AccountManagerHelper in project AndroidChromium by JackyAndroid.

the class ChildAccountService method checkHasChildAccount.

/**
     * Checks for the presence of child accounts on the device.
     *
     * @param callback A callback which will be called with the result.
     */
public static void checkHasChildAccount(Context context, final Callback<Boolean> callback) {
    ThreadUtils.assertOnUiThread();
    if (!nativeIsChildAccountDetectionEnabled()) {
        callback.onResult(false);
        return;
    }
    final AccountManagerHelper helper = AccountManagerHelper.get(context);
    helper.getGoogleAccounts(new Callback<Account[]>() {

        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                callback.onResult(false);
            } else {
                helper.checkChildAccount(accounts[0], callback);
            }
        }
    });
}
Also used : Account(android.accounts.Account) AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper)

Example 2 with AccountManagerHelper

use of org.chromium.components.signin.AccountManagerHelper in project AndroidChromium by JackyAndroid.

the class ToSAckedReceiver method checkAnyUserHasSeenToS.

/**
     * Checks whether any of the current google accounts has seen the ToS in setup wizard.
     * @param context Context for the app.
     * @return Whether or not the the ToS has been seen.
     */
public static boolean checkAnyUserHasSeenToS(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return false;
    Set<String> toSAckedAccounts = ContextUtils.getAppSharedPreferences().getStringSet(TOS_ACKED_ACCOUNTS, null);
    if (toSAckedAccounts == null || toSAckedAccounts.isEmpty())
        return false;
    AccountManagerHelper accountHelper = AccountManagerHelper.get(context);
    List<String> accountNames = accountHelper.getGoogleAccountNames();
    if (accountNames.isEmpty())
        return false;
    for (int k = 0; k < accountNames.size(); k++) {
        if (toSAckedAccounts.contains(accountNames.get(k)))
            return true;
    }
    return false;
}
Also used : AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper)

Example 3 with AccountManagerHelper

use of org.chromium.components.signin.AccountManagerHelper in project AndroidChromium by JackyAndroid.

the class OAuth2TokenService method getAccountOrNullFromUsername.

private static Account getAccountOrNullFromUsername(Context context, String username) {
    if (username == null) {
        Log.e(TAG, "Username is null");
        return null;
    }
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    Account account = accountManagerHelper.getAccountFromName(username);
    if (account == null) {
        Log.e(TAG, "Account not found for provided username.");
        return null;
    }
    return account;
}
Also used : Account(android.accounts.Account) AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper)

Example 4 with AccountManagerHelper

use of org.chromium.components.signin.AccountManagerHelper in project AndroidChromium by JackyAndroid.

the class OAuth2TokenService method getSystemAccountNames.

/**
     * Called by native to list the activite account names in the OS.
     */
@VisibleForTesting
@CalledByNative
public static String[] getSystemAccountNames(Context context) {
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
    return accountNames.toArray(new String[accountNames.size()]);
}
Also used : AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper) VisibleForTesting(org.chromium.base.VisibleForTesting) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 5 with AccountManagerHelper

use of org.chromium.components.signin.AccountManagerHelper in project AndroidChromium by JackyAndroid.

the class OAuth2TokenService method getOAuth2AuthToken.

/**
     * Called by native to retrieve OAuth2 tokens.
     *
     * @param username The native username (full address).
     * @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix).
     * @param nativeCallback The pointer to the native callback that should be run upon completion.
     */
@CalledByNative
public static void getOAuth2AuthToken(Context context, String username, String scope, final long nativeCallback) {
    Account account = getAccountOrNullFromUsername(context, username);
    if (account == null) {
        ThreadUtils.postOnUiThread(new Runnable() {

            @Override
            public void run() {
                nativeOAuth2TokenFetched(null, false, nativeCallback);
            }
        });
        return;
    }
    String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    accountManagerHelper.getAuthToken(account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() {

        @Override
        public void tokenAvailable(String token) {
            nativeOAuth2TokenFetched(token, false, nativeCallback);
        }

        @Override
        public void tokenUnavailable(boolean isTransientError) {
            nativeOAuth2TokenFetched(null, isTransientError, nativeCallback);
        }
    });
}
Also used : Account(android.accounts.Account) AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper) CalledByNative(org.chromium.base.annotations.CalledByNative)

Aggregations

AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)6 Account (android.accounts.Account)3 VisibleForTesting (org.chromium.base.VisibleForTesting)2 CalledByNative (org.chromium.base.annotations.CalledByNative)2