Commit Graph

63 Commits

Author SHA1 Message Date
Nick Moukhine
67b5e387b5 Use BIND_INCLUDE_CAPABILITIES for SoundTriggerService
SoundTriggerService is used by Now Playing to read DSP audio.  Now that audio permissions are gated on process capability, we need this flag for system server to pass on its capability during the bind.  With the new capability, permissions will no longer be denied.

Bug: 150508177
Fixes: 150508177
Test: todo
Change-Id: I79a18a9c98e5f36000f329bf15ca5a5f73826ffe
2020-03-16 19:31:49 +00:00
Ytai Ben-tsvi
49f7e6bfdf Merge "Correctly set the recognition state in response to GET_STATE" 2020-01-15 19:54:32 +00:00
Ytai Ben-Tsvi
8672d25e8a Correctly set the recognition state in response to GET_STATE
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
2020-01-14 16:54:15 -08:00
Nicholas Ambur
d3ec82fbc4 add version entry to soundtrigger model database
Bug:147159435
Test: manual hotword trigger with upgraded database
&& dumpsys voiceinteraction

Change-Id: I45497c1159fe879e1de119a18aac8f7ecc2b0686
2020-01-13 12:23:56 -08:00
Nicholas Ambur
f94db1c822 add parameter control to AlwaysOnHotwordDetector
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
2020-01-09 18:18:47 -08:00
Daulet Zhanguzin
e789eeee79 Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull

Bug: 126528330

Test: Treehugger
Change-Id: I902d340cf8025c560d3ae61223e8eba0c6bc5b30
2019-12-30 14:01:53 +00:00
Nicholas Ambur
a0be6be387 add SoundTrigger HAL 2.3 per model parameter apis
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
2019-12-11 19:16:48 -08:00
Eric Laurent
d4718e182d Merge "SoundTriggerHelper: fix state after audioserver death" into qt-qpr1-dev am: e5a3106cc5
am: e34b12d69b

Change-Id: Ie5d8451abfc732b45b9d803a6a901313479c0aa3
2019-09-19 12:03:09 -07:00
Eric Laurent
2fedc55920 SoundTriggerHelper: fix state after audioserver death
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
2019-09-12 01:37:15 +00:00
Nicholas Ambur
1aa4b4b779 Add ability to get soundtrigger props from dsp
exposes sound trigger module properties to privileged
system apps with MANAGE_SOUND_TRIGGER permission

Bug: 139071862
Test: GTS test confirmed API accessible and providing valid data
Change-Id: Iec7ba6fc59912f44341fbe8d7f99193b9ead52f0
2019-08-30 10:10:18 -07:00
Eric Laurent
80565fbf36 SoundTriggerHelper: fix power save mode listener
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
2019-07-19 12:06:24 -07:00
Benjamin Schwartz
9e7a0158fc SoundTriggerService: Track model stats
Bug: 133868565
Test: adb bugreport
Test: In bugreport, check DUMPSYS - voiceinteraction
Change-Id: I09750de4b3de1088ac6fba5ad08f01a4b1249112
2019-06-11 13:20:41 -07:00
mike dooley
baa22c7a8f Limit GetModelState API to generic sound models (ie music detector)
This limitation is being added to increase privacy protection.

Bug: 70619678
Bug: 117213117
Test: built android
Change-Id: Ic6ceed60a9687204fc7bf440becaa344a42d8e74
2019-05-17 07:26:11 +00:00
Jason Hsu
1363f581dc SoundTrigger Event logging
check bugreport DUMPSYS - voiceinteraction

BUG: 128965282
Test: manual
Change-Id: If2032e2cc5c0e071f9205e516987462625248b1c
Signed-off-by: Jason Hsu <jasonchhsu@google.com>
2019-04-29 12:14:41 +08:00
rago
f96269ab4d Enabling HW detection while phone ringing
Updated logic to allow HotWord detection while phone is ringing (still
not off-hook).

Test: Manual Testing
Bug: 124762676
Change-Id: Idce6d39a5589aee6d5baa4e5bcd8d98b3e13b239
2019-03-26 10:34:04 -07:00
mike dooley
9b20c1cda4 Treat getModelState recognition events the same as regular recognition
events.

This change should have been part of ag/5933708

Test: manual test with NowPlaying app on p19 device

