diff options
| author | Mathias Agopian <mathias@google.com> | 2010-07-23 17:03:43 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-07-23 17:03:43 -0700 |
| commit | eab07e5c1d48d45f76ac2dd4a45c8a3457aa290d (patch) | |
| tree | e4720178e5606cf9c3f0bbbb1419f5df7bd4a484 | |
| parent | f88ed6c2ce750fcf7fb23778286e15557de758f9 (diff) | |
| parent | 32123fde1b82fc7f5d04f35e2b972364d4352ec9 (diff) | |
| download | frameworks_base-eab07e5c1d48d45f76ac2dd4a45c8a3457aa290d.zip frameworks_base-eab07e5c1d48d45f76ac2dd4a45c8a3457aa290d.tar.gz frameworks_base-eab07e5c1d48d45f76ac2dd4a45c8a3457aa290d.tar.bz2 | |
Merge "Report sensor events to BatteryStats service" into gingerbread
| -rw-r--r-- | core/java/com/android/internal/app/IBatteryStats.aidl | 7 | ||||
| -rw-r--r-- | services/sensorservice/SensorService.cpp | 64 |
2 files changed, 49 insertions, 22 deletions
diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl index 88ef395..d040d3f 100644 --- a/core/java/com/android/internal/app/IBatteryStats.aidl +++ b/core/java/com/android/internal/app/IBatteryStats.aidl @@ -24,8 +24,15 @@ interface IBatteryStats { byte[] getStatistics(); void noteStartWakelock(int uid, String name, int type); void noteStopWakelock(int uid, String name, int type); + + /* DO NOT CHANGE the position of noteStartSensor without updating + SensorService.cpp */ void noteStartSensor(int uid, int sensor); + + /* DO NOT CHANGE the position of noteStopSensor without updating + SensorService.cpp */ void noteStopSensor(int uid, int sensor); + void noteStartGps(int uid); void noteStopGps(int uid); void noteScreenOn(); 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) // --------------------------------------------------------------------------- |
