Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96519288 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Automerger Merge Worker
Browse files

Merge changes from topic "btapiattribution" into sc-dev am: 99555765

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

Change-Id: Icc52110c6291ddc535f691cb647cae0d55f9532f
parents 2b4476ce 99555765
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -23,13 +23,13 @@ import android.annotation.Nullable;
import android.annotation.RequiresNoPermission;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SuppressLint;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
@@ -265,7 +265,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
    @SystemApi
    public static final int DYNAMIC_BUFFER_SUPPORT_A2DP_SOFTWARE_ENCODING = 2;

    private BluetoothAdapter mAdapter;
    private final BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
    private final BluetoothProfileConnector<IBluetoothA2dp> mProfileConnector =
            new BluetoothProfileConnector(this, BluetoothProfile.A2DP, "BluetoothA2dp",
                    IBluetoothA2dp.class.getName()) {
@@ -279,8 +280,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * Create a BluetoothA2dp proxy object for interacting with the local
     * Bluetooth A2DP service.
     */
    /*package*/ BluetoothA2dp(Context context, ServiceListener listener) {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    /* package */ BluetoothA2dp(Context context, ServiceListener listener,
            BluetoothAdapter adapter) {
        mAdapter = adapter;
        mAttributionSource = adapter.getAttributionSource();
        mProfileConnector.connect(context, listener);
    }

@@ -386,7 +389,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
        try {
            final IBluetoothA2dp service = getService();
            if (service != null && isEnabled()) {
                return service.getConnectedDevices();
                return BluetoothDevice.setAttributionSource(
                        service.getConnectedDevices(), mAttributionSource);
            }
            if (service == null) Log.w(TAG, "Proxy not attached to service");
            return new ArrayList<BluetoothDevice>();
@@ -407,7 +411,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
        try {
            final IBluetoothA2dp service = getService();
            if (service != null && isEnabled()) {
                return service.getDevicesMatchingConnectionStates(states);
                return BluetoothDevice.setAttributionSource(
                        service.getDevicesMatchingConnectionStates(states), mAttributionSource);
            }
            if (service == null) Log.w(TAG, "Proxy not attached to service");
            return new ArrayList<BluetoothDevice>();
+11 −5
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
@@ -78,7 +79,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public static final String ACTION_CONNECTION_STATE_CHANGED =
            "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED";

    private BluetoothAdapter mAdapter;
    private final BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
    private final BluetoothProfileConnector<IBluetoothA2dpSink> mProfileConnector =
            new BluetoothProfileConnector(this, BluetoothProfile.A2DP_SINK,
                    "BluetoothA2dpSink", IBluetoothA2dpSink.class.getName()) {
@@ -92,8 +94,10 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     * Create a BluetoothA2dp proxy object for interacting with the local
     * Bluetooth A2DP service.
     */
    /*package*/ BluetoothA2dpSink(Context context, ServiceListener listener) {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    /* package */ BluetoothA2dpSink(Context context, ServiceListener listener,
            BluetoothAdapter adapter) {
        mAdapter = adapter;
        mAttributionSource = adapter.getAttributionSource();
        mProfileConnector.connect(context, listener);
    }

@@ -198,7 +202,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled()) {
            try {
                return service.getConnectedDevices();
                return BluetoothDevice.setAttributionSource(
                        service.getConnectedDevices(), mAttributionSource);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
@@ -221,7 +226,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled()) {
            try {
                return service.getDevicesMatchingConnectionStates(states);
                return BluetoothDevice.setAttributionSource(
                        service.getDevicesMatchingConnectionStates(states), mAttributionSource);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
+26 −20
Original line number Diff line number Diff line
@@ -752,18 +752,23 @@ public final class BluetoothAdapter {

    /**
     * Get a handle to the default local Bluetooth adapter.
     * <p>Currently Android only supports one Bluetooth adapter, but the API
     * could be extended to support more. This will always return the default
     * adapter.
     * <p>
     * Currently Android only supports one Bluetooth adapter, but the API could
     * be extended to support more. This will always return the default adapter.
     * </p>
     *
     * @return the default local adapter, or null if Bluetooth is not supported on this hardware
     * platform
     * @return the default local adapter, or null if Bluetooth is not supported
     *         on this hardware platform
     * @deprecated this method will continue to work, but developers are
     *             strongly encouraged to migrate to using
     *             {@link BluetoothManager#getAdapter()}, since that approach
     *             enables support for {@link Context#createAttributionContext}.
     */
    @Deprecated
    @RequiresNoPermission
    public static synchronized BluetoothAdapter getDefaultAdapter() {
        if (sAdapter == null) {
            sAdapter = createAdapter(ActivityThread.currentAttributionSource());
            sAdapter = createAdapter(BluetoothManager.resolveAttributionSource(null));
        }
        return sAdapter;
    }
@@ -2966,50 +2971,51 @@ public final class BluetoothAdapter {
        }

        if (profile == BluetoothProfile.HEADSET) {
            BluetoothHeadset headset = new BluetoothHeadset(context, listener);
            BluetoothHeadset headset = new BluetoothHeadset(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.A2DP) {
            BluetoothA2dp a2dp = new BluetoothA2dp(context, listener);
            BluetoothA2dp a2dp = new BluetoothA2dp(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.A2DP_SINK) {
            BluetoothA2dpSink a2dpSink = new BluetoothA2dpSink(context, listener);
            BluetoothA2dpSink a2dpSink = new BluetoothA2dpSink(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.AVRCP_CONTROLLER) {
            BluetoothAvrcpController avrcp = new BluetoothAvrcpController(context, listener);
            BluetoothAvrcpController avrcp = new BluetoothAvrcpController(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.HID_HOST) {
            BluetoothHidHost iDev = new BluetoothHidHost(context, listener);
            BluetoothHidHost iDev = new BluetoothHidHost(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.PAN) {
            BluetoothPan pan = new BluetoothPan(context, listener);
            BluetoothPan pan = new BluetoothPan(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.PBAP) {
            BluetoothPbap pbap = new BluetoothPbap(context, listener);
            BluetoothPbap pbap = new BluetoothPbap(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.HEALTH) {
            Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated");
            return false;
        } else if (profile == BluetoothProfile.MAP) {
            BluetoothMap map = new BluetoothMap(context, listener);
            BluetoothMap map = new BluetoothMap(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.HEADSET_CLIENT) {
            BluetoothHeadsetClient headsetClient = new BluetoothHeadsetClient(context, listener);
            BluetoothHeadsetClient headsetClient =
                    new BluetoothHeadsetClient(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.SAP) {
            BluetoothSap sap = new BluetoothSap(context, listener);
            BluetoothSap sap = new BluetoothSap(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.PBAP_CLIENT) {
            BluetoothPbapClient pbapClient = new BluetoothPbapClient(context, listener);
            BluetoothPbapClient pbapClient = new BluetoothPbapClient(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.MAP_CLIENT) {
            BluetoothMapClient mapClient = new BluetoothMapClient(context, listener);
            BluetoothMapClient mapClient = new BluetoothMapClient(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.HID_DEVICE) {
            BluetoothHidDevice hidDevice = new BluetoothHidDevice(context, listener);
            BluetoothHidDevice hidDevice = new BluetoothHidDevice(context, listener, this);
            return true;
        } else if (profile == BluetoothProfile.HEARING_AID) {
            if (isHearingAidProfileSupported()) {
                BluetoothHearingAid hearingAid = new BluetoothHearingAid(context, listener);
                BluetoothHearingAid hearingAid = new BluetoothHearingAid(context, listener, this);
                return true;
            }
            return false;
+11 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint;
import android.annotation.SdkConstant.SdkConstantType;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
@@ -86,7 +87,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    public static final String EXTRA_PLAYER_SETTING =
            "android.bluetooth.avrcp-controller.profile.extra.PLAYER_SETTING";

    private BluetoothAdapter mAdapter;
    private final BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
    private final BluetoothProfileConnector<IBluetoothAvrcpController> mProfileConnector =
            new BluetoothProfileConnector(this, BluetoothProfile.AVRCP_CONTROLLER,
                    "BluetoothAvrcpController", IBluetoothAvrcpController.class.getName()) {
@@ -101,8 +103,10 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
     * Create a BluetoothAvrcpController proxy object for interacting with the local
     * Bluetooth AVRCP service.
     */
    /*package*/ BluetoothAvrcpController(Context context, ServiceListener listener) {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    /* package */ BluetoothAvrcpController(Context context, ServiceListener listener,
            BluetoothAdapter adapter) {
        mAdapter = adapter;
        mAttributionSource = adapter.getAttributionSource();
        mProfileConnector.connect(context, listener);
    }

@@ -131,7 +135,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
                getService();
        if (service != null && isEnabled()) {
            try {
                return service.getConnectedDevices();
                return BluetoothDevice.setAttributionSource(
                        service.getConnectedDevices(), mAttributionSource);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
@@ -153,7 +158,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
                getService();
        if (service != null && isEnabled()) {
            try {
                return service.getDevicesMatchingConnectionStates(states);
                return BluetoothDevice.setAttributionSource(
                        service.getDevicesMatchingConnectionStates(states), mAttributionSource);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
+18 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.ActivityThread;
import android.app.PropertyInvalidatedCache;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresBluetoothLocationPermission;
@@ -48,6 +47,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.UUID;

/**
@@ -1167,13 +1167,29 @@ public final class BluetoothDevice implements Parcelable {

        mAddress = address;
        mAddressType = ADDRESS_TYPE_PUBLIC;
        mAttributionSource = ActivityThread.currentAttributionSource();
        mAttributionSource = BluetoothManager.resolveAttributionSource(null);
    }

    void setAttributionSource(AttributionSource attributionSource) {
        mAttributionSource = attributionSource;
    }

    static BluetoothDevice setAttributionSource(BluetoothDevice device,
            AttributionSource attributionSource) {
        device.setAttributionSource(attributionSource);
        return device;
    }

    static List<BluetoothDevice> setAttributionSource(List<BluetoothDevice> devices,
            AttributionSource attributionSource) {
        if (devices != null) {
            for (BluetoothDevice device : devices) {
                device.setAttributionSource(attributionSource);
            }
        }
        return devices;
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (o instanceof BluetoothDevice) {
Loading