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

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

Merge changes If4b3e3bd,I998246f8 into main am: f0c67c32

parents fd17787d f0c67c32
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -1153,10 +1153,7 @@ public class A2dpService extends ProfileService {
            mFactory.getAvrcpTargetService().handleA2dpActiveDeviceChanged(device);
        }

        mAdapterService
                .getActiveDeviceManager()
                .profileActiveDeviceChanged(BluetoothProfile.A2DP, device);
        mAdapterService.getSilenceDeviceManager().a2dpActiveDeviceChanged(device);
        mAdapterService.handleActiveDeviceChange(BluetoothProfile.A2DP, device);

        BluetoothStatsLog.write(BluetoothStatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED,
                BluetoothProfile.A2DP, mAdapterService.obfuscateAddress(device),
+1 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
     * Called when active state of audio profiles changed
     *
     * @param profile The Bluetooth profile of which active state changed
     * @param device The device currently activated. {@code null} if no A2DP device activated
     * @param device The device currently activated. {@code null} if no device is active
     */
    public void profileActiveDeviceChanged(int profile, BluetoothDevice device) {
        switch (profile) {
+7 −0
Original line number Diff line number Diff line
@@ -6931,6 +6931,13 @@ public class AdapterService extends Service {
        mPhonePolicy.profileConnectionStateChanged(profile, device, fromState, toState);
    }

    /** Handle Bluetooth app state when active device changes for a given {@code profile}. */
    public void handleActiveDeviceChange(int profile, BluetoothDevice device) {
        mActiveDeviceManager.profileActiveDeviceChanged(profile, device);
        mSilenceDeviceManager.profileActiveDeviceChanged(profile, device);
        mPhonePolicy.profileActiveDeviceChanged(profile, device);
    }

    static int convertScanModeToHal(int mode) {
        switch (mode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
+10 −37
Original line number Diff line number Diff line
@@ -19,12 +19,8 @@ package com.android.bluetooth.btservice;
import static com.android.bluetooth.Utils.isDualModeAudioEnabled;

import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
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.content.BroadcastReceiver;
@@ -91,7 +87,6 @@ class PhonePolicy {
    // Message types for the handler (internal messages generated by intents or timeouts)
    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;
    private static final int MESSAGE_DEVICE_CONNECTED = 6;

    @VisibleForTesting static final String AUTO_CONNECT_PROFILES_PROPERTY =
@@ -129,6 +124,16 @@ class PhonePolicy {
        }
    }

    /**
     * Called when active state of audio profiles changed
     *
     * @param profile The Bluetooth profile of which active state changed
     * @param device The device currently activated. {@code null} if no A2DP device activated
     */
    public void profileActiveDeviceChanged(int profile, BluetoothDevice device) {
        mHandler.post(() -> processActiveDeviceChanged(device, profile));
    }

    // Broadcast receiver for all changes to states of various profiles
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
@@ -139,26 +144,6 @@ class PhonePolicy {
                return;
            }
            switch (action) {
                case BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED,
                            BluetoothProfile.A2DP, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED,
                            BluetoothProfile.HEADSET, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED,
                            BluetoothProfile.HEARING_AID, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED:
                    mHandler.obtainMessage(MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED,
                            BluetoothProfile.LE_AUDIO, -1, // No-op argument
                            intent).sendToTarget();
                    break;
                case BluetoothAdapter.ACTION_STATE_CHANGED:
                    // Only pass the message on if the adapter has actually changed state from
                    // non-ON to ON. NOTE: ON is the state depicting BREDR ON and not just BLE ON.
@@ -191,14 +176,6 @@ class PhonePolicy {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED: {
                    Intent intent = (Intent) msg.obj;
                    BluetoothDevice activeDevice =
                            intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    processActiveDeviceChanged(activeDevice, msg.arg1);
                }
                break;

                case MESSAGE_CONNECT_OTHER_PROFILES: {
                    // Called when we try connect some profiles in processConnectOtherProfiles but
                    // we send a delayed message to try connecting the remaining profiles
@@ -229,10 +206,6 @@ class PhonePolicy {
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
        filter.addAction(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED);
        filter.addAction(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED);
        mAdapterService.registerReceiver(mReceiver, filter);
    }

+19 −18
Original line number Diff line number Diff line
@@ -76,6 +76,25 @@ public class SilenceDeviceManager {
    private static final int ENABLE_SILENCE = 0;
    private static final int DISABLE_SILENCE = 1;

    /**
     * Called when active state of audio profiles changed
     *
     * @param profile The Bluetooth profile of which active state changed
     * @param device The device currently activated. {@code null} if no device is active
     */
    public void profileActiveDeviceChanged(int profile, BluetoothDevice device) {
        switch (profile) {
            case BluetoothProfile.A2DP:
                mHandler.obtainMessage(MSG_A2DP_ACTIVE_DEVICE_CHANGED, device).sendToTarget();
                break;
            case BluetoothProfile.HEADSET:
                mHandler.obtainMessage(MSG_HFP_ACTIVE_DEVICE_CHANGED, device).sendToTarget();
                break;
            default:
                break;
        }
    }

    /**
     * Called when A2DP connection state changed by A2dpService
     *
@@ -88,15 +107,6 @@ public class SilenceDeviceManager {
                .sendToTarget();
    }

    /**
     * Called when A2DP active device changed by A2dpService
     *
     * @param device The device currently activated. {@code null} if no A2DP device activated
     */
    public void a2dpActiveDeviceChanged(BluetoothDevice device) {
        mHandler.obtainMessage(MSG_A2DP_ACTIVE_DEVICE_CHANGED, device).sendToTarget();
    }

    /**
     * Called when HFP connection state changed by HeadsetService
     *
@@ -109,15 +119,6 @@ public class SilenceDeviceManager {
                .sendToTarget();
    }

    /**
     * Called when HFP active device is changed by HeadsetService
     *
     * @param device The device currently activated. {@code null} if no HFP device activated
     */
    public void hfpActiveDeviceChanged(BluetoothDevice device) {
        mHandler.obtainMessage(MSG_HFP_ACTIVE_DEVICE_CHANGED, device).sendToTarget();
    }

    class SilenceDeviceManagerHandler extends Handler {
        SilenceDeviceManagerHandler(Looper looper) {
            super(looper);
Loading