Search in sources :

Example 51 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class OAuth2TokenService method getOAuth2AccessTokenWithTimeout.

/**
     * Call this method to retrieve an OAuth2 access token for the given account and scope. This
     * method times out after the specified timeout, and will return null if that happens.
     *
     * Given that this is a blocking method call, this should never be called from the UI thread.
     *
     * @param account the account to get the access token for.
     * @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix).
     * @param timeout the timeout.
     * @param unit the unit for |timeout|.
     */
@VisibleForTesting
public static String getOAuth2AccessTokenWithTimeout(Context context, Account account, String scope, long timeout, TimeUnit unit) {
    assert !ThreadUtils.runningOnUiThread();
    final AtomicReference<String> result = new AtomicReference<String>();
    final Semaphore semaphore = new Semaphore(0);
    getOAuth2AccessToken(context, account, scope, new AccountManagerHelper.GetAuthTokenCallback() {

        @Override
        public void tokenAvailable(String token) {
            result.set(token);
            semaphore.release();
        }

        @Override
        public void tokenUnavailable(boolean isTransientError) {
            result.set(null);
            semaphore.release();
        }
    });
    try {
        if (semaphore.tryAcquire(timeout, unit)) {
            return result.get();
        } else {
            Log.d(TAG, "Failed to retrieve auth token within timeout (" + timeout + " + " + unit.name() + ")");
            return null;
        }
    } catch (InterruptedException e) {
        Log.w(TAG, "Got interrupted while waiting for auth token");
        return null;
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper) Semaphore(java.util.concurrent.Semaphore) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 52 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class FeatureUtilities method hasGoogleAccountAuthenticator.

@VisibleForTesting
static boolean hasGoogleAccountAuthenticator(Context context) {
    if (sHasGoogleAccountAuthenticator == null) {
        AccountManagerHelper accountHelper = AccountManagerHelper.get(context);
        sHasGoogleAccountAuthenticator = accountHelper.hasGoogleAccountAuthenticator();
    }
    return sHasGoogleAccountAuthenticator;
}
Also used : AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper) VisibleForTesting(org.chromium.base.VisibleForTesting)

Aggregations

VisibleForTesting (org.chromium.base.VisibleForTesting)52 Intent (android.content.Intent)6 IOException (java.io.IOException)6 SharedPreferences (android.content.SharedPreferences)5 JSONObject (org.json.JSONObject)4 PendingIntent (android.app.PendingIntent)3 SpannableString (android.text.SpannableString)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 CalledByNative (org.chromium.base.annotations.CalledByNative)3 AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Paint (android.graphics.Paint)2 File (java.io.File)2 FileReader (java.io.FileReader)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2