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);
}
}
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;
}
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()]);
}
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;
}
}
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;
}
Aggregations