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

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

Issue 2751343003: Add Intent Filter to listen for BLE state change (Closed)
Patch Set: Dans nits 2 Created 3 years, 9 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/PhysicalWebBroadcastService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebBroadcastService.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebBroadcastService.java
index d18e18f141f948abd9d86ee90db7668874a25719..0943ed7d5310a794f2e05e0d482ac8e208085877 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebBroadcastService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebBroadcastService.java
@@ -8,6 +8,7 @@ import android.annotation.TargetApi;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
+import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -24,6 +25,7 @@ import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder;
import org.chromium.chrome.browser.notifications.NotificationConstants;
import org.chromium.chrome.browser.notifications.NotificationManagerProxy;
import org.chromium.chrome.browser.notifications.NotificationManagerProxyImpl;
+import org.chromium.chrome.browser.util.IntentUtils;
/**
* Broadcasts Physical Web URLs via Bluetooth Low Energy (BLE).
@@ -54,6 +56,7 @@ public class PhysicalWebBroadcastService extends Service {
private static final String STOP_SERVICE =
"org.chromium.chrome.browser.physicalweb.stop_service";
private static final String TAG = "PhysicalWebSharing";
+ private static final int BLUETOOTH_ADAPTER_DEFAULT_STATE = -1;
private boolean mStartedByRestart;
@@ -62,7 +65,13 @@ public class PhysicalWebBroadcastService extends Service {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (STOP_SERVICE.equals(action)) {
+ if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
+ int state = IntentUtils.safeGetIntExtra(
+ intent, BluetoothAdapter.EXTRA_STATE, BLUETOOTH_ADAPTER_DEFAULT_STATE);
+ if (state == BluetoothAdapter.STATE_OFF) {
+ stopSelf();
+ }
+ } else if (STOP_SERVICE.equals(action)) {
stopSelf();
} else {
Log.e(TAG, "Unrecognized Broadcast Received");
@@ -81,7 +90,9 @@ public class PhysicalWebBroadcastService extends Service {
return START_STICKY;
}
- IntentFilter filter = new IntentFilter(STOP_SERVICE);
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+ filter.addAction(STOP_SERVICE);
registerReceiver(mBroadcastReceiver, filter);
// TODO(iankc): implement parsing, broadcasting, Url Shortener.
« 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