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

Commit 6dbff25f authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "AudioManager: fix device callbacks when native audio server restarts" into main

parents 0ed1ea97 7a2974c8
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: