From 6d177c83b50ff465fdbca5136a162c1f833ecf8a Mon Sep 17 00:00:00 2001 From: Suprabh Shukla Date: Mon, 6 Feb 2023 19:54:01 -0800 Subject: [PATCH] Adding an API to report sound trigger events Sound trigger events can wake the CPU up. Adding an API that can be used by the sound trigger modules to report whenever the underlying hardware notifies the main chip on recognizing a phrase. The API is non-functional now. Functionality will be added once the event has been piped from the SoundTrigger system. Test: Builds, boots. Bug: 267717665 Change-Id: Id6382aa2f2b09cde0a2fda728c0825e3a5d15a3d --- .../core/java/android/os/BatteryStatsInternal.java | 12 +++++++++++- .../com/android/server/am/BatteryStatsService.java | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/services/core/java/android/os/BatteryStatsInternal.java b/services/core/java/android/os/BatteryStatsInternal.java index 9c2de65f27773..17ef9a2324014 100644 --- a/services/core/java/android/os/BatteryStatsInternal.java +++ b/services/core/java/android/os/BatteryStatsInternal.java @@ -104,8 +104,18 @@ public abstract class BatteryStatsInternal { /** * Reports any activity that could potentially have caused the CPU to wake up. - * Accepts a timestamp to allow the reporter to report it before or after the event. + * Accepts a timestamp to allow free ordering between the event and its reporting. + * @param subsystem The subsystem this activity should be attributed to. + * @param elapsedMillis The time when this activity happened in the elapsed timebase. + * @param uids The uid (or uids) that should be blamed for this activity. */ public abstract void noteCpuWakingActivity(@CpuWakeupSubsystem int subsystem, long elapsedMillis, @NonNull int... uids); + + /** + * Reports a sound trigger recognition event that may have woken up the CPU. + * @param elapsedMillis The time when the event happened in the elapsed timebase. + * @param uid The uid that requested this trigger. + */ + public abstract void noteWakingSoundTrigger(long elapsedMillis, int uid); } diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index f09622f101ac4..3207a12d32e37 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -483,6 +483,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub Objects.requireNonNull(uids); mCpuWakeupStats.noteWakingActivity(subsystem, elapsedMillis, uids); } + + @Override + public void noteWakingSoundTrigger(long elapsedMillis, int uid) { + // TODO(b/267717665): Pipe to noteCpuWakingActivity once SoundTrigger starts using this. + Slog.w(TAG, "Sound trigger event dispatched to uid " + uid); + } } @Override