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.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Dialog; | 8 import android.app.Dialog; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.DialogInterface.OnCancelListener; | 10 import android.content.DialogInterface.OnCancelListener; |
11 import android.content.pm.ApplicationInfo; | 11 import android.content.pm.ApplicationInfo; |
12 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
13 import android.content.pm.PackageManager.NameNotFoundException; | 13 import android.content.pm.PackageManager.NameNotFoundException; |
14 import android.os.Binder; | 14 import android.os.Binder; |
15 import android.os.StrictMode; | 15 import android.os.StrictMode; |
16 import android.os.SystemClock; | |
16 import android.text.TextUtils; | 17 import android.text.TextUtils; |
17 | 18 |
18 import com.google.android.gms.common.ConnectionResult; | 19 import com.google.android.gms.common.ConnectionResult; |
19 import com.google.android.gms.common.GoogleApiAvailability; | 20 import com.google.android.gms.common.GoogleApiAvailability; |
20 | 21 |
21 import org.chromium.base.ApplicationStatus; | 22 import org.chromium.base.ApplicationStatus; |
22 import org.chromium.base.Log; | 23 import org.chromium.base.Log; |
23 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
24 import org.chromium.base.VisibleForTesting; | 25 import org.chromium.base.VisibleForTesting; |
25 import org.chromium.base.metrics.RecordHistogram; | 26 import org.chromium.base.metrics.RecordHistogram; |
26 import org.chromium.chrome.browser.ChromeApplication; | 27 import org.chromium.chrome.browser.ChromeApplication; |
27 | 28 |
29 import java.util.concurrent.TimeUnit; | |
28 import java.util.concurrent.atomic.AtomicReference; | 30 import java.util.concurrent.atomic.AtomicReference; |
29 | 31 |
30 /** | 32 /** |
31 * Utility class for external authentication tools. | 33 * Utility class for external authentication tools. |
32 * | 34 * |
33 * This class is safe to use on any thread. | 35 * This class is safe to use on any thread. |
34 */ | 36 */ |
35 public class ExternalAuthUtils { | 37 public class ExternalAuthUtils { |
36 public static final int FLAG_SHOULD_BE_GOOGLE_SIGNED = 1 << 0; | 38 public static final int FLAG_SHOULD_BE_GOOGLE_SIGNED = 1 << 0; |
37 public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1; | 39 public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 * and returns the code produced by the attempt. Subclasses can override to force the behavior | 238 * and returns the code produced by the attempt. Subclasses can override to force the behavior |
237 * one way or another, or to change the way that the check is performed. | 239 * one way or another, or to change the way that the check is performed. |
238 * @param context The current context. | 240 * @param context The current context. |
239 * @return The code produced by calling the external code | 241 * @return The code produced by calling the external code |
240 */ | 242 */ |
241 protected int checkGooglePlayServicesAvailable(final Context context) { | 243 protected int checkGooglePlayServicesAvailable(final Context context) { |
242 // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577 190 | 244 // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577 190 |
243 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 245 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
244 StrictMode.allowThreadDiskWrites(); | 246 StrictMode.allowThreadDiskWrites(); |
245 try { | 247 try { |
246 return GoogleApiAvailability.getInstance().isGooglePlayServicesAvail able(context); | 248 long time = SystemClock.elapsedRealtime(); |
249 int isAvailable = | |
250 GoogleApiAvailability.getInstance().isGooglePlayServicesAvai lable(context); | |
Yaron
2016/01/21 22:03:22
this one also can happen without native
Peter Wen
2016/01/21 22:13:54
Done.
| |
251 RecordHistogram.recordTimesHistogram("Android.StrictMode.CheckGoogle PlayServicesTime", | |
252 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS) ; | |
253 return isAvailable; | |
247 } finally { | 254 } finally { |
248 StrictMode.setThreadPolicy(oldPolicy); | 255 StrictMode.setThreadPolicy(oldPolicy); |
249 } | 256 } |
250 } | 257 } |
251 | 258 |
252 /** | 259 /** |
253 * Invokes whatever external code is necessary to check if the specified res ult code from | 260 * Invokes whatever external code is necessary to check if the specified res ult code from |
254 * {@link #checkGooglePlayServicesAvailable(Context)} represents success. | 261 * {@link #checkGooglePlayServicesAvailable(Context)} represents success. |
255 * @param resultCode The code to check | 262 * @param resultCode The code to check |
256 * @return true If the result code represents success. | 263 * @return true If the result code represents success. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 */ | 310 */ |
304 public void showErrorDialog(final int errorCode, final Activity activity, fi nal int requestCode, | 311 public void showErrorDialog(final int errorCode, final Activity activity, fi nal int requestCode, |
305 final OnCancelListener onCancelListener) { | 312 final OnCancelListener onCancelListener) { |
306 final Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog ( | 313 final Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog ( |
307 activity, errorCode, requestCode, onCancelListener); | 314 activity, errorCode, requestCode, onCancelListener); |
308 if (dialog != null) { // This can happen if errorCode is ConnectionResul t.SERVICE_INVALID | 315 if (dialog != null) { // This can happen if errorCode is ConnectionResul t.SERVICE_INVALID |
309 dialog.show(); | 316 dialog.show(); |
310 } | 317 } |
311 } | 318 } |
312 } | 319 } |
OLD | NEW |