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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java

Issue 2618613007: Auto-enable Physical Web for appropriate users (Closed)
Patch Set: Rebase Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698