summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothManager.java
diff options
context:
space:
mode:
authorPhilip P. Moltmann <moltmann@google.com>2019-11-15 12:41:09 -0800
committerPhilip P. Moltmann <moltmann@google.com>2019-12-13 10:49:16 -0800
commit658617b40f1526657c0ad59a406068af78598ccb (patch)
treeb2badf0e46729c47fd946abc2bd4eb810f6cc44f /framework/java/android/bluetooth/BluetoothManager.java
parentfccb8d42581e8523296dac72cb4be67bd6ae8c35 (diff)
Pipe featureId from app to noteOp in BT code
FeatureIds are not yet available, hence in BTManager we assume always a "null" featureId. The effect of this change is that for apps that opt into using featureIds, they will have one BluetoothAdapter per feature, not one per process as before. In my testing this caused no problem. Most apps won't use featureIds, hence for most apps there is no change in behavior. Test: used bluetooth Bug: 136595429 Change-Id: Ic40326ea331c60f764f213bb2673cb4c49a81604
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothManager.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothManager.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/framework/java/android/bluetooth/BluetoothManager.java b/framework/java/android/bluetooth/BluetoothManager.java
index adedff3e93..cff4c2d75d 100644
--- a/framework/java/android/bluetooth/BluetoothManager.java
+++ b/framework/java/android/bluetooth/BluetoothManager.java
@@ -22,7 +22,9 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.os.IBinder;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.util.Log;
import java.util.ArrayList;
@@ -60,22 +62,34 @@ public final class BluetoothManager {
* @hide
*/
public BluetoothManager(Context context) {
- context = context.getApplicationContext();
- if (context == null) {
- throw new IllegalArgumentException(
- "context not associated with any application (using a mock context?)");
+ if (null == null) {
+ context = context.getApplicationContext();
+ if (context == null) {
+ throw new IllegalArgumentException(
+ "context not associated with any application (using a mock context?)");
+ }
+
+ mAdapter = BluetoothAdapter.getDefaultAdapter();
+ } else {
+ IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE);
+ if (b != null) {
+ mAdapter = new BluetoothAdapter(IBluetoothManager.Stub.asInterface(b));
+ } else {
+ Log.e(TAG, "Bluetooth binder is null");
+ mAdapter = null;
+ }
}
- // Legacy api - getDefaultAdapter does not take in the context
- mAdapter = BluetoothAdapter.getDefaultAdapter();
+
+ // Context is not initialized in constructor
if (mAdapter != null) {
mAdapter.setContext(context);
}
}
/**
- * Get the default BLUETOOTH Adapter for this device.
+ * Get the BLUETOOTH Adapter for this device.
*
- * @return the default BLUETOOTH Adapter
+ * @return the BLUETOOTH Adapter
*/
public BluetoothAdapter getAdapter() {
return mAdapter;