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

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

Issue 2176373007: Use Nearby to background scan for URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make some variables private static final Created 4 years, 5 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
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 ed8716c8502a4c6165850c2fe128d75b43c27011..f47da5cdba8d0a0e88ec6fc023bd380ba28640b9 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
@@ -4,12 +4,14 @@
package org.chromium.chrome.browser.physicalweb;
+import android.content.Context;
import android.content.SharedPreferences;
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.components.location.LocationUtils;
/**
* This class provides the basic interface to the Physical Web feature.
@@ -56,22 +58,29 @@ public class PhysicalWeb {
* At the moment, this only enables URL discovery over BLE.
*/
public static void startPhysicalWeb() {
- PhysicalWebBleClient.getInstance().backgroundSubscribe(new Runnable() {
- @Override
- public void run() {
- // We need to clear the list of nearby URLs so that they can be repopulated by the
- // new subscription, but we don't know whether we are already subscribed, so we need
- // to pass a callback so that we can clear as soon as we are resubscribed.
- UrlManager.getInstance().clearNearbyUrls();
- }
- });
+ // Only subscribe to Nearby if we have the location permission.
+ LocationUtils locationUtils = LocationUtils.getInstance();
+ Context context = ContextUtils.getApplicationContext();
+ if (locationUtils.hasAndroidLocationPermission(context)
+ && locationUtils.isSystemLocationSettingEnabled(context)) {
+ new NearbyBackgroundSubscription(NearbySubscription.SUBSCRIBE, new Runnable() {
+ @Override
+ public void run() {
+ // We need to clear the list of nearby URLs so that they can be repopulated by
+ // the new subscription, but we don't know whether we are already subscribed, so
+ // we need to pass a callback so that we can clear as soon as we are
+ // resubscribed.
+ UrlManager.getInstance().clearNearbyUrls();
+ }
+ });
+ }
}
/**
* Stop the Physical Web feature.
*/
public static void stopPhysicalWeb() {
- PhysicalWebBleClient.getInstance().backgroundUnsubscribe(new Runnable() {
+ new NearbyBackgroundSubscription(NearbySubscription.UNSUBSCRIBE, new Runnable() {
@Override
public void run() {
// This isn't absolutely necessary, but it's nice to clean up all our shared prefs.

Powered by Google App Engine
This is Rietveld 408576698