| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.externalauth; | 5 package org.chromium.chrome.browser.externalauth; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.pm.ApplicationInfo; | 8 import android.content.pm.ApplicationInfo; |
| 9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
| 10 import android.content.pm.PackageManager.NameNotFoundException; | 10 import android.content.pm.PackageManager.NameNotFoundException; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 * @param context The context to use for getting package information. | 149 * @param context The context to use for getting package information. |
| 150 * @param authRequirements The requirements to be exercised on the caller. | 150 * @param authRequirements The requirements to be exercised on the caller. |
| 151 * @return Whether the caller meets the authentication requirements. | 151 * @return Whether the caller meets the authentication requirements. |
| 152 */ | 152 */ |
| 153 public boolean isCallerValid(Context context, int authRequirements) { | 153 public boolean isCallerValid(Context context, int authRequirements) { |
| 154 return isCallerValid(context, authRequirements, ""); | 154 return isCallerValid(context, authRequirements, ""); |
| 155 } | 155 } |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * Checks whether Google Play Services can be used, applying the specified e
rror-handling | 158 * Checks whether Google Play Services can be used, applying the specified e
rror-handling |
| 159 * policy if a user-recoverable error occurs. To avoid undue burden on the u
ser, the error | 159 * policy if a user-recoverable error occurs. This method is threadsafe. If
the specified |
| 160 * handling policy will be applied at most one time per browser startup (i.e
., a dialog or | 160 * error-handling policy requires UI interaction, it will be run on the UI t
hread. |
| 161 * a system notification). | |
| 162 * This method is threadsafe. If the specified error-handling policy require
s UI interaction, | |
| 163 * an asynchronous task will be posted to the main thread to perform such in
teraction. | |
| 164 * @param context The current context. | 161 * @param context The current context. |
| 165 * @param errorHandler How to handle user-recoverable errors; must be non-nu
ll. | 162 * @param errorHandler How to handle user-recoverable errors; must be non-nu
ll. |
| 166 * @return true if and only if Google Play Services can be used | 163 * @return true if and only if Google Play Services can be used |
| 167 */ | 164 */ |
| 168 public boolean canUseGooglePlayServices( | 165 public boolean canUseGooglePlayServices( |
| 169 final Context context, final UserRecoverableErrorHandler errorHandle
r) { | 166 final Context context, final UserRecoverableErrorHandler errorHandle
r) { |
| 170 final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailab
le(context); | 167 final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailab
le(context); |
| 171 if (errorCode == ConnectionResult.SUCCESS) { | 168 if (errorCode == ConnectionResult.SUCCESS) { |
| 172 return true; // Hooray! | 169 return true; // Hooray! |
| 173 } | 170 } |
| 174 // The rest of the method is error-handling bits. | |
| 175 Log.v(TAG, "Unable to use Google Play Services: %s", | 171 Log.v(TAG, "Unable to use Google Play Services: %s", |
| 176 GooglePlayServicesUtil.getErrorString(errorCode)); | 172 GooglePlayServicesUtil.getErrorString(errorCode)); |
| 177 if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { | 173 if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { |
| 178 ThreadUtils.runOnUiThread(errorHandler); | 174 Runnable errorHandlerTask = new Runnable() { |
| 175 @Override |
| 176 public void run() { |
| 177 errorHandler.handleError(context, errorCode); |
| 178 } |
| 179 }; |
| 180 ThreadUtils.runOnUiThread(errorHandlerTask); |
| 179 } | 181 } |
| 180 return false; | 182 return false; |
| 181 } | 183 } |
| 182 } | 184 } |
| OLD | NEW |