Change-Id: I42ed7c17ebdd2cb75055122b8d45302e28c510b6
2019-01-24 08:17:13 +01:00
mike dooley
da48092c9b Make framework treat getModelState recognition events the same
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
2019-01-08 10:58:23 +01:00
mike dooley
23c625677d Fixing getModelState event processing
Test: manual testing with SoundTriggerTestApp

Bug: 119386757

Change-Id: I2c2960d169b119cb35345315638eeae28460896c
2018-12-20 16:48:53 +01:00
mike dooley
b2ab04aefd Converting sound trigger v2.2 getModelState to be asynchronous
Test: built android with checkbuild flag

Change-Id: I4c6f2388c93b6e577113fc7f2cd19242628ee50f
Bug-Id: 70206501
2018-11-09 08:36:15 +01:00
Michael Dooley
291751e510 Revert "Revert "Adding getModelState API to sound trigger""
This reverts commit 81f71f1c27.

Reason for revert: rolling forward with fix

Change-Id: Ifc0c53581ac567cb968d91993f453220f8253aec
2018-10-23 07:44:51 +02:00
Michael Dooley
be93d52505 Revert "Revert "Revert "Adding getModelState API to sound trigger"""
This reverts commit 7999836ee3.

Reason for revert: broke build

Change-Id: Id02636908aed26ee0ed38042da1ace0125a6d417
2018-09-28 07:30:28 +00:00
Michael Dooley
7999836ee3 Revert "Revert "Adding getModelState API to sound trigger""
This reverts commit 81f71f1c27.

Reason for revert: undoing rollback

Change-Id: Ifddfd0c730f03e93788d662a392d538564ce210b
2018-09-21 12:13:01 +00:00
Michael Dooley
c106550132 Merge "Revert "Adding getModelState API to sound trigger"" 2018-09-14 16:21:17 +00:00
Michael Dooley
81f71f1c27 Revert "Adding getModelState API to sound trigger"
This reverts commit 4f809fe73e.

Reason for revert: fix build breakage

Change-Id: I75a54189f96fc21f6cb12dd8a05e513b1bda027c
2018-09-14 16:09:18 +00:00
Michael Dooley
a707ba1cb0 Merge "Adding getModelState API to sound trigger" 2018-09-14 12:32:09 +00:00
Andreas Gampe
8ce7ed95a0 Frameworks: Annotate trivial @GuardedBy in services
Add @GuardedBy for simple functions that require locks and have a name in
one of the frameworks naming styles for locks ("^.*(Locked|LPw|LPr|L[a-zA-Z]|UL|AL|NL)$").

Derived by errorprone.

Bug: 73000847
Test: m
Change-Id: If70bb03313388af34d547efca20fb5115de95bf1
2018-09-05 17:02:08 -07:00
mike dooley
4f809fe73e Adding getModelState API to sound trigger
Test: built android
Bug-Id: 70206501
Change-Id: Ieb83a366d4ddd471186d5089efe0675ea6285454
2018-09-05 15:58:27 +02:00
mike dooley
82aaf21a54 Merge "Fixing a couple crashes in the SoundTriggerTestApp" into pi-dev am: 67890e0e1d
am: bbea1f436f

Change-Id: I4899434b32a6f2685fdbfe3d25a854917832f25d
2018-05-10 00:23:16 -07:00
TreeHugger Robot
67890e0e1d Merge "Fixing a couple crashes in the SoundTriggerTestApp" into pi-dev 2018-05-10 06:57:32 +00:00
Philip P. Moltmann
7108c33e3b Merge "Disable throttling of SoundTrigger" into pi-dev am: 1936031cbe
am: c7029fe7e0

Change-Id: Ifb78f41f756ac2002d12dc4e5de09dddef02f074
2018-05-08 12:31:31 -07:00
android-build-team Robot
cffc7c5b90 Merge "Simulate handling of event when throttling" into pi-dev am: 0458578642
am: 64bc4fab47

Change-Id: I2f87a69a1836cc9b109e78e49b3d0085bfb32b81
2018-05-07 18:03:42 -07:00
Philip P. Moltmann
3d1683be84 Disable throttling of SoundTrigger
Currently we don't have a way of throttling sound trigger events without
upsettings the DSP.

Bug: 78212455, 78310504
Test: Played music while having song detection enabled. Saw songs being
      detected

