| Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
|
| index bc4ec0667c33490316c0a8d335fc23de616ed9d8..ba594a7a5f10007f4b9df8857d5e251177356bc2 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
|
| @@ -10,6 +10,8 @@ import android.os.Build;
|
| import org.chromium.base.ContextUtils;
|
| import org.chromium.chrome.browser.ChromeFeatureList;
|
| import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager;
|
| +import org.chromium.chrome.browser.profiles.Profile;
|
| +import org.chromium.chrome.browser.search_engines.TemplateUrlService;
|
| import org.chromium.components.location.LocationUtils;
|
|
|
| /**
|
| @@ -24,7 +26,7 @@ public class PhysicalWeb {
|
| private static final int MIN_ANDROID_VERSION = 18;
|
|
|
| /**
|
| - * Evaluate whether the environment is one in which the Physical Web should
|
| + * Evaluates whether the environment is one in which the Physical Web should
|
| * be enabled.
|
| * @return true if the PhysicalWeb should be enabled
|
| */
|
| @@ -53,7 +55,7 @@ public class PhysicalWeb {
|
| }
|
|
|
| /**
|
| - * Start the Physical Web feature.
|
| + * Starts the Physical Web feature.
|
| * At the moment, this only enables URL discovery over BLE.
|
| */
|
| public static void startPhysicalWeb() {
|
| @@ -66,7 +68,7 @@ public class PhysicalWeb {
|
| }
|
|
|
| /**
|
| - * Stop the Physical Web feature.
|
| + * Stops the Physical Web feature.
|
| */
|
| public static void stopPhysicalWeb() {
|
| new NearbyBackgroundSubscription(NearbySubscription.UNSUBSCRIBE, new Runnable() {
|
| @@ -108,21 +110,40 @@ public class PhysicalWeb {
|
| }
|
|
|
| /**
|
| - * Perform various Physical Web operations that should happen on startup.
|
| + * Performs various Physical Web operations that should happen on startup.
|
| */
|
| public static void onChromeStart() {
|
| - // The PhysicalWebUma calls in this method should be called only when the native library is
|
| - // loaded. This is always the case on chrome startup.
|
| - if (featureIsEnabled() && (isPhysicalWebPreferenceEnabled() || isOnboarding())) {
|
| + if (!featureIsEnabled()) {
|
| + stopPhysicalWeb();
|
| + return;
|
| + }
|
| +
|
| + // If this user is in the default state, we need to check if we should enable Physical Web.
|
| + if (isOnboarding() && shouldAutoEnablePhysicalWeb()) {
|
| + PrivacyPreferencesManager.getInstance().setPhysicalWebEnabled(true);
|
| + }
|
| +
|
| + if (isPhysicalWebPreferenceEnabled()) {
|
| boolean ignoreOtherClients =
|
| ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAME);
|
| ContextUtils.getAppSharedPreferences().edit()
|
| .putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
|
| .apply();
|
| startPhysicalWeb();
|
| + // The PhysicalWebUma call in this method should be called only when the native library
|
| + // is loaded. This is always the case on chrome startup.
|
| PhysicalWebUma.uploadDeferredMetrics();
|
| - } else {
|
| - stopPhysicalWeb();
|
| }
|
| }
|
| +
|
| + /**
|
| + * Checks if this device should have Physical Web automatically enabled.
|
| + */
|
| + private static boolean shouldAutoEnablePhysicalWeb() {
|
| + LocationUtils locationUtils = LocationUtils.getInstance();
|
| + return locationUtils.isSystemLocationSettingEnabled()
|
| + && locationUtils.hasAndroidLocationPermission()
|
| + && TemplateUrlService.getInstance().isDefaultSearchEngineGoogle()
|
| + && !Profile.getLastUsedProfile().isOffTheRecord();
|
| + }
|
| }
|
|
|