Loading libs/binder/IBatteryStats.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,15 @@ public: remote()->transact(NOTE_RESET_FLASHLIGHT_TRANSACTION, data, &reply); } virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int handle) { Parcel data, reply; data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor()); data.writeInt64(elapsedNanos); data.writeInt32(uid); data.writeInt32(handle); status_t ret = remote()->transact(NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION, data, &reply); return binder::Status::fromStatusT(ret); } }; IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats") Loading Loading @@ -235,6 +244,16 @@ status_t BnBatteryStats::onTransact( reply->writeNoException(); return NO_ERROR; } break; case NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION: { CHECK_INTERFACE(IBatteryStats, data, reply); int64_t elapsedNanos = data.readInt64(); int uid = data.readInt32(); int handle = data.readInt32(); noteWakeupSensorEvent(elapsedNanos, uid, handle); reply->writeNoException(); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } Loading libs/binder/include_batterystats/batterystats/IBatteryStats.h +4 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #ifndef __ANDROID_VNDK__ #include <binder/IInterface.h> #include <binder/Status.h> namespace android { Loading @@ -43,6 +44,7 @@ public: virtual void noteStopCamera(int uid) = 0; virtual void noteResetCamera() = 0; virtual void noteResetFlashlight() = 0; virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int sensor) = 0; enum { NOTE_START_SENSOR_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, Loading @@ -58,7 +60,8 @@ public: NOTE_START_CAMERA_TRANSACTION, NOTE_STOP_CAMERA_TRANSACTION, NOTE_RESET_CAMERA_TRANSACTION, NOTE_RESET_FLASHLIGHT_TRANSACTION NOTE_RESET_FLASHLIGHT_TRANSACTION, NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION }; }; Loading services/sensorservice/BatteryService.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,14 @@ void BatteryService::disableSensorImpl(uid_t uid, int handle) { } } void BatteryService::noteWakeupSensorEventImpl(int64_t elapsedNanos, uid_t uid, int handle) { if (checkService()) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteWakeupSensorEvent(elapsedNanos, uid, handle); IPCThreadState::self()->restoreCallingIdentity(identity); } } bool BatteryService::checkService() { if (mBatteryStatService == nullptr) { const sp<IServiceManager> sm(defaultServiceManager()); Loading services/sensorservice/BatteryService.h +14 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -32,6 +35,7 @@ class BatteryService : public Singleton<BatteryService> { 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; Loading @@ -44,6 +48,7 @@ class BatteryService : public Singleton<BatteryService> { } }; int64_t mLastWakeupSensorEventReportedMs; Mutex mActivationsLock; SortedVector<Info> mActivations; bool addSensor(uid_t uid, int handle); Loading @@ -57,6 +62,15 @@ public: 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; } } }; // --------------------------------------------------------------------------- Loading services/sensorservice/SensorEventConnection.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <sensor/SensorEventQueue.h> #include "vec.h" #include "BatteryService.h" #include "SensorEventConnection.h" #include "SensorDevice.h" Loading Loading @@ -391,6 +392,8 @@ status_t SensorService::SensorEventConnection::sendEvents( if (hasSensorAccess()) { index_wake_up_event = findWakeUpSensorEventLocked(scratch, count); if (index_wake_up_event >= 0) { BatteryService::noteWakeupSensorEvent(scratch[index_wake_up_event].timestamp, mUid, scratch[index_wake_up_event].sensor); scratch[index_wake_up_event].flags |= WAKE_UP_SENSOR_EVENT_NEEDS_ACK; ++mWakeLockRefCount; #if DEBUG_CONNECTIONS Loading Loading
libs/binder/IBatteryStats.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,15 @@ public: remote()->transact(NOTE_RESET_FLASHLIGHT_TRANSACTION, data, &reply); } virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int handle) { Parcel data, reply; data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor()); data.writeInt64(elapsedNanos); data.writeInt32(uid); data.writeInt32(handle); status_t ret = remote()->transact(NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION, data, &reply); return binder::Status::fromStatusT(ret); } }; IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats") Loading Loading @@ -235,6 +244,16 @@ status_t BnBatteryStats::onTransact( reply->writeNoException(); return NO_ERROR; } break; case NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION: { CHECK_INTERFACE(IBatteryStats, data, reply); int64_t elapsedNanos = data.readInt64(); int uid = data.readInt32(); int handle = data.readInt32(); noteWakeupSensorEvent(elapsedNanos, uid, handle); reply->writeNoException(); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } Loading
libs/binder/include_batterystats/batterystats/IBatteryStats.h +4 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #ifndef __ANDROID_VNDK__ #include <binder/IInterface.h> #include <binder/Status.h> namespace android { Loading @@ -43,6 +44,7 @@ public: virtual void noteStopCamera(int uid) = 0; virtual void noteResetCamera() = 0; virtual void noteResetFlashlight() = 0; virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int sensor) = 0; enum { NOTE_START_SENSOR_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, Loading @@ -58,7 +60,8 @@ public: NOTE_START_CAMERA_TRANSACTION, NOTE_STOP_CAMERA_TRANSACTION, NOTE_RESET_CAMERA_TRANSACTION, NOTE_RESET_FLASHLIGHT_TRANSACTION NOTE_RESET_FLASHLIGHT_TRANSACTION, NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION }; }; Loading
services/sensorservice/BatteryService.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,14 @@ void BatteryService::disableSensorImpl(uid_t uid, int handle) { } } void BatteryService::noteWakeupSensorEventImpl(int64_t elapsedNanos, uid_t uid, int handle) { if (checkService()) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteWakeupSensorEvent(elapsedNanos, uid, handle); IPCThreadState::self()->restoreCallingIdentity(identity); } } bool BatteryService::checkService() { if (mBatteryStatService == nullptr) { const sp<IServiceManager> sm(defaultServiceManager()); Loading
services/sensorservice/BatteryService.h +14 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -32,6 +35,7 @@ class BatteryService : public Singleton<BatteryService> { 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; Loading @@ -44,6 +48,7 @@ class BatteryService : public Singleton<BatteryService> { } }; int64_t mLastWakeupSensorEventReportedMs; Mutex mActivationsLock; SortedVector<Info> mActivations; bool addSensor(uid_t uid, int handle); Loading @@ -57,6 +62,15 @@ public: 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; } } }; // --------------------------------------------------------------------------- Loading
services/sensorservice/SensorEventConnection.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <sensor/SensorEventQueue.h> #include "vec.h" #include "BatteryService.h" #include "SensorEventConnection.h" #include "SensorDevice.h" Loading Loading @@ -391,6 +392,8 @@ status_t SensorService::SensorEventConnection::sendEvents( if (hasSensorAccess()) { index_wake_up_event = findWakeUpSensorEventLocked(scratch, count); if (index_wake_up_event >= 0) { BatteryService::noteWakeupSensorEvent(scratch[index_wake_up_event].timestamp, mUid, scratch[index_wake_up_event].sensor); scratch[index_wake_up_event].flags |= WAKE_UP_SENSOR_EVENT_NEEDS_ACK; ++mWakeLockRefCount; #if DEBUG_CONNECTIONS Loading