Change-Id: I3494d608f097532f02e6a588e22d9fe2d06048b1
2018-05-07 16:02:44 -07:00
Philip P. Moltmann
a5b4403a1f Simulate handling of event when throttling
When trottling we need to simulate handling of the event as otherwise
the DSP gets upset and SoundTriggerService and SoundTriggerHelper get
out of sync.

(1) Currently the DSP requires to open and release the AudioRecord if
a event was detected. Hence If we drop and event we need to do the
minimal version of that

(2) If a recognitions is set up with !allowMultipleTriggers the other
parts assume that as soon as one even is handled no further will be
needed. The other parts of the system are not aware of throttling.
Hence even when throttled we have to destroy the service when
!allowMultipleTriggers.

We do this by splitting the ops into three parts.

Setup (always executed): Takes care of problem (2) by checking the flag
and setting the destroy-once-ops-and-handled flag

Execute (not thottled): Send the op to the remote service

Drop (Trottled): Do what is needed if the remote service is not
involved. This handled issue (1)

Test: Caused throttling and saw - AudioRecord started and released
                                - service connection destroyed
Bug: 78212455

Change-Id: I0ff81a7b38d07db1365be7ecc44e93cf329b32d5
2018-05-04 13:59:45 -07:00
TreeHugger Robot
63b534768e Merge "Remove PendingIntent based soundTrigger" 2018-04-25 21:29:06 +00:00
mike dooley
cabbb11c01 Fixing a couple crashes in the SoundTriggerTestApp
Bug: 78269975
Test: built and ran the SoundTriggerTestApp
Change-Id: I966550a3d64e9f6a66c40e062a89f39b897aaea2
2018-04-19 15:57:06 +02:00
Philip P. Moltmann
09dd8c47d8 Properly disconnect after skipping an operation.
If we skip an operation we used to just return. This lead to the service
staying connected, holding the wakelock and consuming power.

Hence after we skip an operation we need to check if we can disconnect
the service, basically treating skipping an operation similar failing
to execute the operation.

Fixes: 77766977
Test: Detected music via sound trigger service and triggered dropping of
operations

Change-Id: Ia837d628193b3a5c2763f4aae666193d624b6d7f
2018-04-11 09:23:19 -07:00
Philip P. Moltmann
19402f557b Remove PendingIntent based soundTrigger
How that we have the SoundTriggerDetectionService we don't need the
pending intent based mechanism anymore.

Test: Checked that ambient music still detects music
Change-Id: If16c59028b31ff7d2e7f4d7f764460ac948ba946
Fixes: 73829108
2018-04-05 16:32:59 -07:00
Philip P. Moltmann
7e25b3d915 Throttle number of sound trigger operations / day
It is not clear when the day should start. Further a day might have
25 hours in the case of daylight savings time.
Hence a day in this case is the last 24 hours, not a calendar day.

Keeping track of the time of each operation might waste memory as we
don't need that much precision.

Hence keep track how many operations were performed in the last 24
hours in buckets of hours. If the total count reaches a maximum suppress
any further operations.

The maximum is configurable via global settings. It can be updated
by apps that have the appropriate permissions. Hence if the default
value turns out to be incorrect, it can be adjusted after release.

This does not throttle based on battery state as it is better to
completely unload the sound model to not even have a detection event.

Test: atest SoundTriggerDetectionServiceTests (separate CL)
      atest android.provider.SettingsBackupTest
Bug: 73829108
Change-Id: Ied8570b60b61b6a055bd2576d1502c1b36424efa
2018-03-20 13:57:14 -07:00
Philip P. Moltmann
18e3eb8168 Add SoundTriggerDetectionService
The service is meant to replace the PendingIntent based API. Once all
users of the PendingIntent based API switched the PendingIntent based API
will be removed.

To have as little as possible impact on the whole SoundTrigger framework
the RemoteSoundTriggerDetectionService class implements the same
interface as the PendingIntent based class. Hence the exising code has
very little change. Further once the old code can be removed the amount
of changed (and added) code is limited.

The RemoteSoundTriggerDetectionService -> SoundTriggerDetectionService
is a vanilla as possible service implementation. The special behaviors
are:
- The system holds a wakelock while service operations are in progress
and the service is bound as foreground. Hence the service can e.g.
listen to the microphone.
- Service operations have a certain amount of time they are allowed to
run. Once every operation is either finished or the the operation
exceeded the allotted time, the system calls onStopOperation for each
still pending operation. This is a similar model as for the commonly
used JobService.
  Please note that if the time allowed for an operation is 15s and
