diff options
| author | 2018-12-13 12:42:58 +0000 | |
|---|---|---|
| committer | 2018-12-13 12:42:58 +0000 | |
| commit | bee9a87193a80f59dc174ce02deb5ed5d967716b (patch) | |
| tree | 4a9789bb41b4d7c92f74c45fe2d007f4830797d2 | |
| parent | da9de2d7fa24ab8003ca2b490ccae9e1e6ad9d9c (diff) | |
| parent | 57e6e90204de2c152f2624b94f49f9045edc1346 (diff) | |
Merge "Pass package name as part of startDiscovery"
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 20 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothManager.java | 1 |
2 files changed, 20 insertions, 1 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 654bfaf293b8..10c8b15a7a79 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -643,6 +643,7 @@ public final class BluetoothAdapter { private final IBluetoothManager mManagerService; @UnsupportedAppUsage private IBluetooth mService; + private Context mContext; private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock(); private final Object mLock = new Object(); @@ -1541,6 +1542,23 @@ public final class BluetoothAdapter { } /** + * Set the context for this BluetoothAdapter (only called from BluetoothManager) + * @hide + */ + public void setContext(Context context) { + mContext = context; + } + + private String getOpPackageName() { + // Workaround for legacy API for getting a BluetoothAdapter not + // passing a context + if (mContext != null) { + return mContext.getOpPackageName(); + } + return ActivityThread.currentOpPackageName(); + } + + /** * Start the remote device discovery process. * <p>The discovery process usually involves an inquiry scan of about 12 * seconds, followed by a page scan of each new device to retrieve its @@ -1577,7 +1595,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { - return mService.startDiscovery(); + return mService.startDiscovery(getOpPackageName()); } } catch (RemoteException e) { Log.e(TAG, "", e); diff --git a/core/java/android/bluetooth/BluetoothManager.java b/core/java/android/bluetooth/BluetoothManager.java index e3672a7e064f..e08d405324ea 100644 --- a/core/java/android/bluetooth/BluetoothManager.java +++ b/core/java/android/bluetooth/BluetoothManager.java @@ -67,6 +67,7 @@ public final class BluetoothManager { } // Legacy api - getDefaultAdapter does not take in the context mAdapter = BluetoothAdapter.getDefaultAdapter(); + mAdapter.setContext(context); } /** |