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

Commit 53a722bd authored by Aritra Sen's avatar Aritra Sen Committed by Automerger Merge Worker
Browse files

Merge "Make Phone Policy changes on connection state changes handled via...

Merge "Make Phone Policy changes on connection state changes handled via direct calls routed via adapter service." into main am: 95fcc49a

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2744077



Change-Id: Ia9cf2aabbbd57a9997e23037e95a01cd06090d5d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 846a3f9d 95fcc49a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1282,6 +1282,8 @@ public class A2dpService extends ProfileService {
        }
        mAdapterService.notifyProfileConnectionStateChangeToGatt(
                BluetoothProfile.A2DP, fromState, toState);
        mAdapterService.handleProfileConnectionStateChange(
                BluetoothProfile.A2DP, device, fromState, toState);
        mAdapterService
                .getActiveDeviceManager()
                .profileConnectionStateChanged(BluetoothProfile.A2DP, device, fromState, toState);
+11 −0
Original line number Diff line number Diff line
@@ -6920,6 +6920,17 @@ public class AdapterService extends Service {
        mGattService.notifyProfileConnectionStateChange(profile, fromState, toState);
    }

    /**
     * Handle Bluetooth app state when connection state changes for a given {@code profile}.
     *
     * <p>Currently this function is limited to handling Phone policy but the eventual goal is to
     * move all connection logic here.
     */
    public void handleProfileConnectionStateChange(
            int profile, BluetoothDevice device, int fromState, int toState) {
        mPhonePolicy.profileConnectionStateChanged(profile, device, fromState, toState);
    }

    static int convertScanModeToHal(int mode) {
        switch (mode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
+16 −43
Original line number Diff line number Diff line
@@ -21,14 +21,12 @@ import static com.android.bluetooth.Utils.isDualModeAudioEnabled;
import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.BluetoothVolumeControl;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -91,7 +89,6 @@ class PhonePolicy {
    private static final String TAG = "BluetoothPhonePolicy";

    // Message types for the handler (internal messages generated by intents or timeouts)
    private static final int MESSAGE_PROFILE_CONNECTION_STATE_CHANGED = 1;
    private static final int MESSAGE_CONNECT_OTHER_PROFILES = 3;
    private static final int MESSAGE_ADAPTER_STATE_TURNED_ON = 4;
    private static final int MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED = 5;
@@ -116,6 +113,22 @@ class PhonePolicy {
    private final HashSet<BluetoothDevice> mConnectOtherProfilesDeviceSet = new HashSet<>();
    @VisibleForTesting boolean mAutoConnectProfilesSupported;

    public void profileConnectionStateChanged(
            int profile, BluetoothDevice device, int fromState, int toState) {
        switch (profile) {
            case BluetoothProfile.A2DP:
            case BluetoothProfile.HEADSET:
            case BluetoothProfile.LE_AUDIO:
            case BluetoothProfile.CSIP_SET_COORDINATOR:
            case BluetoothProfile.VOLUME_CONTROL:
                mHandler.post(
                        () -> processProfileStateChanged(device, profile, toState, fromState));
                break;
            default:
                break;
        }
    }

    // Broadcast receiver for all changes to states of various profiles
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
@@ -126,31 +139,6 @@ class PhonePolicy {
                return;
            }
            switch (action) {
                case BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_CONNECTION_STATE_CHANGED,
                            BluetoothProfile.HEADSET, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_CONNECTION_STATE_CHANGED,
                            BluetoothProfile.A2DP, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_CONNECTION_STATE_CHANGED,
                            BluetoothProfile.CSIP_SET_COORDINATOR, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_CONNECTION_STATE_CHANGED,
                            BluetoothProfile.LE_AUDIO, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothVolumeControl.ACTION_CONNECTION_STATE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_CONNECTION_STATE_CHANGED,
                            BluetoothProfile.VOLUME_CONTROL, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED,
                            BluetoothProfile.A2DP, -1, // No-op argument
@@ -203,16 +191,6 @@ class PhonePolicy {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_PROFILE_CONNECTION_STATE_CHANGED: {
                    Intent intent = (Intent) msg.obj;
                    BluetoothDevice device =
                            intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    int prevState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
                    int nextState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
                    processProfileStateChanged(device, msg.arg1, nextState, prevState);
                }
                break;

                case MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED: {
                    Intent intent = (Intent) msg.obj;
                    BluetoothDevice activeDevice =
@@ -249,11 +227,6 @@ class PhonePolicy {
    protected void start() {
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothVolumeControl.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
+2 −0
Original line number Diff line number Diff line
@@ -1056,6 +1056,8 @@ public class CsipSetCoordinatorService extends ProfileService {
            mGroupIdToConnectedDevices.get(groupId).add(device);
            disableCsipIfNeeded(groupId);
        }
        mAdapterService.handleProfileConnectionStateChange(
                BluetoothProfile.CSIP_SET_COORDINATOR, device, fromState, toState);
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -2007,6 +2007,8 @@ public class HeadsetService extends ProfileService {
                .handleHeadsetConnectionStateChanged(device, fromState, toState);
        mAdapterService.notifyProfileConnectionStateChangeToGatt(
                BluetoothProfile.HEADSET, fromState, toState);
        mAdapterService.handleProfileConnectionStateChange(
                BluetoothProfile.HEADSET, device, fromState, toState);
    }

    /**
Loading