Search in sources :

Example 31 with VisibleForTesting

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

the class OmahaClient method createConnection.

/**
     * Returns a HttpURLConnection to the server.
     */
@VisibleForTesting
protected HttpURLConnection createConnection() throws RequestFailureException {
    try {
        URL url = new URL(getRequestGenerator().getServerUrl());
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(MS_CONNECTION_TIMEOUT);
        connection.setReadTimeout(MS_CONNECTION_TIMEOUT);
        return connection;
    } catch (MalformedURLException e) {
        throw new RequestFailureException("Caught a malformed URL exception.", e);
    } catch (IOException e) {
        throw new RequestFailureException("Failed to open connection to URL", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) IOException(java.io.IOException) URL(java.net.URL) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 32 with VisibleForTesting

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

the class ShareHelper method getShareIntent.

@VisibleForTesting
public static Intent getShareIntent(Activity activity, String title, String text, String url, Uri offlineUri, Uri screenshotUri) {
    if (!TextUtils.isEmpty(url)) {
        url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
        if (!TextUtils.isEmpty(text)) {
            // Concatenate text and URL with a space.
            text = text + " " + url;
        } else {
            text = url;
        }
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    intent.putExtra(EXTRA_TASK_ID, activity.getTaskId());
    if (screenshotUri != null) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
    if (screenshotUri != null) {
        // To give read access to an Intent target, we need to put |screenshotUri| in clipData
        // because adding Intent.FLAG_GRANT_READ_URI_PERMISSION doesn't work for
        // EXTRA_SHARE_SCREENSHOT_AS_STREAM.
        intent.setClipData(ClipData.newRawUri("", screenshotUri));
        intent.putExtra(EXTRA_SHARE_SCREENSHOT_AS_STREAM, screenshotUri);
    }
    if (offlineUri == null) {
        intent.setType("text/plain");
    } else {
        intent.setType("multipart/related");
        intent.putExtra(Intent.EXTRA_STREAM, offlineUri);
    }
    return intent;
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 33 with VisibleForTesting

use of org.chromium.base.VisibleForTesting 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 34 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 35 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