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

Commit 7a2974c8 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioManager: fix device callbacks when native audio server restarts

Fix device comparison when creating the list of added or removed devices
in broadcastDeviceListChange_sync(): compare only type and address as
the port ID changes when the native audio server restarts.

Also reload the device port cache when the native audio server death
notification is received in the AudioPortEventHandler instead of doing
it later n the OnAmPortUpdateListener callback.

This avoids sending spurious audio device removed/added callbacks to
clients.

Bug: 378032953
Test: restart audioserver multiple times
Flag: EXEMPT bug fix
Change-Id: I8a36c240be0ab8d5e78e8ae4566412d850cf361e
parent d9f8adde
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -210,6 +210,27 @@ public class AudioDevicePort extends AudioPort {
        return super.equals(o);
    }

    /**
     * Returns true if the AudioDevicePort passed as argument represents the same device (same
     * type and same address). This is different from equals() in that the port IDs are not compared
     * which allows matching devices across native audio server restarts.
     * @param other the other audio device port to compare to.
     * @return true if both device port correspond to the same audio device, false otherwise.
     * @hide
     */
    public boolean isSameAs(AudioDevicePort other) {
        if (mType != other.type()) {
            return false;
        }
        if (mAddress == null && other.address() != null) {
            return false;
        }
        if (!mAddress.equals(other.address())) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        String type = (mRole == ROLE_SOURCE ?
+5 −8
Original line number Diff line number Diff line
@@ -8068,15 +8068,15 @@ public class AudioManager {
            ArrayList<AudioDevicePort> ports_A, ArrayList<AudioDevicePort> ports_B, int flags) {

        ArrayList<AudioDevicePort> delta_ports = new ArrayList<AudioDevicePort>();

        AudioDevicePort cur_port = null;
        for (int cur_index = 0; cur_index < ports_B.size(); cur_index++) {
            boolean cur_port_found = false;
            cur_port = ports_B.get(cur_index);
            AudioDevicePort cur_port = ports_B.get(cur_index);
            for (int prev_index = 0;
                 prev_index < ports_A.size() && !cur_port_found;
                 prev_index++) {
                cur_port_found = (cur_port.id() == ports_A.get(prev_index).id());
                // Do not compare devices by port ID as these change when the native
                // audio server restarts
                cur_port_found = cur_port.isSameAs(ports_A.get(prev_index));
            }

            if (!cur_port_found) {
@@ -8422,12 +8422,9 @@ public class AudioManager {
         * Callback method called when the mediaserver dies
         */
        public void onServiceDied() {
            synchronized (mDeviceCallbacks) {
                broadcastDeviceListChange_sync(null);
           // Nothing to do here
        }
    }
    }


    /**
     * @hide
+9 −11
Original line number Diff line number Diff line
@@ -97,7 +97,6 @@ class AudioPortEventHandler {

                        ArrayList<AudioPort> ports = new ArrayList<AudioPort>();
                        ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>();
                        if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) {
                        int status = AudioManager.updateAudioPortCache(ports, patches, null);
                        if (status != AudioManager.SUCCESS) {
                            // Since audio ports and audio patches are not null, the return
@@ -108,7 +107,6 @@ class AudioPortEventHandler {
                                    RESCHEDULE_MESSAGE_DELAY_MS);
                            return;
                        }
                        }

                        switch (msg.what) {
                        case AUDIOPORT_EVENT_NEW_LISTENER: