diff options
author | Philip P. Moltmann <moltmann@google.com> | 2019-12-14 09:42:22 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-12-14 09:42:22 -0800 |
commit | cb76bf71bfacf8fdaebc8897dce45d819446a832 (patch) | |
tree | bfbedc18138930372cc031f1b66c1097bf5e8cc1 /framework/java/android/bluetooth/BluetoothManager.java | |
parent | 8d808e5c7ae617eeb8c4f25cfdc2ffbacfe86f7d (diff) | |
parent | 67a2f22984fa397af334fefea6a8cc8493569daf (diff) |
Merge "Pipe featureId from app to noteOp in BT code"
am: 67a2f22984
Change-Id: I0d9a1f47328f8fd47e84859e33a6e559ccb77ebd
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothManager.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothManager.java | 30 |
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; |