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

Commit b27269e8 authored by jiabin's avatar jiabin Committed by android-build-merger
Browse files

Merge "Avoid race condition when broadcasting device list changed." into pi-dev am: 2914820e

am: ce48867c

Change-Id: I6a5962aec5d3a632547ec20bd06b9c05cd2979fb
parents 1a2a4055 ce48867c
Loading
Loading
Loading
Loading
+21 −19
Original line number Diff line number Diff line
@@ -4718,7 +4718,7 @@ public class AudioManager {
                NativeEventHandlerDelegate delegate =
                        new NativeEventHandlerDelegate(callback, handler);
                mDeviceCallbacks.put(callback, delegate);
                broadcastDeviceListChange(delegate.getHandler());
                broadcastDeviceListChange_sync(delegate.getHandler());
            }
        }
    }
@@ -4837,9 +4837,9 @@ public class AudioManager {

    /**
     * Internal method to compute and generate add/remove messages and then send to any
     * registered callbacks.
     * registered callbacks. Must be called synchronized on mDeviceCallbacks.
     */
    private void broadcastDeviceListChange(Handler handler) {
    private void broadcastDeviceListChange_sync(Handler handler) {
        int status;

        // Get the new current set of ports
@@ -4861,7 +4861,6 @@ public class AudioManager {
            AudioDeviceInfo[] removed_devices =
                    calcListDeltas(current_ports, mPreviousPorts, GET_DEVICES_ALL);
            if (added_devices.length != 0 || removed_devices.length != 0) {
                synchronized (mDeviceCallbacks) {
                for (int i = 0; i < mDeviceCallbacks.size(); i++) {
                    handler = mDeviceCallbacks.valueAt(i).getHandler();
                    if (handler != null) {
@@ -4879,7 +4878,6 @@ public class AudioManager {
                }
            }
        }
        }

        mPreviousPorts = current_ports;
    }
@@ -4890,7 +4888,9 @@ public class AudioManager {
    private class OnAmPortUpdateListener implements AudioManager.OnAudioPortUpdateListener {
        static final String TAG = "OnAmPortUpdateListener";
        public void onAudioPortListUpdate(AudioPort[] portList) {
            broadcastDeviceListChange(null);
            synchronized (mDeviceCallbacks) {
                broadcastDeviceListChange_sync(null);
            }
        }

        /**
@@ -4904,7 +4904,9 @@ public class AudioManager {
         * Callback method called when the mediaserver dies
         */
        public void onServiceDied() {
            broadcastDeviceListChange(null);
            synchronized (mDeviceCallbacks) {
                broadcastDeviceListChange_sync(null);
            }
        }
    }