From 658617b40f1526657c0ad59a406068af78598ccb Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Fri, 15 Nov 2019 12:41:09 -0800 Subject: 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 --- .../java/android/bluetooth/BluetoothManager.java | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothManager.java') 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; -- cgit v1.2.3