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 | 4e4c9c4796c2c16d32e87417e084a1f724e9f258 (patch) | |
tree | ea2cfe356abb388e59a0eea879d45f9360f2c26b /framework/java/android/bluetooth/BluetoothManager.java | |
parent | d4e014e265ca543ad8d6d277cacbfafdb799db6f (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 'framework/java/android/bluetooth/BluetoothManager.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothManager.java | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/framework/java/android/bluetooth/BluetoothManager.java b/framework/java/android/bluetooth/BluetoothManager.java index 2374f1cdc5..69f9a79c73 100644 --- a/framework/java/android/bluetooth/BluetoothManager.java +++ b/framework/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()); } } |