Index: content/browser/device_sensors/sensor_manager_android.cc |
diff --git a/content/browser/device_sensors/sensor_manager_android.cc b/content/browser/device_sensors/sensor_manager_android.cc |
index 400adfa355bccbb1ea607eb52c86ae774994851f..d7bd38b626e49e86386e11ff98c3dd1cd6958974 100644 |
--- a/content/browser/device_sensors/sensor_manager_android.cc |
+++ b/content/browser/device_sensors/sensor_manager_android.cc |
@@ -26,15 +26,15 @@ namespace content { |
SensorManagerAndroid::SensorManagerAndroid() |
: number_active_device_motion_sensors_(0), |
+ device_light_buffer_(NULL), |
device_motion_buffer_(NULL), |
device_orientation_buffer_(NULL), |
+ is_light_buffer_ready_(false), |
is_motion_buffer_ready_(false), |
is_orientation_buffer_ready_(false) { |
memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
- device_orientation_.Reset( |
- Java_DeviceSensors_getInstance( |
- AttachCurrentThread(), |
- base::android::GetApplicationContext())); |
+ device_sensors_.Reset(Java_DeviceSensors_getInstance( |
+ AttachCurrentThread(), base::android::GetApplicationContext())); |
} |
SensorManagerAndroid::~SensorManagerAndroid() { |
@@ -137,30 +137,84 @@ void SensorManagerAndroid::GotRotationRate( |
} |
} |
+void SensorManagerAndroid::GotLight(JNIEnv*, jobject, double value) { |
+ base::AutoLock autolock(light_buffer_lock_); |
+ |
+ if (!device_light_buffer_) |
+ return; |
+ |
+ device_light_buffer_->seqlock.WriteBegin(); |
+ device_light_buffer_->data.value = value; |
+ device_light_buffer_->seqlock.WriteEnd(); |
+ |
+ if (!is_light_buffer_ready_) { |
+ SetLightBufferReadyStatus(true); |
+ } |
+} |
+ |
bool SensorManagerAndroid::Start(EventType event_type) { |
- DCHECK(!device_orientation_.is_null()); |
- return Java_DeviceSensors_start( |
- AttachCurrentThread(), device_orientation_.obj(), |
- reinterpret_cast<intptr_t>(this), static_cast<jint>(event_type), |
- kInertialSensorIntervalMillis); |
+ DCHECK(!device_sensors_.is_null()); |
+ return Java_DeviceSensors_start(AttachCurrentThread(), |
+ device_sensors_.obj(), |
+ reinterpret_cast<intptr_t>(this), |
+ static_cast<jint>(event_type), |
+ kInertialSensorIntervalMillis); |
timvolodine
2014/07/16 15:39:38
do we need same interval for device light as for t
riju_
2014/07/18 15:59:17
Done. Now I have added kInertialLightSensorInterva
|
} |
void SensorManagerAndroid::Stop(EventType event_type) { |
- DCHECK(!device_orientation_.is_null()); |
- Java_DeviceSensors_stop( |
- AttachCurrentThread(), device_orientation_.obj(), |
- static_cast<jint>(event_type)); |
+ DCHECK(!device_sensors_.is_null()); |
+ Java_DeviceSensors_stop(AttachCurrentThread(), |
+ device_sensors_.obj(), |
+ static_cast<jint>(event_type)); |
} |
int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { |
- DCHECK(!device_orientation_.is_null()); |
+ DCHECK(!device_sensors_.is_null()); |
return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( |
- AttachCurrentThread(), device_orientation_.obj()); |
+ AttachCurrentThread(), device_sensors_.obj()); |
} |
// ----- Shared memory API methods |
+// --- Device Light |
+ |
+bool SensorManagerAndroid::StartFetchingDeviceLightData( |
+ DeviceLightHardwareBuffer* buffer) { |
+ DCHECK(buffer); |
+ { |
+ base::AutoLock autolock(light_buffer_lock_); |
+ device_light_buffer_ = buffer; |
+ ClearInternalLightBuffers(); |
+ } |
+ bool success = Start(kTypeLight); |
+ |
+ { |
+ base::AutoLock autolock(light_buffer_lock_); |
+ SetLightBufferReadyStatus(!success); |
+ } |
+ |
+ return success; |
+} |
+ |
+void SensorManagerAndroid::StopFetchingDeviceLightData() { |
+ Stop(kTypeLight); |
+ { |
+ base::AutoLock autolock(light_buffer_lock_); |
+ if (device_light_buffer_) { |
+ ClearInternalLightBuffers(); |
+ device_light_buffer_ = NULL; |
+ } |
+ } |
+} |
+ |
+void SensorManagerAndroid::SetLightBufferReadyStatus(bool ready) { |
+ is_light_buffer_ready_ = ready; |
timvolodine
2014/07/16 15:39:38
why do you need this? where is it used?
riju_
2014/07/18 15:59:17
Done.
|
+} |
+ |
+void SensorManagerAndroid::ClearInternalLightBuffers() { |
+ SetLightBufferReadyStatus(false); |
timvolodine
2014/07/16 15:39:38
should the lux value be set to -1 here?
riju_
2014/07/18 15:59:17
Done.
|
+} |
// --- Device Motion |
bool SensorManagerAndroid::StartFetchingDeviceMotionData( |