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

Commit 872de70b authored by jiabin's avatar jiabin
Browse files

Add prepareToDisconnectExternalDevice.

When an external device is disconnected, some HALs rely on the early
disconnect indication to immediately abort any active read/write
operations on drivers to avoid problems with HW interfaces. In that
case, APM will broadcast the device disconnection before the streams are
closed. However, in AOSP AIDL HAL, the device may not be disconnected
when there are active configurations. In that case, a new way to notify
the HAL to prepare to disconnect external device is required.

Bug: 277955540
Test: atest audiopolicy_tests
Test: connect/disconnect USB device
Change-Id: Ie5868ac5efedb3dbdd8b4c2e3225c0c4085806a1
Merged-In: Ie5868ac5efedb3dbdd8b4c2e3225c0c4085806a1
parent 58e1c4e2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ aidl_interface {
        "aidl/android/media/AudioTimestampInternal.aidl",
        "aidl/android/media/AudioUniqueIdUse.aidl",
        "aidl/android/media/AudioVibratorInfo.aidl",
        "aidl/android/media/DeviceConnectedState.aidl",
        "aidl/android/media/EffectDescriptor.aidl",
        "aidl/android/media/TrackSecondaryOutputInfo.aidl",
        "aidl/android/media/SurroundSoundConfig.aidl",
+4 −4
Original line number Diff line number Diff line
@@ -803,10 +803,10 @@ int32_t AudioFlingerClientAdapter::getAAudioHardwareBurstMinUsec() {
}

status_t AudioFlingerClientAdapter::setDeviceConnectedState(
        const struct audio_port_v7 *port, bool connected) {
        const struct audio_port_v7 *port, media::DeviceConnectedState state) {
    media::AudioPortFw aidlPort = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_port_v7_AudioPortFw(*port));
    return statusTFromBinderStatus(mDelegate->setDeviceConnectedState(aidlPort, connected));
    return statusTFromBinderStatus(mDelegate->setDeviceConnectedState(aidlPort, state));
}

status_t AudioFlingerClientAdapter::setSimulateDeviceConnections(bool enabled) {
@@ -1354,9 +1354,9 @@ Status AudioFlingerServerAdapter::getAAudioHardwareBurstMinUsec(int32_t* _aidl_r
}

Status AudioFlingerServerAdapter::setDeviceConnectedState(
        const media::AudioPortFw& port, bool connected) {
        const media::AudioPortFw& port, media::DeviceConnectedState state) {
    audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPortFw_audio_port_v7(port));
    return Status::fromStatusT(mDelegate->setDeviceConnectedState(&portLegacy, connected));
    return Status::fromStatusT(mDelegate->setDeviceConnectedState(&portLegacy, state));
}

Status AudioFlingerServerAdapter::setSimulateDeviceConnections(bool enabled) {
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.media;

/**
 * {@hide}
 */
@Backing(type="int")
enum DeviceConnectedState {
    CONNECTED = 0,
    DISCONNECTED = 1,
    PREPARE_TO_DISCONNECT = 2,
}
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.media.CreateRecordRequest;
import android.media.CreateRecordResponse;
import android.media.CreateTrackRequest;
import android.media.CreateTrackResponse;
import android.media.DeviceConnectedState;
import android.media.OpenInputRequest;
import android.media.OpenInputResponse;
import android.media.OpenOutputRequest;
@@ -227,7 +228,7 @@ interface IAudioFlingerService {

    int getAAudioHardwareBurstMinUsec();

    void setDeviceConnectedState(in AudioPortFw devicePort, boolean connected);
    void setDeviceConnectedState(in AudioPortFw devicePort, DeviceConnectedState state);

    // Used for tests only. Requires AIDL HAL to work.
    void setSimulateDeviceConnections(boolean enabled);
+6 −3
Original line number Diff line number Diff line
@@ -358,7 +358,8 @@ public:

    virtual int32_t getAAudioHardwareBurstMinUsec() = 0;

    virtual status_t setDeviceConnectedState(const struct audio_port_v7 *port, bool connected) = 0;
    virtual status_t setDeviceConnectedState(const struct audio_port_v7 *port,
                                             media::DeviceConnectedState state) = 0;

    virtual status_t setSimulateDeviceConnections(bool enabled) = 0;

@@ -474,7 +475,8 @@ public:
            std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) override;
    int32_t getAAudioMixerBurstCount() override;
    int32_t getAAudioHardwareBurstMinUsec() override;
    status_t setDeviceConnectedState(const struct audio_port_v7 *port, bool connected) override;
    status_t setDeviceConnectedState(const struct audio_port_v7 *port,
                                     media::DeviceConnectedState state) override;
    status_t setSimulateDeviceConnections(bool enabled) override;
    status_t setRequestedLatencyMode(audio_io_handle_t output,
            audio_latency_mode_t mode) override;
@@ -701,7 +703,8 @@ public:
            std::vector<media::audio::common::AudioMMapPolicyInfo> *_aidl_return) override;
    Status getAAudioMixerBurstCount(int32_t* _aidl_return) override;
    Status getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) override;
    Status setDeviceConnectedState(const media::AudioPortFw& port, bool connected) override;
    Status setDeviceConnectedState(const media::AudioPortFw& port,
                                   media::DeviceConnectedState state) override;
    Status setSimulateDeviceConnections(bool enabled) override;
    Status setRequestedLatencyMode(
            int output, media::audio::common::AudioLatencyMode mode) override;
Loading