OSDN Git Service

Pass package name as part of startDiscovery
authorZach Johnson <zachoverflow@google.com>
Thu, 13 Dec 2018 01:11:25 +0000 (17:11 -0800)
committerZach Johnson <zachoverflow@google.com>
Thu, 13 Dec 2018 04:33:09 +0000 (20:33 -0800)
Test: manual
Bug: 118347252
Change-Id: Icbc2e7e756b16ffd181924b586a0292c2bf32ec5

core/java/android/bluetooth/BluetoothAdapter.java
core/java/android/bluetooth/BluetoothManager.java

index 654bfaf..10c8b15 100644 (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();
@@ -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);
index e3672a7..e08d405 100644 (file)
@@ -67,6 +67,7 @@ public final class BluetoothManager {
         }
         // Legacy api - getDefaultAdapter does not take in the context
         mAdapter = BluetoothAdapter.getDefaultAdapter();
+        mAdapter.setContext(context);
     }
 
     /**