Java Code Examples for org.chromium.sync.signin.AccountManagerHelper#get()

The following examples show how to use org.chromium.sync.signin.AccountManagerHelper#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChildAccountService.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
            }
        }
    });
}
 
Example 2
Source File: OAuth2TokenService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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 int nativeCallback) {
    Account account = getAccountOrNullFromUsername(context, username);
    if (account == null) {
        nativeOAuth2TokenFetched(null, false, nativeCallback);
        return;
    }
    String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;

    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    accountManagerHelper.getAuthTokenFromForeground(
        null, account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() {
            @Override
            public void tokenAvailable(String token) {
                nativeOAuth2TokenFetched(
                    token, token != null, nativeCallback);
            }
        });
}
 
Example 3
Source File: OAuth2TokenService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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 int nativeCallback) {
    Account account = getAccountOrNullFromUsername(context, username);
    if (account == null) {
        nativeOAuth2TokenFetched(null, false, nativeCallback);
        return;
    }
    String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;

    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    accountManagerHelper.getAuthTokenFromForeground(
        null, account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() {
            @Override
            public void tokenAvailable(String token) {
                nativeOAuth2TokenFetched(
                    token, token != null, nativeCallback);
            }
        });
}
 
Example 4
Source File: OAuth2TokenService.java    From delion with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: OAuth2TokenService.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * 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()]);
}
 
Example 6
Source File: OAuth2TokenService.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
                }
            });
}
 
Example 7
Source File: FeatureUtilities.java    From delion with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static boolean hasGoogleAccountAuthenticator(Context context) {
    if (sHasGoogleAccountAuthenticator == null) {
        AccountManagerHelper accountHelper = AccountManagerHelper.get(context);
        sHasGoogleAccountAuthenticator = accountHelper.hasGoogleAccountAuthenticator();
    }
    return sHasGoogleAccountAuthenticator;
}
 
Example 8
Source File: ToSAckedReceiver.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
    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;
}
 
Example 9
Source File: OAuth2TokenService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example 10
Source File: OAuth2TokenService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Called by native to list the accounts with OAuth2 refresh tokens.
 */
@CalledByNative
public static String[] getAccounts(Context context) {
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
    return accountNames.toArray(new String[accountNames.size()]);
}
 
Example 11
Source File: OAuth2TokenService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example 12
Source File: OAuth2TokenService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Called by native to list the accounts with OAuth2 refresh tokens.
 */
@CalledByNative
public static String[] getAccounts(Context context) {
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
    return accountNames.toArray(new String[accountNames.size()]);
}
 
Example 13
Source File: AccountSigninView.java    From delion with Apache License 2.0 4 votes vote down vote up
public AccountSigninView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mAccountManagerHelper = AccountManagerHelper.get(getContext().getApplicationContext());
}