diff options
author | Mathias Agopian <mathias@google.com> | 2010-07-26 12:30:01 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-07-26 12:30:01 -0700 |
commit | bf23832accebcb4b8f7824842089b6b409a4c4dd (patch) | |
tree | a4318f6c5db3a11baa93fccbac141a29f264a2ab /services | |
parent | be199f3e111a84829ff800896312e2dad69b581f (diff) | |
parent | fed3c364e6fc6acc5e5836bd1370c3c278f8a248 (diff) | |
download | frameworks_base-bf23832accebcb4b8f7824842089b6b409a4c4dd.zip frameworks_base-bf23832accebcb4b8f7824842089b6b409a4c4dd.tar.gz frameworks_base-bf23832accebcb4b8f7824842089b6b409a4c4dd.tar.bz2 |
am fed3c364: am eab07e5c: Merge "Report sensor events to BatteryStats service" into gingerbread
Merge commit 'fed3c364e6fc6acc5e5836bd1370c3c278f8a248'
* commit 'fed3c364e6fc6acc5e5836bd1370c3c278f8a248':
Report sensor events to BatteryStats service
Diffstat (limited to 'services')
-rw-r--r-- | services/sensorservice/SensorService.cpp | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index 7fcab4c..3025f77 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -24,6 +24,7 @@ #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/Singleton.h> +#include <utils/String16.h> #include <binder/BinderService.h> #include <binder/IServiceManager.h> @@ -38,46 +39,65 @@ namespace android { // --------------------------------------------------------------------------- -/* - * TODO: - * - send sensor info to battery service - * - -static final int TRANSACTION_noteStartSensor = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3); -static final int TRANSACTION_noteStopSensor = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4); - - _data.writeInterfaceToken(DESCRIPTOR); - _data.writeInt(uid); - _data.writeInt(sensor); - mRemote.transact(Stub.TRANSACTION_noteStartSensor, _data, _reply, 0); - _reply.readException(); - * - */ - -// --------------------------------------------------------------------------- - class BatteryService : public Singleton<BatteryService> { + static const int TRANSACTION_noteStartSensor = IBinder::FIRST_CALL_TRANSACTION + 3; + static const int TRANSACTION_noteStopSensor = IBinder::FIRST_CALL_TRANSACTION + 4; + static const String16 DESCRIPTOR; + friend class Singleton<BatteryService>; sp<IBinder> mBatteryStatService; + BatteryService() { - const String16 name("batteryinfo"); - //getService(name, &mBatteryStatService); + const sp<IServiceManager> sm(defaultServiceManager()); + if (sm != NULL) { + const String16 name("batteryinfo"); + mBatteryStatService = sm->getService(name); + } + } + + status_t noteStartSensor(int uid, int handle) { + Parcel data, reply; + data.writeInterfaceToken(DESCRIPTOR); + data.writeInt32(uid); + data.writeInt32(handle); + status_t err = mBatteryStatService->transact( + TRANSACTION_noteStartSensor, data, &reply, 0); + err = reply.readExceptionCode(); + return err; } + + status_t noteStopSensor(int uid, int handle) { + Parcel data, reply; + data.writeInterfaceToken(DESCRIPTOR); + data.writeInt32(uid); + data.writeInt32(handle); + status_t err = mBatteryStatService->transact( + TRANSACTION_noteStopSensor, data, &reply, 0); + err = reply.readExceptionCode(); + return err; + } + public: void enableSensor(int handle) { if (mBatteryStatService != 0) { int uid = IPCThreadState::self()->getCallingUid(); - //mBatteryStatService->noteStartSensor(uid, handle); + int64_t identity = IPCThreadState::self()->clearCallingIdentity(); + noteStartSensor(uid, handle); + IPCThreadState::self()->restoreCallingIdentity(identity); } } void disableSensor(int handle) { if (mBatteryStatService != 0) { int uid = IPCThreadState::self()->getCallingUid(); - //mBatteryStatService->noteStopSensor(uid, handle); + int64_t identity = IPCThreadState::self()->clearCallingIdentity(); + noteStopSensor(uid, handle); + IPCThreadState::self()->restoreCallingIdentity(identity); } } }; +const String16 BatteryService::DESCRIPTOR("com.android.internal.app.IBatteryStats"); + ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService) // --------------------------------------------------------------------------- |