Pipe wakeup sensor events to batterystats
Creating another method in BatteryService to send notifcations from
sensor event connection to BatteryStatsService.
Passing the sensor handle so java code can retrieve a Sensor object and
then query any properties of the sensor from there.
Test: Manually trigger sensor events and check logcat
Ignore-AOSP-First: AIDL method definition not present in AOSP.
Bug: 275436924
Change-Id: I7c3009b33a38047463214eb32ba67925ddc20773
diff --git a/services/sensorservice/BatteryService.h b/services/sensorservice/BatteryService.h
index 13fc58a..60ef03f 100644
--- a/services/sensorservice/BatteryService.h
+++ b/services/sensorservice/BatteryService.h
@@ -19,11 +19,14 @@
#include <batterystats/IBatteryStats.h>
#include <utils/Singleton.h>
+#include <utils/SortedVector.h>
+#include <utils/SystemClock.h>
namespace android {
// ---------------------------------------------------------------------------
class BatteryService : public Singleton<BatteryService> {
+ static constexpr int64_t WAKEUP_SENSOR_EVENT_DEBOUNCE_MS = 1000;
friend class Singleton<BatteryService>;
sp<IBatteryStats> mBatteryStatService;
@@ -32,6 +35,7 @@
void enableSensorImpl(uid_t uid, int handle);
void disableSensorImpl(uid_t uid, int handle);
+ void noteWakeupSensorEventImpl(int64_t elapsedNanos, uid_t uid, int handle);
struct Info {
uid_t uid;
@@ -44,6 +48,7 @@
}
};
+ int64_t mLastWakeupSensorEventReportedMs;
Mutex mActivationsLock;
SortedVector<Info> mActivations;
bool addSensor(uid_t uid, int handle);
@@ -57,6 +62,15 @@
static void disableSensor(uid_t uid, int handle) {
BatteryService::getInstance().disableSensorImpl(uid, handle);
}
+ static void noteWakeupSensorEvent(int64_t elapsed, uid_t uid, int handle) {
+ BatteryService& instance = BatteryService::getInstance();
+ const int64_t nowElapsedMs = elapsedRealtime();
+ if (nowElapsedMs >= (instance.mLastWakeupSensorEventReportedMs
+ + WAKEUP_SENSOR_EVENT_DEBOUNCE_MS)) {
+ instance.noteWakeupSensorEventImpl(elapsed, uid, handle);
+ instance.mLastWakeupSensorEventReportedMs = nowElapsedMs;
+ }
+ }
};
// ---------------------------------------------------------------------------