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..2f227fd5a5047c24e4788bc5c0a7dc5df106d31b 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,73 @@ 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(); |
+} |
+ |
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()); |
+ int rate_in_milliseconds = (event_type == kTypeLight) |
+ ? kInertialLightSensorIntervalMillis |
+ : kInertialSensorIntervalMillis; |
+ return Java_DeviceSensors_start(AttachCurrentThread(), |
+ device_sensors_.obj(), |
+ reinterpret_cast<intptr_t>(this), |
+ static_cast<jint>(event_type), |
+ rate_in_milliseconds); |
} |
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); |
timvolodine
2014/09/04 17:16:57
should the buffer be set to infinity when !success
riju_
2014/09/08 09:26:17
Done.
|
+ return success; |
+} |
+ |
+void SensorManagerAndroid::StopFetchingDeviceLightData() { |
+ Stop(kTypeLight); |
+ { |
+ base::AutoLock autolock(light_buffer_lock_); |
+ if (device_light_buffer_) { |
+ ClearInternalLightBuffers(); |
+ device_light_buffer_ = NULL; |
+ } |
+ } |
+} |
+ |
+void SensorManagerAndroid::ClearInternalLightBuffers() { |
+ device_light_buffer_->data.value = -1; |
timvolodine
2014/09/04 17:16:57
wrap with writeBegin writeEnd.
riju_
2014/09/08 09:26:17
Done.
|
+} |
// --- Device Motion |
bool SensorManagerAndroid::StartFetchingDeviceMotionData( |