diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2021-04-22 12:21:46 -0600 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2021-04-22 12:46:06 -0600 |
| commit | 67d4e1e079033cf5321e43fa70b23b8d00d40f4a (patch) | |
| tree | b11d7468be07a3450ed88482055ceb614c04ea0d /core/java/android/bluetooth/BluetoothManager.java | |
| parent | 557f9e056ee8fb8dddc9a0c05d521bd4191185e3 (diff) | |
Refinement of AttributionSource handling.
Previous CLs had started passing AttributionSource values across
Binder calls inside BluetoothDevice instances, but this can cause
confuse the permission check logic in the future; we should instead
always aim to use the AttributionSource closest to the app making
the call, instead of parceling it.
This change also improves logging to highlight when we're quietly
treating a permission as denied, and when a UID is mismatched.
Bug: 186106084
Test: atest BluetoothInstrumentationTests
Change-Id: I5d3fdb3c573cb9e77474952d8680caa4c4c464eb
Diffstat (limited to 'core/java/android/bluetooth/BluetoothManager.java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothManager.java | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/core/java/android/bluetooth/BluetoothManager.java b/core/java/android/bluetooth/BluetoothManager.java index 2374f1cdc528..69f9a79c7389 100644 --- a/core/java/android/bluetooth/BluetoothManager.java +++ b/core/java/android/bluetooth/BluetoothManager.java @@ -16,19 +16,15 @@ package android.bluetooth; -import android.Manifest; import android.annotation.RequiresFeature; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; -import android.annotation.SuppressLint; import android.annotation.SystemService; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; 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; @@ -66,27 +62,9 @@ public final class BluetoothManager { * @hide */ public BluetoothManager(Context context) { - if (context.getAttributionTag() == 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; - } - } - - // Context is not initialized in constructor - if (mAdapter != null) { - mAdapter.setContext(context); + mAdapter = BluetoothAdapter.createAdapter(); + if (context != null) { + mAdapter.setAttributionSource(context.getAttributionSource()); } } |
