summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jean-Michel Trivi <jmtrivi@google.com> 2020-01-13 13:47:31 -0800
committer Jean-Michel Trivi <jmtrivi@google.com> 2020-01-13 13:47:31 -0800
commit61677938c47ad753bdfebf05be2e94e0b46f0bbc (patch)
treeaee12fa44f27100ae9a9a693051ee8e61e505604
parenta4d4f94e21757148153711a2defe21bd45dc3337 (diff)
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
-rw-r--r--media/java/android/media/audiopolicy/AudioPolicy.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/media/java/android/media/audiopolicy/AudioPolicy.java b/media/java/android/media/audiopolicy/AudioPolicy.java
index 01f12500b77b..27f02fe528f3 100644
--- a/media/java/android/media/audiopolicy/AudioPolicy.java
+++ b/media/java/android/media/audiopolicy/AudioPolicy.java
@@ -719,9 +719,14 @@ public class AudioPolicy {
if (track == null) {
break;
}
- // TODO: add synchronous versions
- track.stop();
- track.flush();
+ 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;
}
- // TODO: if needed: implement an invalidate method
- record.stop();
+ 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
+ }
}
}
}