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

Commit e1468a87 authored by Atneya Nair's avatar Atneya Nair
Browse files

[soundtrigger] Move audio session out of lock

Similar to I67b8b2ee484be7c7aefb26d9df64689e5e3f5d00 --

Acquiring audio session holds the STM lock -> APS lock -> Aflinger lock,
which can be blocked by calls into the audio HAL. Since the HAL also
calls back to the ST fwk synchronously (which grabs the STM lock) this
can cross deadlock.

Again, as a spot fix, pull this call out of the lock, which is fine,
since there is no atomicity required between ST and APM, as the audio
session is simply a set of allocated port ids. The STM lock should be
dropped as we call higher up, so we shouldn't deadlock on a higher level
lock either.

Test: manual assistant hotword
Test: manual now playing
Flag: EXEMPT bugfix
Bug: 391620601
Change-Id: I052e3b58925bde088d9df9d1d37f7c775dcd89c0
parent 8c4f5b3f
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -135,8 +135,6 @@ to call another module, while having its local mutex(es) held:
    changed while the lock has been released.
  - Release the local lock.
  - Invoke any synchronous callbacks if needed.
- Calling from `SoundTriggerMiddlewareImpl` / `SoundTriggerModule` into the audio policy service via
  `acquireSession()` / `releaseSession()` while holding the local lock is legal.
- `setCaptureState()` calls, originating from Audio Policy Service, into the lower layers of the
  stack may call into the HAL (specifically, they must invoke `stopRecognition()`, but must not
  block on callbacks. For this reason, `SoundTriggerHw2ConcurrentCaptureHandler`, which is the
+2 −4
Original line number Diff line number Diff line
@@ -257,10 +257,9 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo

        @Override
        public int loadModel(@NonNull SoundModel model) {
            SoundTriggerMiddlewareImpl.AudioSessionProvider.AudioSession audioSession = null;
            final var audioSession = mAudioSessionProvider.acquireSession();
            try {
                synchronized (SoundTriggerModule.this) {
                    audioSession = mAudioSessionProvider.acquireSession();
                    checkValid();
                    Model loadedModel = new Model();
                    return loadedModel.load(model, audioSession);
@@ -279,10 +278,9 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo

        @Override
        public int loadPhraseModel(@NonNull PhraseSoundModel model) {
            SoundTriggerMiddlewareImpl.AudioSessionProvider.AudioSession audioSession = null;
            final var audioSession = mAudioSessionProvider.acquireSession();
            try {
                synchronized (SoundTriggerModule.this) {
                    audioSession = mAudioSessionProvider.acquireSession();
                    checkValid();
                    Model loadedModel = new Model();
                    int result = loadedModel.load(model, audioSession);