Loading services/voiceinteraction/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java +2 −64 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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. Loading @@ -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). Loading Loading @@ -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(); } } } } Loading @@ -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(); } } } } Loading Loading
services/voiceinteraction/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java +2 −64 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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. Loading @@ -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). Loading Loading @@ -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(); } } } } Loading @@ -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(); } } } } Loading