Merge "Pass package name as part of startDiscovery"

am: bee9a87193

Change-Id: I30eb9a65e4854eff1539d6d86d3f932675eb2dc2
This commit is contained in:
Zach Johnson
2018-12-13 13:49:20 -08:00
committed by android-build-merger
2 changed files with 20 additions and 1 deletions

View File

@@ -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();
@@ -1540,6 +1541,23 @@ public final class BluetoothAdapter {
return -1;
}
/**
* 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
@@ -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);

View File

@@ -67,6 +67,7 @@ public final class BluetoothManager {
}
// Legacy api - getDefaultAdapter does not take in the context
mAdapter = BluetoothAdapter.getDefaultAdapter();
mAdapter.setContext(context);
}
/**