| 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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.pm.ApplicationInfo; | 9 import android.content.pm.ApplicationInfo; |
| 10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
| 11 import android.content.pm.PackageManager.NameNotFoundException; | 11 import android.content.pm.PackageManager.NameNotFoundException; |
| 12 import android.os.Binder; | 12 import android.os.Binder; |
| 13 import android.os.StrictMode; | 13 import android.os.StrictMode; |
| 14 import android.os.SystemClock; | 14 import android.os.SystemClock; |
| 15 import android.text.TextUtils; | 15 import android.text.TextUtils; |
| 16 | 16 |
| 17 import com.google.android.gms.common.ConnectionResult; | 17 import com.google.android.gms.common.ConnectionResult; |
| 18 import com.google.android.gms.common.GoogleApiAvailability; | 18 import com.google.android.gms.common.GoogleApiAvailability; |
| 19 | 19 |
| 20 import org.chromium.base.ContextUtils; | |
| 21 import org.chromium.base.Log; | 20 import org.chromium.base.Log; |
| 22 import org.chromium.base.ThreadUtils; | 21 import org.chromium.base.ThreadUtils; |
| 23 import org.chromium.base.VisibleForTesting; | 22 import org.chromium.base.VisibleForTesting; |
| 24 import org.chromium.base.metrics.CachedMetrics.SparseHistogramSample; | 23 import org.chromium.base.metrics.CachedMetrics.SparseHistogramSample; |
| 25 import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample; | 24 import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample; |
| 26 import org.chromium.chrome.browser.ChromeApplication; | 25 import org.chromium.chrome.browser.AppGlobals; |
| 27 | 26 |
| 28 import java.util.concurrent.TimeUnit; | 27 import java.util.concurrent.TimeUnit; |
| 29 import java.util.concurrent.atomic.AtomicReference; | 28 import java.util.concurrent.atomic.AtomicReference; |
| 30 | 29 |
| 31 /** | 30 /** |
| 32 * Utility class for external authentication tools. | 31 * Utility class for external authentication tools. |
| 33 * | 32 * |
| 34 * This class is safe to use on any thread. | 33 * This class is safe to use on any thread. |
| 35 */ | 34 */ |
| 36 public class ExternalAuthUtils { | 35 public class ExternalAuthUtils { |
| 37 public static final int FLAG_SHOULD_BE_GOOGLE_SIGNED = 1 << 0; | 36 public static final int FLAG_SHOULD_BE_GOOGLE_SIGNED = 1 << 0; |
| 38 public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1; | 37 public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1; |
| 39 private static final String TAG = "ExternalAuthUtils"; | 38 private static final String TAG = "ExternalAuthUtils"; |
| 40 | 39 |
| 41 // Use an AtomicReference since getInstance() can be called from multiple th
reads. | 40 // Use an AtomicReference since getInstance() can be called from multiple th
reads. |
| 42 private static AtomicReference<ExternalAuthUtils> sInstance = | 41 private static AtomicReference<ExternalAuthUtils> sInstance = |
| 43 new AtomicReference<ExternalAuthUtils>(); | 42 new AtomicReference<ExternalAuthUtils>(); |
| 44 private final SparseHistogramSample mConnectionResultHistogramSample = | 43 private final SparseHistogramSample mConnectionResultHistogramSample = |
| 45 new SparseHistogramSample("GooglePlayServices.ConnectionResult"); | 44 new SparseHistogramSample("GooglePlayServices.ConnectionResult"); |
| 46 private final TimesHistogramSample mRegistrationTimeHistogramSample = new Ti
mesHistogramSample( | 45 private final TimesHistogramSample mRegistrationTimeHistogramSample = new Ti
mesHistogramSample( |
| 47 "Android.StrictMode.CheckGooglePlayServicesTime", TimeUnit.MILLISECO
NDS); | 46 "Android.StrictMode.CheckGooglePlayServicesTime", TimeUnit.MILLISECO
NDS); |
| 48 | 47 |
| 49 /** | 48 /** |
| 50 * Returns the singleton instance of ExternalAuthUtils, creating it if neede
d. | 49 * Returns the singleton instance of ExternalAuthUtils, creating it if neede
d. |
| 51 */ | 50 */ |
| 52 public static ExternalAuthUtils getInstance() { | 51 public static ExternalAuthUtils getInstance() { |
| 53 if (sInstance.get() == null) { | 52 if (sInstance.get() == null) { |
| 54 ChromeApplication application = | 53 sInstance.compareAndSet(null, AppGlobals.get().createExternalAuthUti
ls()); |
| 55 (ChromeApplication) ContextUtils.getApplicationContext(); | |
| 56 sInstance.compareAndSet(null, application.createExternalAuthUtils())
; | |
| 57 } | 54 } |
| 58 return sInstance.get(); | 55 return sInstance.get(); |
| 59 } | 56 } |
| 60 | 57 |
| 61 /** | 58 /** |
| 62 * Gets the calling package names for the current transaction. | 59 * Gets the calling package names for the current transaction. |
| 63 * @param context The context to use for accessing the package manager. | 60 * @param context The context to use for accessing the package manager. |
| 64 * @return The calling package names. | 61 * @return The calling package names. |
| 65 */ | 62 */ |
| 66 private static String[] getCallingPackages(Context context) { | 63 private static String[] getCallingPackages(Context context) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 /** | 302 /** |
| 306 * Invokes whatever external code is necessary to obtain a textual descripti
on of an error | 303 * Invokes whatever external code is necessary to obtain a textual descripti
on of an error |
| 307 * code produced by {@link #checkGooglePlayServicesAvailable(Context)}. | 304 * code produced by {@link #checkGooglePlayServicesAvailable(Context)}. |
| 308 * @param errorCode The code to check | 305 * @param errorCode The code to check |
| 309 * @return a textual description of the error code | 306 * @return a textual description of the error code |
| 310 */ | 307 */ |
| 311 protected String describeError(final int errorCode) { | 308 protected String describeError(final int errorCode) { |
| 312 return GoogleApiAvailability.getInstance().getErrorString(errorCode); | 309 return GoogleApiAvailability.getInstance().getErrorString(errorCode); |
| 313 } | 310 } |
| 314 } | 311 } |
| OLD | NEW |