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: device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothAdapter.java

Issue 1129683002: bluetooth: Android adapter can be created with and without Bluetooth permission. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-jni-
Patch Set: Created 5 years, 7 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: device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothAdapter.java
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothAdapter.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothAdapter.java
index 07f6349ddaaa8c6954e7e93511c10cccfb41b9be..afd6ce7338223338727beb5f61ab437d200597e3 100644
--- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothAdapter.java
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothAdapter.java
@@ -20,6 +20,7 @@ final class BluetoothAdapter {
private static final String TAG = Log.makeTag("Bluetooth");
private final boolean mHasBluetoothPermission;
+ private android.bluetooth.BluetoothAdapter mAdapter;
@CalledByNative
private static BluetoothAdapter create(Context context) {
@@ -27,16 +28,80 @@ final class BluetoothAdapter {
}
@CalledByNative
- private boolean hasBluetoothPermission() {
- return mHasBluetoothPermission;
+ private static BluetoothAdapter createWithoutPermissionForTesting(Context context) {
+ return new BluetoothAdapter();
Ted C 2015/05/07 22:23:57 I would look to see if you can actually do somethi
scheib 2015/05/07 23:59:16 Done.
}
+ // Constructs a BluetoothAdapter.
private BluetoothAdapter(Context context) {
mHasBluetoothPermission =
context.checkCallingOrSelfPermission(android.Manifest.permission.BLUETOOTH)
Ted C 2015/05/07 22:23:57 you should be able to import android.Manifest to d
scheib 2015/05/07 23:59:17 Done.
- == PackageManager.PERMISSION_GRANTED;
+ == PackageManager.PERMISSION_GRANTED
+ && context.checkCallingOrSelfPermission(android.Manifest.permission.BLUETOOTH_ADMIN)
+ == PackageManager.PERMISSION_GRANTED;
if (!mHasBluetoothPermission) {
- Log.w(TAG, "Can not use bluetooth API, requires BLUETOOTH permission.");
+ Log.w(TAG,
+ "Bluetooth API disabled; BLUETOOTH and BLUETOOTH_ADMIN permissions required.");
+ return;
+ }
+
+ mAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
+ if (mAdapter == null) {
+ Log.w(TAG, "No adapter found.");
Ted C 2015/05/07 22:23:57 this looks like it should fit on the previous line
scheib 2015/05/07 23:59:17 Done.
+ }
+ }
+
+ // Constructs a BluetoothAdapter for testing, with no permission.
+ private BluetoothAdapter() {
+ Log.i(TAG, "Testing BluetoothAdapter created.");
+ mHasBluetoothPermission = false;
+ }
+
+ @CalledByNative
+ private boolean hasBluetoothPermission() {
+ return mHasBluetoothPermission;
+ }
+
+ // ---------------------------------------------------------------------------------------------
+ // BluetoothAdapterAndroid.h interface:
+
+ @CalledByNative
+ private String getAddress() {
+ if (isPresent()) {
+ return mAdapter.getAddress();
+ } else {
+ return "";
}
}
+
+ @CalledByNative
+ private String getName() {
+ if (isPresent()) {
+ return mAdapter.getName();
+ } else {
+ return "";
+ }
+ }
+
+ @CalledByNative
+ private boolean isPresent() {
+ return mAdapter != null;
+ }
+
+ @CalledByNative
+ private boolean isPowered() {
+ return isPresent() && mAdapter.isEnabled();
+ }
+
+ @CalledByNative
+ private boolean isDiscoverable() {
+ return isPresent()
+ && mAdapter.getScanMode()
+ == android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
+ }
+
+ @CalledByNative
+ private boolean isDiscovering() {
+ return isPresent() && mAdapter.isDiscovering();
+ }
}
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_android.h » ('j') | device/bluetooth/bluetooth_adapter_android.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698