| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/device_sensors/sensor_manager_android.h" | 5 #include "content/browser/device_sensors/sensor_manager_android.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 bool SensorManagerAndroid::Register(JNIEnv* env) { | 69 bool SensorManagerAndroid::Register(JNIEnv* env) { |
| 70 return RegisterNativesImpl(env); | 70 return RegisterNativesImpl(env); |
| 71 } | 71 } |
| 72 | 72 |
| 73 SensorManagerAndroid* SensorManagerAndroid::GetInstance() { | 73 SensorManagerAndroid* SensorManagerAndroid::GetInstance() { |
| 74 return base::Singleton< | 74 return base::Singleton< |
| 75 SensorManagerAndroid, | 75 SensorManagerAndroid, |
| 76 base::LeakySingletonTraits<SensorManagerAndroid>>::get(); | 76 base::LeakySingletonTraits<SensorManagerAndroid>>::get(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SensorManagerAndroid::GotOrientation( | 79 void SensorManagerAndroid::GotOrientation(JNIEnv*, |
| 80 JNIEnv*, jobject, double alpha, double beta, double gamma) { | 80 const JavaParamRef<jobject>&, |
| 81 double alpha, |
| 82 double beta, |
| 83 double gamma) { |
| 81 base::AutoLock autolock(orientation_buffer_lock_); | 84 base::AutoLock autolock(orientation_buffer_lock_); |
| 82 | 85 |
| 83 if (!device_orientation_buffer_) | 86 if (!device_orientation_buffer_) |
| 84 return; | 87 return; |
| 85 | 88 |
| 86 SetOrientation(device_orientation_buffer_, alpha, beta, gamma); | 89 SetOrientation(device_orientation_buffer_, alpha, beta, gamma); |
| 87 | 90 |
| 88 if (!orientation_buffer_initialized_) { | 91 if (!orientation_buffer_initialized_) { |
| 89 OrientationSensorType type = | 92 OrientationSensorType type = |
| 90 static_cast<OrientationSensorType>(GetOrientationSensorTypeUsed()); | 93 static_cast<OrientationSensorType>(GetOrientationSensorTypeUsed()); |
| 91 SetOrientationBufferStatus(device_orientation_buffer_, true, | 94 SetOrientationBufferStatus(device_orientation_buffer_, true, |
| 92 type != GAME_ROTATION_VECTOR); | 95 type != GAME_ROTATION_VECTOR); |
| 93 orientation_buffer_initialized_ = true; | 96 orientation_buffer_initialized_ = true; |
| 94 UpdateDeviceOrientationHistogram(type); | 97 UpdateDeviceOrientationHistogram(type); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 | 100 |
| 98 void SensorManagerAndroid::GotOrientationAbsolute( | 101 void SensorManagerAndroid::GotOrientationAbsolute(JNIEnv*, |
| 99 JNIEnv*, jobject, double alpha, double beta, double gamma) { | 102 const JavaParamRef<jobject>&, |
| 103 double alpha, |
| 104 double beta, |
| 105 double gamma) { |
| 100 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 106 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
| 101 | 107 |
| 102 if (!device_orientation_absolute_buffer_) | 108 if (!device_orientation_absolute_buffer_) |
| 103 return; | 109 return; |
| 104 | 110 |
| 105 SetOrientation(device_orientation_absolute_buffer_, alpha, beta, gamma); | 111 SetOrientation(device_orientation_absolute_buffer_, alpha, beta, gamma); |
| 106 | 112 |
| 107 if (!orientation_absolute_buffer_initialized_) { | 113 if (!orientation_absolute_buffer_initialized_) { |
| 108 SetOrientationBufferStatus(device_orientation_absolute_buffer_, true, true); | 114 SetOrientationBufferStatus(device_orientation_absolute_buffer_, true, true); |
| 109 orientation_absolute_buffer_initialized_ = true; | 115 orientation_absolute_buffer_initialized_ = true; |
| 110 // TODO(timvolodine): Add UMA. | 116 // TODO(timvolodine): Add UMA. |
| 111 } | 117 } |
| 112 } | 118 } |
| 113 | 119 |
| 114 | 120 void SensorManagerAndroid::GotAcceleration(JNIEnv*, |
| 115 void SensorManagerAndroid::GotAcceleration( | 121 const JavaParamRef<jobject>&, |
| 116 JNIEnv*, jobject, double x, double y, double z) { | 122 double x, |
| 123 double y, |
| 124 double z) { |
| 117 base::AutoLock autolock(motion_buffer_lock_); | 125 base::AutoLock autolock(motion_buffer_lock_); |
| 118 | 126 |
| 119 if (!device_motion_buffer_) | 127 if (!device_motion_buffer_) |
| 120 return; | 128 return; |
| 121 | 129 |
| 122 device_motion_buffer_->seqlock.WriteBegin(); | 130 device_motion_buffer_->seqlock.WriteBegin(); |
| 123 device_motion_buffer_->data.accelerationX = x; | 131 device_motion_buffer_->data.accelerationX = x; |
| 124 device_motion_buffer_->data.hasAccelerationX = true; | 132 device_motion_buffer_->data.hasAccelerationX = true; |
| 125 device_motion_buffer_->data.accelerationY = y; | 133 device_motion_buffer_->data.accelerationY = y; |
| 126 device_motion_buffer_->data.hasAccelerationY = true; | 134 device_motion_buffer_->data.hasAccelerationY = true; |
| 127 device_motion_buffer_->data.accelerationZ = z; | 135 device_motion_buffer_->data.accelerationZ = z; |
| 128 device_motion_buffer_->data.hasAccelerationZ = true; | 136 device_motion_buffer_->data.hasAccelerationZ = true; |
| 129 device_motion_buffer_->seqlock.WriteEnd(); | 137 device_motion_buffer_->seqlock.WriteEnd(); |
| 130 | 138 |
| 131 if (!motion_buffer_initialized_) { | 139 if (!motion_buffer_initialized_) { |
| 132 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION] = 1; | 140 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION] = 1; |
| 133 CheckMotionBufferReadyToRead(); | 141 CheckMotionBufferReadyToRead(); |
| 134 } | 142 } |
| 135 } | 143 } |
| 136 | 144 |
| 137 void SensorManagerAndroid::GotAccelerationIncludingGravity( | 145 void SensorManagerAndroid::GotAccelerationIncludingGravity( |
| 138 JNIEnv*, jobject, double x, double y, double z) { | 146 JNIEnv*, |
| 147 const JavaParamRef<jobject>&, |
| 148 double x, |
| 149 double y, |
| 150 double z) { |
| 139 base::AutoLock autolock(motion_buffer_lock_); | 151 base::AutoLock autolock(motion_buffer_lock_); |
| 140 | 152 |
| 141 if (!device_motion_buffer_) | 153 if (!device_motion_buffer_) |
| 142 return; | 154 return; |
| 143 | 155 |
| 144 device_motion_buffer_->seqlock.WriteBegin(); | 156 device_motion_buffer_->seqlock.WriteBegin(); |
| 145 device_motion_buffer_->data.accelerationIncludingGravityX = x; | 157 device_motion_buffer_->data.accelerationIncludingGravityX = x; |
| 146 device_motion_buffer_->data.hasAccelerationIncludingGravityX = true; | 158 device_motion_buffer_->data.hasAccelerationIncludingGravityX = true; |
| 147 device_motion_buffer_->data.accelerationIncludingGravityY = y; | 159 device_motion_buffer_->data.accelerationIncludingGravityY = y; |
| 148 device_motion_buffer_->data.hasAccelerationIncludingGravityY = true; | 160 device_motion_buffer_->data.hasAccelerationIncludingGravityY = true; |
| 149 device_motion_buffer_->data.accelerationIncludingGravityZ = z; | 161 device_motion_buffer_->data.accelerationIncludingGravityZ = z; |
| 150 device_motion_buffer_->data.hasAccelerationIncludingGravityZ = true; | 162 device_motion_buffer_->data.hasAccelerationIncludingGravityZ = true; |
| 151 device_motion_buffer_->seqlock.WriteEnd(); | 163 device_motion_buffer_->seqlock.WriteEnd(); |
| 152 | 164 |
| 153 if (!motion_buffer_initialized_) { | 165 if (!motion_buffer_initialized_) { |
| 154 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY] = 1; | 166 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY] = 1; |
| 155 CheckMotionBufferReadyToRead(); | 167 CheckMotionBufferReadyToRead(); |
| 156 } | 168 } |
| 157 } | 169 } |
| 158 | 170 |
| 159 void SensorManagerAndroid::GotRotationRate( | 171 void SensorManagerAndroid::GotRotationRate(JNIEnv*, |
| 160 JNIEnv*, jobject, double alpha, double beta, double gamma) { | 172 const JavaParamRef<jobject>&, |
| 173 double alpha, |
| 174 double beta, |
| 175 double gamma) { |
| 161 base::AutoLock autolock(motion_buffer_lock_); | 176 base::AutoLock autolock(motion_buffer_lock_); |
| 162 | 177 |
| 163 if (!device_motion_buffer_) | 178 if (!device_motion_buffer_) |
| 164 return; | 179 return; |
| 165 | 180 |
| 166 device_motion_buffer_->seqlock.WriteBegin(); | 181 device_motion_buffer_->seqlock.WriteBegin(); |
| 167 device_motion_buffer_->data.rotationRateAlpha = alpha; | 182 device_motion_buffer_->data.rotationRateAlpha = alpha; |
| 168 device_motion_buffer_->data.hasRotationRateAlpha = true; | 183 device_motion_buffer_->data.hasRotationRateAlpha = true; |
| 169 device_motion_buffer_->data.rotationRateBeta = beta; | 184 device_motion_buffer_->data.rotationRateBeta = beta; |
| 170 device_motion_buffer_->data.hasRotationRateBeta = true; | 185 device_motion_buffer_->data.hasRotationRateBeta = true; |
| 171 device_motion_buffer_->data.rotationRateGamma = gamma; | 186 device_motion_buffer_->data.rotationRateGamma = gamma; |
| 172 device_motion_buffer_->data.hasRotationRateGamma = true; | 187 device_motion_buffer_->data.hasRotationRateGamma = true; |
| 173 device_motion_buffer_->seqlock.WriteEnd(); | 188 device_motion_buffer_->seqlock.WriteEnd(); |
| 174 | 189 |
| 175 if (!motion_buffer_initialized_) { | 190 if (!motion_buffer_initialized_) { |
| 176 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; | 191 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; |
| 177 CheckMotionBufferReadyToRead(); | 192 CheckMotionBufferReadyToRead(); |
| 178 } | 193 } |
| 179 } | 194 } |
| 180 | 195 |
| 181 void SensorManagerAndroid::GotLight(JNIEnv*, jobject, double value) { | 196 void SensorManagerAndroid::GotLight(JNIEnv*, |
| 197 const JavaParamRef<jobject>&, |
| 198 double value) { |
| 182 base::AutoLock autolock(light_buffer_lock_); | 199 base::AutoLock autolock(light_buffer_lock_); |
| 183 | 200 |
| 184 if (!device_light_buffer_) | 201 if (!device_light_buffer_) |
| 185 return; | 202 return; |
| 186 | 203 |
| 187 device_light_buffer_->seqlock.WriteBegin(); | 204 device_light_buffer_->seqlock.WriteBegin(); |
| 188 device_light_buffer_->data.value = value; | 205 device_light_buffer_->data.value = value; |
| 189 device_light_buffer_->seqlock.WriteEnd(); | 206 device_light_buffer_->seqlock.WriteEnd(); |
| 190 } | 207 } |
| 191 | 208 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 543 } |
| 527 } | 544 } |
| 528 } | 545 } |
| 529 | 546 |
| 530 void SensorManagerAndroid::Shutdown() { | 547 void SensorManagerAndroid::Shutdown() { |
| 531 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 548 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 532 is_shutdown_ = true; | 549 is_shutdown_ = true; |
| 533 } | 550 } |
| 534 | 551 |
| 535 } // namespace content | 552 } // namespace content |
| OLD | NEW |