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

Commit 3e14c032 authored by Felix Oghina's avatar Felix Oghina
Browse files

[speech] unbind from recognition service

Currently, we only remove the service reference, but rely on the timeout
built into `ServiceConnector` to actually unbind. This is causing a
service leak.

We also move `SpeechRecognizer#destroy()` to be handled on the Handler
(just like all other calls) in order to fix racing.

Bug: 313604307
Bug: 311124261
Test: cts

Change-Id: I5384916da98b286f869a32857079087105ca32f9
parent 2232a502
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -206,22 +206,16 @@ final class RemoteSpeechRecognitionService extends ServiceConnector.Impl<IRecogn
        synchronized (mLock) {
            ClientState clientState = mClients.get(listener.asBinder());

            if (clientState == null) {
                if (DEBUG) {
                    Slog.w(TAG, "#cancel called with no preceding #startListening - ignoring.");
                }
                return;
            }
            if (clientState != null) {
                clientState.mRecordingInProgress = false;

            // Temporary reference to allow for resetting the hard link mDelegatingListener to null.
                // Temporary reference to allow for resetting mDelegatingListener to null.
                final IRecognitionListener delegatingListener = clientState.mDelegatingListener;
                run(service -> service.cancel(delegatingListener, isShutdown));
            }

            // If shutdown, remove the client info from the map. Unbind if that was the last client.
            if (isShutdown) {
                removeClient(listener);

                if (mClients.isEmpty()) {
                    if (DEBUG) {
                        Slog.d(TAG, "Unbinding from the recognition service.");