op1 was run as 0si, and op1 was run at 5s, the service is allowed to run
until 20s. Hence _both_ onStopOperations will happen at 20s. This is
done for ease of implementation but should not give the service more
power than calling onStopOperation exactly 15s after each operation is
triggered.
- If an operation is done before the allotted time is reached, the
service can declare the operation as finished manually by calling
onOperationFinished. This is a call back into the system, hence a
'client' binder is sent to the service. If the operation is finished
by calling this method onStopOperation will not be called.
- As the service instance might be killed and restored between
operations we add a opaque bundle 'params' to each operations. The users
of the API can use this to send data from the start command to the
operations. It can also just be set to null. The params are not meant to
store changing state in between operations. Such state needs to be
persisted using the regular methods (e.g. write it to disk)
- A service can be used for multiple recognition sessions. Each
recognition is uniquelity defined by its sound model UUID. Hence each
operation gets at least tree arguments: Operation ID, sound mode UUID, params
- As a small optimization the params are cached inside of the service
instance.

The time allowed for each operation is in a @SystemAPI global setting,
so the service can make sure it finishes the operations before they are
stopped. It might take some time to deliver the operations via the
binder, hence it is not recommended to try to use every last ms of
allotted time.

Test: atest SoundTriggerDetectionServiceTest (added in separate CL)
      atest android.provider.SettingsBackupTest
Change-Id: I47f813b7a5138a6f24732197813a605d29f85a93
Fixes: 73829108
2018-03-20 13:57:14 -07:00
Hall Liu
017afff112 Merge "Check for location access on TelephonyRegistry" am: 31230bb193 am: f581580fdb
am: 9b31dd86da

Change-Id: Icd2feab82a9350fa2b6539617863ad91a44e5208
2018-02-22 00:43:12 +00:00
Hall Liu
5fb337ff85 Check for location access on TelephonyRegistry
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
2018-02-06 14:01:47 -08:00
Chris Thornton
ae5fb99096 Fix deadlock in SoundTriggerService using intent API.
The callback of the SoundTriggerService using the intent API used to try
and grab the same lock that other calls to the STS were using when they
accessed the SoundTriggerHelper.

This happens because most functions in the STH grab the STH's lock,
including the one that handles the recognition events. The recognition
event callback in the STS would then try to grab the STS lock, while
implicitly holding the STH one.

However, a concurrent call to the STS from outside could first grab the
STS lock, then call into the STH which may need the STH lock, resulting
in a deadlock.

By removing the requirement that the STS callback grab the main STS
lock, this condition is avoided.

Bug: 70346433
Test: On device
Change-Id: I44571fba786a82a17423d45f503be9537b476a01
2017-12-07 18:39:06 -08:00
Makoto Onuki
2eccd02628 Make the battery saver knobs hidden public,
so other components (system UI, settings, etc) can use them.

Bug: 68769804
Test: Build & presubmit
Change-Id: I30fe78e49d2187bee7c7aeba735cd9c26fc332a5
2017-11-01 14:49:10 -07:00
Chris Thornton
ba08b7945a Add SoundTriggerManager APIs to use a PendingIntent to get callbacks.
Test: APIs exercised using a special test app not in this CL.

Change-Id: I99425d1e67a778513e6c75e7d595c072032aa2ab
2017-06-13 18:37:48 -07:00
Chris Thornton
23a57404e3 Prevent ConcurrentModificationException in updateAllRecognitions
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
2017-06-10 17:38:41 -07:00
Chris Thornton
a533b9942d SoundTriggerHelper: Remove unused models onLoad
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
2017-03-27 11:21:34 -07:00
Chris Thornton
2411a2c38e Clean up dead objects when detected in the SoundTriggerHelper
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
2017-03-22 21:28:31 -07:00
jackqdyulei
455e90add2 Add BatterySaverPolicy for power save mode
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
2017-03-08 09:20:36 -08:00
Chris Thornton
d0a83b89a6 SoundTriggerHelpoer: Send pause events on abort if a model is running.
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
2016-07-20 14:43:07 -07:00
Chris Thornton
f967da9052 VIMS should only stop the keyphrases it started.
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
2016-05-02 19:22:57 -07:00