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

Commit 61677938 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioPolicy: catch exceptions on unregister

Make the synchronous AudioManager.unregisterAudioPolicy() method
compatible with situations where the owner of the policy has already
stopped / flushed the tracks or recorders associated with the policy
by catching the IllegalStateException that could be thrown.

Test: atest AudioServiceHostTest#testGetDevicesForAttributes
Change-Id: Ic0ae0732b775a10135f6cbdd31d5e3409e550942
parent a4d4f94e
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -719,9 +719,14 @@ public class AudioPolicy {
                    if (track == null) {
                        break;
                    }
                    try {
                        // TODO: add synchronous versions
                        track.stop();
                        track.flush();
                    } catch (IllegalStateException e) {
                        // ignore exception, AudioTrack could have already been stopped or
                        // released by the user of the AudioPolicy
                    }
                }
            }
            if (mCaptors != null) {
@@ -730,8 +735,13 @@ public class AudioPolicy {
                    if (record == null) {
                        break;
                    }
                    try {
                        // TODO: if needed: implement an invalidate method
                        record.stop();
                    } catch (IllegalStateException e) {
                        // ignore exception, AudioRecord could have already been stopped or
                        // released by the user of the AudioPolicy
                    }
                }
            }
        }