Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 package org.chromium.device.sensors; | 5 package org.chromium.device.sensors; |
| 6 | 6 |
| 7 import android.hardware.Sensor; | 7 import android.hardware.Sensor; |
| 8 import android.hardware.SensorEvent; | 8 import android.hardware.SensorEvent; |
| 9 import android.hardware.SensorEventListener; | 9 import android.hardware.SensorEventListener; |
| 10 import android.os.Build; | 10 import android.os.Build; |
| 11 | 11 |
| 12 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
| 13 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
| 14 import org.chromium.device.mojom.ReportingMode; | 14 import org.chromium.device.mojom.ReportingMode; |
| 15 | 15 |
| 16 import java.util.List; | 16 import java.util.List; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Implementation of PlatformSensor that uses Android Sensor Framework. Lifetime is controlled by | 19 * Implementation of PlatformSensor that uses Android Sensor Framework. Lifetime is controlled by |
| 20 * the device::PlatformSensorAndroid. | 20 * the device::PlatformSensorAndroid. |
| 21 */ | 21 */ |
| 22 @JNINamespace("device") | 22 @JNINamespace("device") |
| 23 public class PlatformSensor implements SensorEventListener { | 23 public class PlatformSensor implements SensorEventListener { |
| 24 private static final double MICROSECONDS_IN_SECOND = 1000000; | 24 private static final double MICROSECONDS_IN_SECOND = 1000000; |
| 25 private static final double SECONDS_IN_MICROSECOND = 0.000001d; | |
|
timvolodine
2016/11/03 17:32:55
why not use import java.util.concurrent.TimeUnit f
Mikhail
2016/11/04 21:17:44
That API operates with 'long' type and loses preci
| |
| 25 private static final double SECONDS_IN_NANOSECOND = 0.000000001d; | 26 private static final double SECONDS_IN_NANOSECOND = 0.000000001d; |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * The SENSOR_FREQUENCY_NORMAL is defined as 5Hz which corresponds to a poll ing delay | 29 * The SENSOR_FREQUENCY_NORMAL is defined as 5Hz which corresponds to a poll ing delay |
| 29 * @see android.hardware.SensorManager.SENSOR_DELAY_NORMAL value that is def ined as 200000 | 30 * @see android.hardware.SensorManager.SENSOR_DELAY_NORMAL value that is def ined as 200000 |
| 30 * microseconds. | 31 * microseconds. |
| 31 */ | 32 */ |
| 32 private static final double SENSOR_FREQUENCY_NORMAL = 5.0d; | 33 private static final double SENSOR_FREQUENCY_NORMAL = 5.0d; |
| 33 | 34 |
| 34 /** | 35 /** |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 * Returns default configuration supported by the sensor. Currently only fre quency is supported. | 118 * Returns default configuration supported by the sensor. Currently only fre quency is supported. |
| 118 * | 119 * |
| 119 * @return double frequency. | 120 * @return double frequency. |
| 120 */ | 121 */ |
| 121 @CalledByNative | 122 @CalledByNative |
| 122 protected double getDefaultConfiguration() { | 123 protected double getDefaultConfiguration() { |
| 123 return SENSOR_FREQUENCY_NORMAL; | 124 return SENSOR_FREQUENCY_NORMAL; |
| 124 } | 125 } |
| 125 | 126 |
| 126 /** | 127 /** |
| 128 * Returns maximum sampling frequency supported by the sensor. | |
| 129 * | |
| 130 * @return double frequency in Hz. | |
| 131 */ | |
| 132 @CalledByNative | |
| 133 protected double getMaximumSupportedFrequency() { | |
| 134 if (mMinDelayUsec == 0) return getDefaultConfiguration(); | |
| 135 return 1 / (mMinDelayUsec * SECONDS_IN_MICROSECOND); | |
| 136 } | |
| 137 | |
| 138 /** | |
| 127 * Requests sensor to start polling for data. | 139 * Requests sensor to start polling for data. |
| 128 * | 140 * |
| 129 * @return boolean true if successful, false otherwise. | 141 * @return boolean true if successful, false otherwise. |
| 130 */ | 142 */ |
| 131 @CalledByNative | 143 @CalledByNative |
| 132 protected boolean startSensor(double frequency) { | 144 protected boolean startSensor(double frequency) { |
| 133 // If we already polling hw with same frequency, do not restart the sens or. | 145 // If we already polling hw with same frequency, do not restart the sens or. |
| 134 if (mCurrentPollingFrequency == frequency) return true; | 146 if (mCurrentPollingFrequency == frequency) return true; |
| 135 | 147 |
| 136 // Unregister old listener if polling frequency has changed. | 148 // Unregister old listener if polling frequency has changed. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 break; | 231 break; |
| 220 default: | 232 default: |
| 221 updateSensorReading(timestamp, event.values[0], event.values[1], event.values[2]); | 233 updateSensorReading(timestamp, event.values[0], event.values[1], event.values[2]); |
| 222 } | 234 } |
| 223 } | 235 } |
| 224 | 236 |
| 225 private native void nativeNotifyPlatformSensorError(long nativePlatformSenso rAndroid); | 237 private native void nativeNotifyPlatformSensorError(long nativePlatformSenso rAndroid); |
| 226 private native void nativeUpdatePlatformSensorReading(long nativePlatformSen sorAndroid, | 238 private native void nativeUpdatePlatformSensorReading(long nativePlatformSen sorAndroid, |
| 227 double timestamp, double value1, double value2, double value3); | 239 double timestamp, double value1, double value2, double value3); |
| 228 } | 240 } |
| OLD | NEW |