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

Unified Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted two small unnecessary changes. Created 4 years, 6 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 | device/bluetooth/bluetooth_adapter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java
index a7751f75fab24955e4642b3ad2cca6efb4924bbe..ed6d53f5182d4ed219a5cf6fe152b0690cf0de54 100644
--- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java
@@ -36,7 +36,6 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
private long mNativeBluetoothAdapterAndroid;
// mAdapter is final to ensure registerReceiver is followed by unregisterReceiver.
private final Wrappers.BluetoothAdapterWrapper mAdapter;
- private int mNumDiscoverySessions;
private ScanCallback mScanCallback;
// ---------------------------------------------------------------------------------------------
@@ -141,76 +140,11 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
return isPresent() && (mAdapter.isDiscovering() || mScanCallback != null);
}
- // Implements BluetoothAdapterAndroid::AddDiscoverySession.
- @CalledByNative
- private boolean addDiscoverySession() {
- if (!isPowered()) {
- Log.d(TAG, "addDiscoverySession: Fails: !isPowered");
- return false;
- }
-
- mNumDiscoverySessions++;
- Log.d(TAG, "addDiscoverySession: Now %d sessions.", mNumDiscoverySessions);
- if (mNumDiscoverySessions > 1) {
- return true;
- }
-
- if (!startScan()) {
- mNumDiscoverySessions--;
- return false;
- }
- return true;
- }
-
- // Implements BluetoothAdapterAndroid::RemoveDiscoverySession.
- @CalledByNative
- private boolean removeDiscoverySession() {
- if (mNumDiscoverySessions == 0) {
- assert false;
- Log.w(TAG, "removeDiscoverySession: No scan in progress.");
- return false;
- }
-
- --mNumDiscoverySessions;
-
- if (mNumDiscoverySessions == 0) {
- Log.d(TAG, "removeDiscoverySession: Now 0 sessions. Stopping scan.");
- return stopScan();
- }
-
- Log.d(TAG, "removeDiscoverySession: Now %d sessions.", mNumDiscoverySessions);
- return true;
- }
-
- // ---------------------------------------------------------------------------------------------
- // Implementation details:
-
- /**
- * @return true if Chromium has permission to scan for Bluetooth devices.
- */
- private boolean canScan() {
- Wrappers.ContextWrapper context = mAdapter.getContext();
- return context.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
- || context.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION);
- }
-
- private void registerBroadcastReceiver() {
- if (mAdapter != null) {
- mAdapter.getContext().registerReceiver(
- this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
- }
- }
-
- private void unregisterBroadcastReceiver() {
- if (mAdapter != null) {
- mAdapter.getContext().unregisterReceiver(this);
- }
- }
-
/**
* Starts a Low Energy scan.
* @return True on success.
*/
+ @CalledByNative
private boolean startScan() {
Wrappers.BluetoothLeScannerWrapper scanner = mAdapter.getBluetoothLeScanner();
@@ -247,6 +181,7 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
* Stops the Low Energy scan.
* @return True if a scan was in progress.
*/
+ @CalledByNative
private boolean stopScan() {
if (mScanCallback == null) {
return false;
@@ -266,6 +201,31 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
return true;
}
+ // ---------------------------------------------------------------------------------------------
+ // Implementation details:
+
+ /**
+ * @return true if Chromium has permission to scan for Bluetooth devices.
+ */
+ private boolean canScan() {
+ Wrappers.ContextWrapper context = mAdapter.getContext();
+ return context.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
+ || context.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION);
+ }
+
+ private void registerBroadcastReceiver() {
+ if (mAdapter != null) {
+ mAdapter.getContext().registerReceiver(
+ this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
+ }
+ }
+
+ private void unregisterBroadcastReceiver() {
+ if (mAdapter != null) {
+ mAdapter.getContext().unregisterReceiver(this);
+ }
+ }
+
/**
* Implements callbacks used during a Low Energy scan by notifying upon
* devices discovered or detecting a scan failure.
@@ -291,7 +251,6 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
public void onScanFailed(int errorCode) {
Log.w(TAG, "onScanFailed: %d", errorCode);
nativeOnScanFailed(mNativeBluetoothAdapterAndroid);
- mNumDiscoverySessions = 0;
}
}
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698