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

Commit 70997784 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: optimize Bluetooth device switch

Add an argument to AudioPolicyManager::setDeviceConnectionState()
to indicate that a device disconnection is part of a disconnect/connect
sequence corresponding to a switch betwen two devices of the same type
(same profile for Bluetooth devices).
This is currently only used for Bluetooth devices.
This allows to skip some of the rerouting operations that normally
happen when a device is disconnected knowing that the route evaluation
will happen again when the new device is connected.

Flag: com.android.media.audio.optimize_bt_device_switch
Bug: 373867402
Test: Bluetooth audio use cases regression
Change-Id: I6db94be4cd16804477ca6b1cbaf46015c06ca8c7
parent 442578ec
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1177,7 +1177,7 @@ void AudioSystem::onNewAudioModulesAvailable() {

status_t AudioSystem::setDeviceConnectionState(audio_policy_dev_state_t state,
                                               const android::media::audio::common::AudioPort& port,
                                               audio_format_t encodedFormat) {
                                               audio_format_t encodedFormat, bool deviceSwitch) {
    const sp<IAudioPolicyService> aps = get_audio_policy_service();

    if (aps == nullptr) return AudioPolicyServiceTraits::getError();
@@ -1188,7 +1188,8 @@ status_t AudioSystem::setDeviceConnectionState(audio_policy_dev_state_t state,
                            legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(state)),
                    port,
                    VALUE_OR_RETURN_STATUS(
                            legacy2aidl_audio_format_t_AudioFormatDescription(encodedFormat))));
                            legacy2aidl_audio_format_t_AudioFormatDescription(encodedFormat)),
                    deviceSwitch));
}

audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device,
+2 −1
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ interface IAudioPolicyService {

    void setDeviceConnectionState(in AudioPolicyDeviceState state,
                                  in android.media.audio.common.AudioPort port,
                                  in AudioFormatDescription encodedFormat);
                                  in AudioFormatDescription encodedFormat,
                                  boolean deviceSwitch);

    AudioPolicyDeviceState getDeviceConnectionState(in AudioDevice device);

+2 −1
Original line number Diff line number Diff line
@@ -304,7 +304,8 @@ public:
    static void onNewAudioModulesAvailable();
    static status_t setDeviceConnectionState(audio_policy_dev_state_t state,
                                             const android::media::audio::common::AudioPort& port,
                                             audio_format_t encodedFormat);
                                             audio_format_t encodedFormat,
                                             bool deviceSwitch);
    static audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
                                                                const char *device_address);
    static status_t handleDeviceConfigChange(audio_devices_t device,
+2 −2
Original line number Diff line number Diff line
@@ -698,13 +698,13 @@ TEST_F(AudioSystemTest, SetDeviceConnectedState) {
        // !!! Instead of the default format, use each format from 'ext.encodedFormats'
        // !!! if they are not empty
        status = AudioSystem::setDeviceConnectionState(AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
                                                       aidlPort, AUDIO_FORMAT_DEFAULT);
                                                       aidlPort, AUDIO_FORMAT_DEFAULT, false);
        EXPECT_EQ(OK, status);
        if (status != OK) continue;
        deviceState = AudioSystem::getDeviceConnectionState(type, address);
        EXPECT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE, deviceState);
        status = AudioSystem::setDeviceConnectionState(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
                                                       aidlPort, AUDIO_FORMAT_DEFAULT);
                                                       aidlPort, AUDIO_FORMAT_DEFAULT, false);
        EXPECT_EQ(OK, status);
        deviceState = AudioSystem::getDeviceConnectionState(type, address);
        EXPECT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, deviceState);
+1 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ public:
    // indicate a change in device connection status
    virtual status_t setDeviceConnectionState(audio_policy_dev_state_t state,
                                              const android::media::audio::common::AudioPort& port,
                                              audio_format_t encodedFormat) = 0;
                                              audio_format_t encodedFormat, bool deviceSwitch) = 0;
    // retrieve a device connection status
    virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
                                                              const char *device_address) = 0;
Loading