Loading services/sensorservice/BatteryService.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -30,12 +30,7 @@ namespace android { // --------------------------------------------------------------------------- BatteryService::BatteryService() { const sp<IServiceManager> sm(defaultServiceManager()); if (sm != NULL) { const String16 name("batterystats"); mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); } BatteryService::BatteryService() : mBatteryStatService(nullptr) { } bool BatteryService::addSensor(uid_t uid, int handle) { Loading @@ -61,7 +56,7 @@ bool BatteryService::removeSensor(uid_t uid, int handle) { void BatteryService::enableSensorImpl(uid_t uid, int handle) { if (mBatteryStatService != 0) { if (checkService()) { if (addSensor(uid, handle)) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteStartSensor(uid, handle); Loading @@ -70,7 +65,7 @@ void BatteryService::enableSensorImpl(uid_t uid, int handle) { } } void BatteryService::disableSensorImpl(uid_t uid, int handle) { if (mBatteryStatService != 0) { if (checkService()) { if (removeSensor(uid, handle)) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteStopSensor(uid, handle); Loading @@ -80,7 +75,7 @@ void BatteryService::disableSensorImpl(uid_t uid, int handle) { } void BatteryService::cleanupImpl(uid_t uid) { if (mBatteryStatService != 0) { if (checkService()) { Mutex::Autolock _l(mActivationsLock); int64_t identity = IPCThreadState::self()->clearCallingIdentity(); for (size_t i=0 ; i<mActivations.size() ; i++) { Loading @@ -95,6 +90,17 @@ void BatteryService::cleanupImpl(uid_t uid) { } } bool BatteryService::checkService() { if (mBatteryStatService == nullptr) { const sp<IServiceManager> sm(defaultServiceManager()); if (sm != NULL) { const String16 name("batterystats"); mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); } } return mBatteryStatService != nullptr; } ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService) // --------------------------------------------------------------------------- Loading services/sensorservice/BatteryService.h +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ class BatteryService : public Singleton<BatteryService> { SortedVector<Info> mActivations; bool addSensor(uid_t uid, int handle); bool removeSensor(uid_t uid, int handle); bool checkService(); public: static void enableSensor(uid_t uid, int handle) { Loading Loading
services/sensorservice/BatteryService.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -30,12 +30,7 @@ namespace android { // --------------------------------------------------------------------------- BatteryService::BatteryService() { const sp<IServiceManager> sm(defaultServiceManager()); if (sm != NULL) { const String16 name("batterystats"); mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); } BatteryService::BatteryService() : mBatteryStatService(nullptr) { } bool BatteryService::addSensor(uid_t uid, int handle) { Loading @@ -61,7 +56,7 @@ bool BatteryService::removeSensor(uid_t uid, int handle) { void BatteryService::enableSensorImpl(uid_t uid, int handle) { if (mBatteryStatService != 0) { if (checkService()) { if (addSensor(uid, handle)) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteStartSensor(uid, handle); Loading @@ -70,7 +65,7 @@ void BatteryService::enableSensorImpl(uid_t uid, int handle) { } } void BatteryService::disableSensorImpl(uid_t uid, int handle) { if (mBatteryStatService != 0) { if (checkService()) { if (removeSensor(uid, handle)) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteStopSensor(uid, handle); Loading @@ -80,7 +75,7 @@ void BatteryService::disableSensorImpl(uid_t uid, int handle) { } void BatteryService::cleanupImpl(uid_t uid) { if (mBatteryStatService != 0) { if (checkService()) { Mutex::Autolock _l(mActivationsLock); int64_t identity = IPCThreadState::self()->clearCallingIdentity(); for (size_t i=0 ; i<mActivations.size() ; i++) { Loading @@ -95,6 +90,17 @@ void BatteryService::cleanupImpl(uid_t uid) { } } bool BatteryService::checkService() { if (mBatteryStatService == nullptr) { const sp<IServiceManager> sm(defaultServiceManager()); if (sm != NULL) { const String16 name("batterystats"); mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); } } return mBatteryStatService != nullptr; } ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService) // --------------------------------------------------------------------------- Loading
services/sensorservice/BatteryService.h +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ class BatteryService : public Singleton<BatteryService> { SortedVector<Info> mActivations; bool addSensor(uid_t uid, int handle); bool removeSensor(uid_t uid, int handle); bool checkService(); public: static void enableSensor(uid_t uid, int handle) { Loading