summaryrefslogtreecommitdiff
path: root/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java
Commit message (Collapse)AuthorAgeFilesLines
* Wait for an abort event when stopping a modelYtai Ben-Tsvi2022-04-111-19/+28
| | | | | | | | | | | | | | | | | | Because the client callbacks from SoundTriggerMiddleware service are async, if a client quickly stops and starts a model, then receives a detection event for that model, it is impossible for it to tell whether the event corresponding to the previous or current session, and thus is unable to reason about the resulting state of the model. To mitigate that, we will always wait for an abort event when a model is stopped before any other operation is attempted. This way the model state stays synchronized. Bug: 191935600 Fixes: 226926627 Test: Manual verification of soundtrigger use-cases. Specifically, quick toggling of Assitant and Now Playing via Settings. Change-Id: Ia1b91e78aa6981a7b3612ae9213af1b37a333d00
* Revert "Wait for an abort event when stopping a model"Ytai Ben-Tsvi2022-04-111-53/+29
| | | | | | | | | | | | | | | | | | | | | | This reverts commit 6e2eb81ac4687ac5340673ff996c0591154def7f. The original commit fixed b/223922855, which resulted from fixing b/191935600, but created another. Blocking the stop() call until the event confirming the stop arrives is a bad idea, since: - We have to give up the lock when waiting for the event, and thus lose the atomicity of some of the operations. b/226926627 is an example of this. - It turns out some of the forward calls happen from the main thread's looper, which is also used for callbacks, and we risk deadlocks. A follow-up commit will address the fix in a better way. Bug: 191935600 Bug: 226926627 Bug: 223922855 Test: See next commit in the chain. Change-Id: I2b9987ae93803d3b4f72a1df56c88e284bed43c5
* Check for null callbackYtai Ben-Tsvi2022-03-211-1/+4
| | | | | | | | | | | The modelData callback may be nullified before actually being invoked, e.g. when calling startRecognition() on an already running model, with a different callback. Fixes: 225768984 Test: Manual reproduction on the issue and then applying the fix and verifying that it works. Change-Id: I089061123c8cf12eef19fdf16bb3a2c106ea2438
* Wait for an abort event when stopping a modelYtai Ben-Tsvi2022-03-171-29/+53
| | | | | | | | | | | | | | | | | | | Because the client callbacks from SoundTriggerMiddleware service are async, if a client quickly stops and starts a model, then receives a detection event for that model, it is impossible for it to tell whether the event corresponding to the previous or current session, and thus is unable to reason about the resulting state of the model. To mitigate that, we will always wait for an abort event when a model is stopped before any other operation is attempted. This way the model state stays synchronized. Fixes: 191935600 Test: Manual verification of soundtrigger use-cases. Specifically, quick toggling of Assitant and Now Playing via Settings. Change-Id: I010558e8fa1891922f20dcdb7b0ca04c9500c2e1
* Support back-to-back soundtrigger recognitionsYtai Ben-Tsvi2021-10-181-2/+2
| | | | | | | | | | | | | | | | | | | This change allows the HAL driver, at its discretion, indicate that recognition is still active after a success event. This is achieved by an additional flag added to the event. The behavior to support this case has already been in place, for the sake of supporting a FORCED event. This change just generalizes this behavior to be able to cover SUCCESS as well. For b/w compat, when the status is FORCED, we override the new flag with 'true', indicating that recognition is still active. We do not allow the flag to be set for status codes other than FORCED or SUCCESS. Test: atest FrameworksServicesTests:{SoundTriggerMiddlewareImplTest,SoundHw2CompatTest} Test: Manual verification of sound trigger operation by invoking the assistant and now playing multiple times. Bug: 186031938 Change-Id: Ie4edf82607c72ccb0b8d90a828b04c93153ec8f3
* Merge "Reduce severity of SoundTriggerService error messages" into sc-dev ↵Ytai Ben-tsvi2021-04-011-1/+1
|\ | | | | | | | | | | | | | | am: 322aa5763b Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14056378 Change-Id: Ib999f1ff8943394b7df160b7c759346ebe35b3de
| * Reduce severity of SoundTriggerService error messagesYtai Ben-Tsvi2021-03-311-1/+1
| | | | | | | | | | | | | | | | Errors resulting from misuse by the client are considered warnings. Test: Compiles Bug: 181269159 Change-Id: Ib81397706a137a41f12810b8b63548170ce855bc
* | Adopt "resourcesAvailable" naming instead of "tryAgain"Ytai Ben-Tsvi2021-03-051-4/+4
| | | | | | | | | | | | Test: Compiles Bug: 178722883 Change-Id: I13c983ae34d33f616677280eb856c17fb5c69ed8
* | Support preemptive model unloadingYtai Ben-Tsvi2021-03-051-26/+17
|/ | | | | | | | | This change plumbs soundtrigger preemptive model unloading, typically initiated by the STHAL, all the way to SoundTriggerService, where logic for retry / lazy loading already exists. Test: Manual verification of existing soundtrigger use-cases. Change-Id: I49195fbf2ccd6268e7fbc0279ec6fe04c1cc016e
* add API for ST clients run in battery saver modeNicholas Ambur2021-01-221-57/+99
| | | | | | | | | | | | | | | | | | | | | New system API interface for both SoundTriggerManager and AlwaysOnHotwordDetector to indicate if a recognition should run in battery saver mode or not. Clients supply this information through the existing startRecognition calls, and the client must hold a new privledged permission, SOUND_TRIGGER_RUN_IN_BATTERY_SAVER, to indicate this intention. As a prerequisite, the device PowerManagerService must have the SoundTrigger service enabled in the battery saver mode battery policy. If not enabled, recognition will be paused as if the client did not provide the indication to run in battery saver mode. Bug: 172294448 Test: build with Google search apk using this feature and verify recognition keeps running in battery saver mode Change-Id: Ia43be99290e6fd7c50ff8e4908d6c60ea513b19a
* Reset mServiceDisabled when service diesYtai Ben-Tsvi2020-12-081-0/+1
| | | | | | | | | | When we don't reset the state, if the service died while it was disabled, future attempts to load models would fail. Fixes: 171953855 Test: Verified basic sound trigger cases as well as recovery from STHAL and audioserver crashes. Change-Id: I32929123aa936cbee3101ec0ef65c52dd28b240b
* fix issue with ST listModules checkNicholas Ambur2020-11-181-8/+26
| | | | | | | | | | | | SoundTrigger.listModules call was being passed to the SoundTrigger HAL without SoundTriggerMiddleware checking permissions against the client. Instead, client was checking permissions against the system service UID. Bug: 171342256 Test: verify `dumpsys soundtrigger_middleware` logs listmodules as being called by the SoundTrigger client session Change-Id: Ic4bef05f59ef3d13ab0eed16017275070513ec84
* Clean up on client death in SoundTriggerServiceYtai Ben-Tsvi2020-11-111-1/+20
| | | | | | | | | This change adds tracking of SoundTriggerService client death and frees up resources whenever that happens. Test: Kill Now Playing process and observer recovery. Bug: 171026874 Change-Id: Ie31d0a3ed392b1513b4e81ec3c344f4e79adcf52
* Tighten up Binder.clearCallingIdentity() usage.Jeff Sharkey2020-10-061-2/+2
| | | | | | | | | | | | | | | | | | | | The recently added AndroidFrameworkBinderIdentity Error Prone checker examines code to ensure that any cleared identities are restored to avoid obscure security vulnerabilities. This change is a purely mechanical refactoring that adds the "final" keyword to the cleared identity to ensure that it's not accidentally modified before eventually being cleared. Here's the exact command used to generate this CL: $ find . -name "*.java" -exec sed -Ei \ 's/ (long \w+ = .+?clearCallingIdentity)/ final \1/' \ {} \; Bug: 155703208 Test: make Exempt-From-Owner-Approval: trivial refactoring Change-Id: I832c9d70c3dfcd8d669cf71939d97837becc973a
* Sessionize the SoundTriggerService layer.Ytai Ben-Tsvi2020-09-101-1/+6
| | | | | | | | This changes associates identity information with every SoundTrigerService session. Change-Id: I30c9177f21203c8f3d03d4ff31523137497e760b Bug: 163865561
* Require identity information in SoundTrigger.javaYtai Ben-Tsvi2020-09-101-2/+9
| | | | | | | | | | Deprecate the way to attach to SoundTrigger that doesn't include identity information. Plumb that up to the SoundTriggerService layer, where it is temporarily provided in a backward-compatible way instead of with the actual identity. Change-Id: Icc2bf3b80300bd2b75c81d253986b4e1582737ca Bug: 163865561
* SoundTriggerHelper: improve in call behaviorEric Laurent2020-04-061-50/+108
| | | | | | | | | | | | | | | | | | | Fix 3 issues in SoundTriggerHelper when a call is active: 1) Do not actually load a sound model when recognition start is requested but disabled because of and active call or any other reason. Previously we were loading the sound model even if actual start was deferred until enabled. 2) Allow to start recognition while disabled: the recognition start request is stored as pending and will be executed when enabled again. 3) Process call state change with enough delay when call ends to allow time for the HAL to process the call disconnect notification before re enabling pending recognitions. Also remove assumption on valid model handle values. Test: repro steps in b/152723355 Bug: 152723355 Change-Id: Id46ae8c285426ed2ace8a6d80478fecb98f4ec33
* remove SoundTrigger public member variablesNicholas Ambur2020-03-261-3/+3
| | | | | | | Bug: 150127026 Test: boot and verify soundtrigger hotword is functional Change-Id: I04061cdb3eba02aac0f08de96f957e2b74c70a12
* Correctly set the recognition state in response to GET_STATEYtai Ben-Tsvi2020-01-141-2/+6
| | | | | | | | | | A forced recognition does not stop recognition. SoundTriggerHelper had a bug where it assumed that it does, and so future interactions would assume the wrong state and would eventually erroneously use the underlying layers. Bug: 147568295 Change-Id: I5ae69a8b292fda6aadc6011c4bf5cbc4d263a1ca
* add parameter control to AlwaysOnHotwordDetectorNicholas Ambur2020-01-091-42/+68
| | | | | | | | | | Per-model control to AlwaysOnHotwordDetector interface. Models are selected by keyphrase and locale associated with the AlwaysOnHotwordDetector instance. Bug: 141929369 Test: tested manually with test app Change-Id: Iffeb0954059fa030d8a4fefb934a3e665323be37
* add SoundTrigger HAL 2.3 per model parameter apisNicholas Ambur2019-12-111-6/+71
| | | | | | | | | | add support for model parameter control APIs with THRESHOLD_FACTOR as the first supported parameter Bug: 141929369 Test: Tested manually with test app and confirmed with GTS test gts-tradefed run gts-dev -m GtsAssistIntentTestCases Change-Id: I06874fcf2ae2ef8796e7c52c4475252e8a026e2c
* SoundTriggerHelper: fix state after audioserver deathEric Laurent2019-09-121-3/+30
| | | | | | | | | | | | | | | | Make sure mRecognitionRequested is reset when a failure condition disables all recognitions: A stale value would prevent from registering call and power state listeners and properly update the states. Also: - In isRecognitionAllowed(), read current call and power states directly from services if listeners are not registered. - Also add missing null checks on mModule at various places. Bug: 139268184 Test: repro steps in the bug Change-Id: I763130b4d491a1a6a9e0756c7a18943e406ce73e
* SoundTriggerHelper: fix power save mode listenerEric Laurent2019-07-191-18/+21
| | | | | | | | | | | When stopping a recognition, do not unregister power save mode listener if no recognition is active any more but only if no recognition is requested. Otherwise recognitions suspended due to power save mode will never resume. Bug: 136978230 Test: Activate power save mode, plug USB and verify OK G works. Change-Id: I426e11447fcde5c578ae2f64aa1fe18ef00fba0f
* Enabling HW detection while phone ringingrago2019-03-261-2/+2
| | | | | | | | | Updated logic to allow HotWord detection while phone is ringing (still not off-hook). Test: Manual Testing Bug: 124762676 Change-Id: Idce6d39a5589aee6d5baa4e5bcd8d98b3e13b239
* Make framework treat getModelState recognition events the samemike dooley2019-01-081-6/+3
| | | | | | | | | | | | | as regular recogntion events The application will differentiate between DSP and app triggered regcognition events. Test: manual test with STTA and NowPlaying app on p19 Bug: 119386757 Change-Id: I4a3eb4da6ee6be35084fec8aaa3c495423d74033
* Fixing getModelState event processingmike dooley2018-12-201-3/+10
| | | | | | | | Test: manual testing with SoundTriggerTestApp Bug: 119386757 Change-Id: I2c2960d169b119cb35345315638eeae28460896c
* Converting sound trigger v2.2 getModelState to be asynchronousmike dooley2018-11-091-12/+9
| | | | | | | Test: built android with checkbuild flag Change-Id: I4c6f2388c93b6e577113fc7f2cd19242628ee50f Bug-Id: 70206501
* Revert "Revert "Adding getModelState API to sound trigger""Michael Dooley2018-10-231-0/+34
| | | | | | | | This reverts commit 81f71f1c27b7e877babe1f3293ac00256a66980c. Reason for revert: rolling forward with fix Change-Id: Ifc0c53581ac567cb968d91993f453220f8253aec
* Revert "Revert "Revert "Adding getModelState API to sound trigger"""Michael Dooley2018-09-281-34/+0
| | | | | | | | This reverts commit 7999836ee3c0da85b3e8b55d0113d0b9796b3d21. Reason for revert: broke build Change-Id: Id02636908aed26ee0ed38042da1ace0125a6d417
* Revert "Revert "Adding getModelState API to sound trigger""Michael Dooley2018-09-211-0/+34
| | | | | | | | This reverts commit 81f71f1c27b7e877babe1f3293ac00256a66980c. Reason for revert: undoing rollback Change-Id: Ifddfd0c730f03e93788d662a392d538564ce210b
* Revert "Adding getModelState API to sound trigger"Michael Dooley2018-09-141-34/+0
| | | | | | | | This reverts commit 4f809fe73ee94802ac473b87c0d47a7345244d5a. Reason for revert: fix build breakage Change-Id: I75a54189f96fc21f6cb12dd8a05e513b1bda027c
* Adding getModelState API to sound triggermike dooley2018-09-051-0/+34
| | | | | | Test: built android Bug-Id: 70206501 Change-Id: Ieb83a366d4ddd471186d5089efe0675ea6285454
* Fixing a couple crashes in the SoundTriggerTestAppmike dooley2018-04-191-1/+6
| | | | | | Bug: 78269975 Test: built and ran the SoundTriggerTestApp Change-Id: I966550a3d64e9f6a66c40e062a89f39b897aaea2
* Merge "Check for location access on TelephonyRegistry" am: 31230bb193 am: ↵Hall Liu2018-02-221-14/+20
|\ | | | | | | | | | | | | | | f581580fdb am: 9b31dd86da Change-Id: Icd2feab82a9350fa2b6539617863ad91a44e5208
| * Check for location access on TelephonyRegistryHall Liu2018-02-061-14/+20
| | | | | | | | | | | | | | | | | | | | When sending outbound callbacks on CELL_INFO and CELL_LOCATION, check to make sure that the user has authorized us and the receiving app to get information on their location. Bug: 69637693 Test: manual: telephony testapp Change-Id: Iacfc894428b11a7ec973567d7a797eedb281355f
* | Make the battery saver knobs hidden public,Makoto Onuki2017-11-011-1/+1
|/ | | | | | | | so other components (system UI, settings, etc) can use them. Bug: 68769804 Test: Build & presubmit Change-Id: I30fe78e49d2187bee7c7aeba735cd9c26fc332a5
* Add SoundTriggerManager APIs to use a PendingIntent to get callbacks.Chris Thornton2017-06-131-0/+7
| | | | | | Test: APIs exercised using a special test app not in this CL. Change-Id: I99425d1e67a778513e6c75e7d595c072032aa2ab
* Prevent ConcurrentModificationException in updateAllRecognitionsChris Thornton2017-06-101-18/+20
| | | | | | | | | | | | | | | | | | | When invoking updateAllRecognitions, if a callback binder was determined to have died, an internal function would go and remove it from mModelDataMap. However, updateAllRecognitions was iterating over this map, so it would then explode. By first making a copy of the model datas before iterating over all of them, this problem is avoided. (As part of trying to figure out what was happening, also updated all the method names that implicitly assumed they had a lock, and double checked that everything with a Locked suffix is actually locked) Bug: 62487479 Test: Use the sound trigger test app to load and start two models, force kill the app (so the dangling binders hang around), then enable power save (which triggers the call to updateAllRecognitions) Change-Id: I87b9dfc1b2af5e294050b146737916ccaad882c1
* SoundTriggerHelper: Remove unused models onLoadChris Thornton2017-03-271-2/+49
| | | | | | | | | | | | | | | | If some process tries to start a recognition, the STH will now check to see if there are any other models that have been loaded and either: - Have a callback that's died (determined by pinging the binder) - Don't have a callback at all (meaning they didn't clean up after the last detection and didn't start it again). If it finds such a model, it will be stopped and unloaded, freeing up resources in the HAL. Test: Manually load model/kill the process and make sure that it is unloaded the next time some other model is loaded. Also made sure running models aren't evicted. Change-Id: Ia1139b47afe5f88102a3773d90f4f056ea3cdc92
* Clean up dead objects when detected in the SoundTriggerHelperChris Thornton2017-03-221-11/+62
| | | | | | | | | | | | | If an app has died while being connected to the sound trigger helper/the binder goes away, we should stop and unload the model since there's no way to get a handle on it again (without reloading the same UUID at some point). Test: Force stop the SoundTriggerTestApp while it has a model started, trigger the sound model, then watch it get unloaded when the helper notices that the binder is dead. Change-Id: Iddfaaa03482d56e71f23e5982d4bd579f386b51d
* Add BatterySaverPolicy for power save modejackqdyulei2017-03-081-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | The BatterySaverPolicy is designed to consolidate all battery saver knobs into a central location. Usually it is consistent to mLowPowerModeEnabled unless it gets different data for specific service. By adding these knobs, we can effectively tune the battery saver. This cl sets up the framework for BatterySaverPolicy and updates following service to get battery saver data from BatterySaverPolicy 1. GnssLocationProvider 2. VibratorService 3. WindowManagerService 4. BackupManagerService 5. SoundTriggerService 6. NetworkPolicyManagerService Screen brightness will come in a following cl. Bug: 34693888 Test: FrameworksServicesTests Change-Id: I6b040e93391614b44d136a485faa4a332c396e51
* SoundTriggerHelpoer: Send pause events on abort if a model is running.Chris Thornton2016-07-201-1/+6
| | | | | | | | | If the recognition was aborted due to the service state being set to false, clients were not made aware that the model had been stopped (but would get a resume event). Bug: 30233664 Change-Id: I9f663362ff142eadfd5ef727c5f0c941f8e9e89d
* VIMS should only stop the keyphrases it started.Chris Thornton2016-05-021-28/+0
| | | | | | | | | | | When the VIMS changes the implementation or has its implementation force stopped, it used to stop all the recognitions that were in the SoundTriggerService (without letting those clients know that they've been stopped). Instead, the VIMS should just unload the keyphrases that it loaded, so the other clients are not perturbed. Bug:28518547 Change-Id: Ia70e8576f43cb8a8521c947ff7fc56f63cfbad54
* Remove the STH tracking if a model has been aborted.Chris Thornton2016-05-021-29/+19
| | | | | | | | | The STH just needs to log the fact that a model has been stopped when it is aborted. We also need to allow models to be stopped even if the service is unavailable. Bug:28474708 Change-Id: I2d618ae9c7c87311223f7d75b8ded7678252d11c
* Keep STH state in sync with HALChris Thornton2016-04-301-1/+4
| | | | | | | | | | | During stopAllRecognitions(), the internal state of a sound model was being cleared (which made it look like the model was being unloaded). However, the model was still loaded, so subsequent calls to load a 'new' model would break. Bug:28432002 Change-Id: I7090bf52704c6e46e3bb6d495d8fe4b8a1d9e2ad
* Use .equals() to compare two UUIDs in SoundTriggerHelper, rather than ==Chris Thornton2016-04-181-8/+5
| | | | | | | Also refactors ModelData::clearState to clear a bit more of the state. Bug:28251543 Change-Id: I18d7ccd90a6a9ee8bc8743d9a92c48f17d87c842
* SoundTriggerHelper: Add ability to manage multiple voice models.Arunesh Mishra2016-04-141-156/+182
| | | | | | | | This CL adds the ability in STH to manage multiple voice models indexed by keyphrase ID, which is an integer. Bug: 28104190 Change-Id: I8e10cca05ed8b4b8414cae7fffc26c132d4b7cbd
* SoundTriggerHelper re-design.Arunesh Mishra2016-04-081-345/+454
| | | | | | | | | | | | | | | | | | | | | This CL redesigns and cleans up a lot of the core logic in STH. Major changes include: - Adds Tron logging based counters. - Common startRecognition(), stopRecognition() and updateRecognition() routines that work on both Keyphrase and Generic sound models. - Common streamlined logic for when recognition is aborted, requested and paused due to phone call/power save etc, for both keyphrase and generic models. - Special handling of the singleton nature of keyphrase models in startRecognition(). - Moves all Keyphrase model state to the common ModelData structure. - Adds Recognition pause/resume() for generic sound models so that they react to power save, call state, recognition aborted due to service unavailable etc. Bug: 27972641 Change-Id: I96a7f567d2a4973facec556892a163ca74176bbf
* Fix unsynchronized access to model hashmapRyan Bavetta2016-03-081-32/+28
| | | | | BUG:27529749 Change-Id: I5b7cd59d8b45858896e6014b8fe95c1cc3c77869
* Fix AlwaysOnHotwordDetector recognition event bug.Arunesh Mishra2016-02-241-7/+7
| | | | | | | | | | | Parcelables don't work well with inheritance. So changed the IRecognitionStatusCallback to have onKeyphraseDetected() and onGenericSoundTriggerDetected() for those respective events. Made corresponding changes to AlwaysOnHotwordDetector and SoundTriggerDetector. Bug: 27250528 Change-Id: Ic08a431e7cc4248c688b05c865348170246de576