Merge "Revert "Removed BluetoothDevice#prepareToEnterProcess"" am: 168b5655a4 am: a3b55d5079 am: 170597987c

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1869964

Change-Id: I20da6815471e8e19813d16f9785d3238d29e46c1
This commit is contained in:
Treehugger Robot
2021-10-26 16:12:59 +00:00
committed by Automerger Merge Worker
3 changed files with 21 additions and 8 deletions

View File

@@ -1186,6 +1186,11 @@ public final class BluetoothDevice implements Parcelable, Attributable {
mAttributionSource = attributionSource; mAttributionSource = attributionSource;
} }
/** {@hide} */
public void prepareToEnterProcess(@NonNull AttributionSource attributionSource) {
setAttributionSource(attributionSource);
}
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object o) {
if (o instanceof BluetoothDevice) { if (o instanceof BluetoothDevice) {

View File

@@ -62,15 +62,15 @@ public final class BluetoothManager {
private static final String TAG = "BluetoothManager"; private static final String TAG = "BluetoothManager";
private static final boolean DBG = false; private static final boolean DBG = false;
private static AttributionSource sAttributionSource = null; private final AttributionSource mAttributionSource;
private final BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter;
/** /**
* @hide * @hide
*/ */
public BluetoothManager(Context context) { public BluetoothManager(Context context) {
sAttributionSource = resolveAttributionSource(context); mAttributionSource = resolveAttributionSource(context);
mAdapter = BluetoothAdapter.createAdapter(sAttributionSource); mAdapter = BluetoothAdapter.createAdapter(mAttributionSource);
} }
/** {@hide} */ /** {@hide} */
@@ -79,9 +79,6 @@ public final class BluetoothManager {
if (context != null) { if (context != null) {
res = context.getAttributionSource(); res = context.getAttributionSource();
} }
else if (sAttributionSource != null) {
return sAttributionSource;
}
if (res == null) { if (res == null) {
res = ActivityThread.currentAttributionSource(); res = ActivityThread.currentAttributionSource();
} }
@@ -201,8 +198,8 @@ public final class BluetoothManager {
IBluetoothGatt iGatt = managerService.getBluetoothGatt(); IBluetoothGatt iGatt = managerService.getBluetoothGatt();
if (iGatt == null) return devices; if (iGatt == null) return devices;
devices = Attributable.setAttributionSource( devices = Attributable.setAttributionSource(
iGatt.getDevicesMatchingConnectionStates(states, sAttributionSource), iGatt.getDevicesMatchingConnectionStates(states, mAttributionSource),
sAttributionSource); mAttributionSource);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "", e); Log.e(TAG, "", e);
} }

View File

@@ -31,6 +31,7 @@ import android.annotation.SuppressLint;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.app.AppGlobals; import android.app.AppGlobals;
import android.bluetooth.BluetoothDevice;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
@@ -11477,6 +11478,16 @@ public class Intent implements Parcelable, Cloneable {
if (fromProtectedComponent) { if (fromProtectedComponent) {
mLocalFlags |= LOCAL_FLAG_FROM_PROTECTED_COMPONENT; mLocalFlags |= LOCAL_FLAG_FROM_PROTECTED_COMPONENT;
} }
// Special attribution fix-up logic for any BluetoothDevice extras
// passed via Bluetooth intents
if (mAction != null && mAction.startsWith("android.bluetooth.")
&& hasExtra(BluetoothDevice.EXTRA_DEVICE)) {
final BluetoothDevice device = getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device != null) {
device.prepareToEnterProcess(source);
}
}
} }
/** @hide */ /** @hide */