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

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

Remove ST INTERCEPTED state

We now handle app ops revocations above this layer, so there is no
reason to restart recognition on a model when permissions are lost.

Bug: 272147641
Fixes: 268221628
Test: SoundTriggerManagerTest
Change-Id: I1208cdc5ac1dd6d4f4651e586221cb5e63df5fe0
parent 70fabce7
Loading
Loading
Loading
Loading
+2 −64
Original line number Diff line number Diff line
@@ -264,13 +264,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
            LOADED,
            /** Model is loaded, recognition is active. */
            ACTIVE,
            /**
             * Model is active as far as the client is concerned, but loaded as far as the
             * layers are concerned. This condition occurs when a recognition event that indicates
             * the recognition for this model arrived from the underlying layer, but had not been
             * delivered to the caller (most commonly, for permission reasons).
             */
            INTERCEPTED,
            /**
             * Model has been preemptively unloaded by the HAL.
             */
@@ -483,18 +476,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
                    throw new IllegalStateException("Invalid handle: " + modelHandle);
                }
                // stopRecognition is idempotent - no need to check model state.

                // From here on, every exception isn't client's fault.
                try {
                    // If the activity state is INTERCEPTED, we skip delegating the command, but
                    // still consider the call valid.
                    if (modelState.activityState == ModelState.Activity.INTERCEPTED) {
                        modelState.activityState = ModelState.Activity.LOADED;
                        return;
                    }
                } catch (Exception e) {
                    throw handleException(e);
                }
            }

            // Calling the delegate's stop must be done without the lock.
@@ -518,27 +499,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
            }
        }

        private void restartIfIntercepted(int modelHandle) {
            synchronized (SoundTriggerMiddlewareValidation.this) {
                // State validation.
                if (mState == ModuleStatus.DETACHED) {
                    return;
                }
                ModelState modelState = mLoadedModels.get(modelHandle);
                if (modelState == null
                        || modelState.activityState != ModelState.Activity.INTERCEPTED) {
                    return;
                }
                try {
                    mDelegate.startRecognition(modelHandle, modelState.config);
                    modelState.activityState = ModelState.Activity.ACTIVE;
                    Log.i(TAG, "Restarted intercepted model " + modelHandle);
                } catch (Exception e) {
                    Log.i(TAG, "Failed to restart intercepted model " + modelHandle, e);
                }
            }
        }

        @Override
        public void forceRecognitionEvent(int modelHandle) {
            // Input validation (always valid).
@@ -742,17 +702,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
                    mCallback.onRecognition(modelHandle, event, captureSession);
                } catch (Exception e) {
                    Log.w(TAG, "Client callback exception.", e);
                    synchronized (SoundTriggerMiddlewareValidation.this) {
                        ModelState modelState = mLoadedModels.get(modelHandle);
                        if (event.recognitionEvent.status != RecognitionStatus.FORCED) {
                            modelState.activityState = ModelState.Activity.INTERCEPTED;
                            // If we failed to deliver an actual event to the client, they would
                            // never know to restart it whenever circumstances change. Thus, we
                            // restart it here. We do this from a separate thread to avoid any
                            // race conditions.
                            new Thread(() -> restartIfIntercepted(modelHandle)).start();
                        }
                    }
               }
            }

@@ -771,17 +720,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
                    mCallback.onPhraseRecognition(modelHandle, event, captureSession);
                } catch (Exception e) {
                    Log.w(TAG, "Client callback exception.", e);
                    synchronized (SoundTriggerMiddlewareValidation.this) {
                        ModelState modelState = mLoadedModels.get(modelHandle);
                        if (!event.phraseRecognitionEvent.common.recognitionStillActive) {
                            modelState.activityState = ModelState.Activity.INTERCEPTED;
                            // If we failed to deliver an actual event to the client, they would
                            // never know to restart it whenever circumstances change. Thus, we
                            // restart it here. We do this from a separate thread to avoid any
                            // race conditions.
                            new Thread(() -> restartIfIntercepted(modelHandle)).start();
                        }
                    }
               }
            }