Commit 5d0bae6b authored by cco3's avatar cco3 Committed by Commit bot

Auto-enable Physical Web for appropriate users

Now that the Physical Web no longer displays notifications, the
opt-in notification will not fire.  Instead, users can enable the
Physical Web manually, or if they have Google search enabled (i.e.,
they are already sending info to Google for omnibox results).  Note
that this is the same behavior as on iOS.

BUG=663842

Review-Url: https://codereview.chromium.org/2618613007
Cr-Commit-Position: refs/heads/master@{#443128}
parent 4d26738f
......@@ -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();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment