From b37ba399c1521c3eba40e126f65d9663532de446 Mon Sep 17 00:00:00 2001 From: Aravind Akella Date: Tue, 5 Aug 2014 14:53:07 -0700 Subject: [PATCH] Sensor related changes for NDK. i) ASensorManager_getDefaultSensor returns a wake-up/non wake-up sensor depending on the type. ii) Add ASensor_isWakeUpSensor and ASensorManager_getDefaultSensorEx methods. Bug : 16399898 Change-Id: I1a86fb8d9de23039fdf41679d1487e1cd761a9d0 --- include/android/sensor.h | 14 +++++++++++++- libs/gui/SensorManager.cpp | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/android/sensor.h b/include/android/sensor.h index 77a5a1c30..d58c4608c 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -210,10 +210,17 @@ int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); /* * Returns the default sensor for the given type, or NULL if no sensor - * of that type exist. + * of that type exists. */ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); +/* + * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor + * of this type and wakeUp properties exists. + */ +ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, + bool wakeUp); + /* * Creates a new sensor event queue and associate it with a looper. */ @@ -321,6 +328,11 @@ const char* ASensor_getStringType(ASensor const* sensor); */ int ASensor_getReportingMode(ASensor const* sensor); +/* + * Returns true if this is a wake up sensor, false otherwise. + */ +bool ASensor_isWakeUpSensor(ASensor const* sensor); + #ifdef __cplusplus }; #endif diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp index b80da5681..7b4fa2f56 100644 --- a/libs/gui/SensorManager.cpp +++ b/libs/gui/SensorManager.cpp @@ -116,12 +116,23 @@ Sensor const* SensorManager::getDefaultSensor(int type) { Mutex::Autolock _l(mLock); if (assertStateLocked() == NO_ERROR) { + bool wakeUpSensor = false; + // For the following sensor types, return a wake-up sensor. These types are by default + // defined as wake-up sensors. For the rest of the sensor types defined in sensors.h return + // a non_wake-up version. + if (type == SENSOR_TYPE_PROXIMITY || type == SENSOR_TYPE_SIGNIFICANT_MOTION || + type == SENSOR_TYPE_TILT_DETECTOR || type == SENSOR_TYPE_WAKE_GESTURE || + type == SENSOR_TYPE_GLANCE_GESTURE || type == SENSOR_TYPE_PICK_UP_GESTURE) { + wakeUpSensor = true; + } // For now we just return the first sensor of that type we find. // in the future it will make sense to let the SensorService make // that decision. for (size_t i=0 ; igetType() == type) + if (mSensorList[i]->getType() == type && + mSensorList[i]->isWakeUpSensor() == wakeUpSensor) { return mSensorList[i]; + } } } return NULL;