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

Commit ce48867c 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

Change-Id: I60801432a37de495e2b2c9282f8c2bfef17aab4d
parents 346c55bd 2914820e
Loading
Loading
Loading
Loading
+21 −19
Original line number Diff line number Diff line
@@ -4717,7 +4717,7 @@ public class AudioManager {
                NativeEventHandlerDelegate delegate =
                        new NativeEventHandlerDelegate(callback, handler);
                mDeviceCallbacks.put(callback, delegate);
                broadcastDeviceListChange(delegate.getHandler());
                broadcastDeviceListChange_sync(delegate.getHandler());
            }
        }
    }
@@ -4836,9 +4836,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
@@ -4860,7 +4860,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) {
@@ -4878,7 +4877,6 @@ public class AudioManager {
                }
            }
        }
        }

        mPreviousPorts = current_ports;
    }
@@ -4889,7 +4887,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);
            }
        }

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