Catch the SecurityException in the APIs of SoundTriggerSession to avoid crashing.
Currently when switching the user, it will be possible to meet this kind of issue due to timing factor that the API of SoundTriggerSession was called by previous user and caused the exception "Caller is not the current voice interaction service.". It seems that the flow between switching user and voice interaction needs to be improved to avoid this race condition issue, but the impact will be high. It would be better to catch the exception and return the fail status to caller instead of crashing as a short term solution. Four approaches are considered below: (1) Change state to STATE_INVALID When AlwaysOnHotwordDetector is shutdown, the state will be set to STATE_INVALID. Then all called methods from it will fail with an IllegalStateException. This is a normal behavior that has been defined in the javadoc. But the STATE_INVALID does not clearly indicate what happended in the AlwaysOnHotwordDetector for this issue and what to do next. So it is not the best approach to change the state to STATE_INVALID directly. (2) Use a new state to inform the caller (apply this) Define a new state STATE_ERROR to indicate the unknown active keyphrase availability due to an error. public static final int STATE_ERROR = 3; When the exception occurs, it will pass STATE_ERROR to the caller by the callback API "onAvailabilityChanged(int status)". Then all called methods from it should fail with an IllegalStateException due to AlwaysOnHotwordDetector can not be used currently. The caller should create a new instance after receiving this state. In order to avoid unintended behavior in the application, it would be better to use this approach when the target SDK version is greater than R. (3) Use onError() callback to inform the caller Currently when some errors occurred during Recognition, the onError() callback will be called. But it doesn't mean the caller should stop to using the AlwaysOnHotwordDetector. It is different from what we want that the caller should not use the AlwaysOnHotwordDetector and should create a new instance. So it is not suitable to use the onError() callback to inform the caller due to no error reason in the onError() callback. The caller will not know what happened and what to do next. (4) Create a new onError(int reason) callback to inform the caller In this approach, it will need to create a new onError(int reason) callback to inform the caller. It also needs to change the state of AlwaysOnHotwordDetector, then all called methods from it should fail with an IllegalStateException due to AlwaysOnHotwordDetector can not be used currently. This approach is also fine, but it is very similar to approach 2. Finaly we use the approach 2. Bug: 148136382 Test: atest CtsVoiceInteractionTestCases Test: atest CtsSoundTriggerTestCases Change-Id: I4697a2e6e26d412cf5c985467c652d30586adbe7
Loading
Please register or sign in to comment