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(); |
- } |
} |