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

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

Issue 1137083002: Revert of 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_android.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/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 3c8b26521f600895c60f8deadbf46b72bfc27f73..07f6349ddaaa8c6954e7e93511c10cccfb41b9be 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
@@ -4,9 +4,7 @@
package org.chromium.device.bluetooth;
-import android.Manifest;
import android.content.Context;
-import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import org.chromium.base.CalledByNative;
@@ -22,7 +20,6 @@
private static final String TAG = Log.makeTag("Bluetooth");
private final boolean mHasBluetoothPermission;
- private android.bluetooth.BluetoothAdapter mAdapter;
@CalledByNative
private static BluetoothAdapter create(Context context) {
@@ -30,78 +27,16 @@
}
@CalledByNative
- private static BluetoothAdapter createWithoutPermissionForTesting(Context context) {
- Context contextWithoutPermission = new ContextWrapper(context) {
- @Override
- public int checkCallingOrSelfPermission(String permission) {
- return PackageManager.PERMISSION_DENIED;
- }
- };
- return new BluetoothAdapter(contextWithoutPermission);
- }
-
- // Constructs a BluetoothAdapter.
- private BluetoothAdapter(Context context) {
- mHasBluetoothPermission =
- context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH)
- == PackageManager.PERMISSION_GRANTED
- && context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH_ADMIN)
- == PackageManager.PERMISSION_GRANTED;
- if (!mHasBluetoothPermission) {
- Log.w(TAG,
- "Bluetooth API disabled; BLUETOOTH and BLUETOOTH_ADMIN permissions required.");
- return;
- }
-
- mAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
- if (mAdapter == null) Log.i(TAG, "No adapter found.");
- }
-
- @CalledByNative
private boolean hasBluetoothPermission() {
return mHasBluetoothPermission;
}
- // ---------------------------------------------------------------------------------------------
- // BluetoothAdapterAndroid.h interface:
-
- @CalledByNative
- private String getAddress() {
- if (isPresent()) {
- return mAdapter.getAddress();
- } else {
- return "";
+ private BluetoothAdapter(Context context) {
+ mHasBluetoothPermission =
+ context.checkCallingOrSelfPermission(android.Manifest.permission.BLUETOOTH)
+ == PackageManager.PERMISSION_GRANTED;
+ if (!mHasBluetoothPermission) {
+ Log.w(TAG, "Can not use bluetooth API, requires BLUETOOTH permission.");
}
}
-
- @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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698