Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java

Issue 1136633005: Add a new utility method to check the availability of Google Play Services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract enum to helper class and clean up logic accordingly Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java
index 8d0367a2a13ba9fd88d1ed0bc1d560eb30fb8f9a..fbd05efd33e71ad69644fc4b4cf7e980d6af0ea3 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java
@@ -11,8 +11,12 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Binder;
import android.text.TextUtils;
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GooglePlayServicesUtil;
+
import org.chromium.base.ApplicationStatus;
import org.chromium.base.Log;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ChromiumApplication;
@@ -26,7 +30,7 @@ import java.util.concurrent.atomic.AtomicReference;
public class ExternalAuthUtils {
public static final int FLAG_SHOULD_BE_GOOGLE_SIGNED = 1 << 0;
public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1;
- private static final String TAG = "ExternalAuthUtils";
+ private static final String TAG = Log.makeTag("ExternalAuthUtils");
// Use an AtomicReference since getInstance() can be called from multiple threads.
private static AtomicReference<ExternalAuthUtils> sInstance =
@@ -149,4 +153,30 @@ public class ExternalAuthUtils {
public boolean isCallerValid(Context context, int authRequirements) {
return isCallerValid(context, authRequirements, "");
}
-}
+
+ /**
+ * Checks whether Google Play Services can be used, applying the specified error-handling
+ * policy if a user-recoverable error occurs. To avoid undue burden on the user, the error
+ * handling policy will be applied at most one time per browser startup (i.e., a dialog or
dgn 2015/05/20 16:33:07 dialog can now be shown more than once
+ * a system notification).
+ * This method is threadsafe. If the specified error-handling policy requires UI interaction,
+ * an asynchronous task will be posted to the main thread to perform such interaction.
+ * @param context The current context.
+ * @param errorHandler How to handle user-recoverable errors; must be non-null.
+ * @return true if and only if Google Play Services can be used
+ */
+ public boolean canUseGooglePlayServices(
+ final Context context, final UserRecoverableErrorHandler errorHandler) {
+ final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
+ if (errorCode == ConnectionResult.SUCCESS) {
+ return true; // Hooray!
+ }
+ // The rest of the method is error-handling bits.
dgn 2015/05/20 16:33:07 The comment is not very useful anymore
+ Log.v(TAG, "Unable to use Google Play Services: %s",
+ GooglePlayServicesUtil.getErrorString(errorCode));
+ if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
+ ThreadUtils.runOnUiThread(errorHandler);
+ }
+ return false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698