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

Commit 7c65d920 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix modelUnload deadlock" into main

parents c0580e3b 5a1a12bf
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -304,11 +304,17 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
        @Override
        public void unloadModel(int modelHandle) {
            synchronized (SoundTriggerModule.this) {
                int sessionId;
                checkValid();
                sessionId = mLoadedModels.get(modelHandle).unload();
                mAudioSessionProvider.releaseSession(sessionId);
                final var session = mLoadedModels.get(modelHandle).getSession();
                mLoadedModels.remove(modelHandle);
                mAudioSessionProvider.releaseSession(session.mSessionHandle);
            }
            // We don't need to post-synchronize on anything once the HAL has finished the unload
            // and dispatched any appropriate callbacks -- since we don't do any state checking
            // onModelUnloaded regardless.
            // This is generally safe since there is no post-condition on the framework side when
            // a model is unloaded. We assume that we won't ever have a modelHandle collision.
            mHalService.unloadSoundModel(modelHandle);
        }

        @Override
@@ -402,6 +408,10 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
                return mState;
            }

            private SoundTriggerMiddlewareImpl.AudioSessionProvider.AudioSession getSession() {
                return mSession;
            }

            private void setState(@NonNull ModelState state) {
                mState = state;
                SoundTriggerModule.this.notifyAll();
@@ -426,16 +436,6 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
                return mHandle;
            }

            /**
             * Unloads the model.
             * @return The audio session handle.
             */
            private int unload() {
                mHalService.unloadSoundModel(mHandle);
                mLoadedModels.remove(mHandle);
                return mSession.mSessionHandle;
            }

            private IBinder startRecognition(@NonNull RecognitionConfig config) {
                if (mIsStopping == true) {
                    throw new RecoverableException(Status.INTERNAL_ERROR, "Race occurred");