tree: fb3f4d780b780271095d6de65300b0db5be528a6 [path history] [tgz]
  1. android/
  2. linux/
  3. windows/
  4. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer.cc
  5. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer.h
  6. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer_unittest.cc
  7. BUILD.gn
  8. DEPS
  9. fake_platform_sensor_and_provider.cc
  10. fake_platform_sensor_and_provider.h
  11. fake_platform_sensor_fusion.cc
  12. fake_platform_sensor_fusion.h
  13. generic_sensor_consts.h
  14. generic_sensor_service_unittest.cc
  15. linear_acceleration_fusion_algorithm_using_accelerometer.cc
  16. linear_acceleration_fusion_algorithm_using_accelerometer.h
  17. linear_acceleration_fusion_algorithm_using_accelerometer_unittest.cc
  18. orientation_euler_angles_fusion_algorithm_using_quaternion.cc
  19. orientation_euler_angles_fusion_algorithm_using_quaternion.h
  20. orientation_euler_angles_fusion_algorithm_using_quaternion_unittest.cc
  21. orientation_quaternion_fusion_algorithm_using_euler_angles.cc
  22. orientation_quaternion_fusion_algorithm_using_euler_angles.h
  23. orientation_quaternion_fusion_algorithm_using_euler_angles_unittest.cc
  24. orientation_test_data.h
  25. orientation_util.cc
  26. orientation_util.h
  27. OWNERS
  28. platform_sensor.cc
  29. platform_sensor.h
  30. platform_sensor_accelerometer_mac.cc
  31. platform_sensor_accelerometer_mac.h
  32. platform_sensor_ambient_light_mac.cc
  33. platform_sensor_ambient_light_mac.h
  34. platform_sensor_and_provider_unittest.cc
  35. platform_sensor_and_provider_unittest_linux.cc
  36. platform_sensor_and_provider_unittest_win.cc
  37. platform_sensor_android.cc
  38. platform_sensor_android.h
  39. platform_sensor_fusion.cc
  40. platform_sensor_fusion.h
  41. platform_sensor_fusion_algorithm.cc
  42. platform_sensor_fusion_algorithm.h
  43. platform_sensor_fusion_unittest.cc
  44. platform_sensor_linux.cc
  45. platform_sensor_linux.h
  46. platform_sensor_provider.cc
  47. platform_sensor_provider.h
  48. platform_sensor_provider_android.cc
  49. platform_sensor_provider_android.h
  50. platform_sensor_provider_base.cc
  51. platform_sensor_provider_base.h
  52. platform_sensor_provider_linux.cc
  53. platform_sensor_provider_linux.h
  54. platform_sensor_provider_mac.cc
  55. platform_sensor_provider_mac.h
  56. platform_sensor_provider_unittest_android.cc
  57. platform_sensor_provider_win.cc
  58. platform_sensor_provider_win.h
  59. platform_sensor_provider_winrt.cc
  60. platform_sensor_provider_winrt.h
  61. platform_sensor_provider_winrt_unittest.cc
  62. platform_sensor_reader_linux.cc
  63. platform_sensor_reader_linux.h
  64. platform_sensor_reader_win.cc
  65. platform_sensor_reader_win.h
  66. platform_sensor_reader_win_base.h
  67. platform_sensor_reader_winrt.cc
  68. platform_sensor_reader_winrt.h
  69. platform_sensor_reader_winrt_unittests.cc
  70. platform_sensor_util.cc
  71. platform_sensor_util.h
  72. platform_sensor_util_unittest.cc
  73. platform_sensor_win.cc
  74. platform_sensor_win.h
  75. README.md
  76. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.cc
  77. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.h
  78. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope.cc
  79. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope.h
  80. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope_unittest.cc
  81. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_unittest.cc
  82. sensor_impl.cc
  83. sensor_impl.h
  84. sensor_provider_impl.cc
  85. sensor_provider_impl.h
services/device/generic_sensor/README.md

Sensors

services/device/generic_sensor contains the platform-specific parts of the Sensor APIs implementation.

Sensors Mojo interfaces are defined in the services/device/public/mojom subdirectory.

Web-exposed Interfaces

Generic Sensors

The Generic Sensors API is implemented in third_party/blink/renderer/modules/sensor and exposes the following sensor types as JavaScript objects:

DeviceOrientation Events

The DeviceOrientation Events API is implemented in third_party/blink/renderer/modules/device_orientation and exposes two events based on the following sensors:

  • DeviceMotionEvent
    • ACCELEROMETER: populates the accelerationIncludingGravity field
    • LINEAR_ACCELEROMETER: populates the acceleration field
    • GYROSCOPE: populates the rotationRate field
  • DeviceOrientationEvent
    • ABSOLUTE_ORIENTATION_EULER_ANGLES (when a listener for the 'deviceorientationabsolute' event is added)
    • RELATIVE_ORIENTATION_EULER_ANGLES (when a listener for the 'deviceorientation' event is added)

The content renderer layer is located in third_party/blink/renderer/modules/device_orientation.

Testing:

  • Browser tests are located in content/browser/device_sensors.
  • Layout tests are located in third_party/WebKit/LayoutTests/device_orientation.
  • Web platform tests are located in third_party/WebKit/LayoutTests/external/wpt/orientation-event and are a mirror of the web-platform-tests GitHub repository.

Permissions

The device service provides no support for permission checks. When the render process requests access to a sensor type this request is proxied through the browser process by SensorProviderProxyImpl which is responsible for checking the permissions granted to the requesting origin.

Platform Support

Support for the SensorTypes defined by the Mojo interface is summarized in this table. An empty cell indicates that the sensor type is not supported on that platform.

SensorTypeAndroidLinuxmacOSWindows
AMBIENT_LIGHTTYPE_LIGHTin_illuminanceAppleLMUControllerYes
PROXIMITY
ACCELEROMETERTYPE_ACCELEROMETERin_accelSMCMotionSensorYes
LINEAR_ACCELEROMETERSee belowACCELEROMETER (*)ACCELEROMETER (*)
GYROSCOPETYPE_GYROSCOPEin_anglvelYes
MAGNETOMETERTYPE_MAGNETIC_FIELDin_magnYes
PRESSURE
ABSOLUTE_ORIENTATION_EULER_ANGLESSee belowACCELEROMETER and MAGNETOMETER (*)Yes
ABSOLUTE_ORIENTATION_QUATERNIONSee belowABSOLUTE_ORIENTATION_EULER_ANGLES (*)Yes
RELATIVE_ORIENTATION_EULER_ANGLESSee belowACCELEROMETER and GYROSCOPE (*)ACCELEROMETER (*)
or ACCELEROMETER (*)
RELATIVE_ORIENTATION_QUATERNIONTYPE_GAME_ROTATION_VECTORRELATIVE_ORIENTATION_EULER_ANGLES (*)RELATIVE_ORIENTATION_EULER_ANGLES (*)

(Note: “*” means the sensor type is provided by sensor fusion.)

Android

Sensors are implemented by passing through values provided by the Sensor class. The TYPE_* values in the below descriptions correspond to the integer constants from the android.hardware.Sensor used to provide data for a SensorType.

For LINEAR_ACCELEROMETER, the following sensor fallback is used:

  1. Use TYPE_LINEAR_ACCELERATION directly
  2. ACCELEROMETER, with a low-pass filter to isolate the effect of gravity

For ABSOLUTE_ORIENTATION_EULER_ANGLES, the following sensor fallback is used:

  1. ABSOLUTE_ORIENTATION_QUATERNION (if it uses TYPE_ROTATION_VECTOR directly)
  2. Combination of ACCELEROMETER and MAGNETOMETER

For ABSOLUTE_ORIENTATION_QUATERNION, the following sensor fallback is used:

  1. Use TYPE_ROTATION_VECTOR directly
  2. ABSOLUTE_ORIENTATION_EULER_ANGLES

For RELATIVE_ORIENTATION_EULER_ANGLES, converts the data produced by RELATIVE_ORIENTATION_QUATERNION to euler angles.

Linux (and Chrome OS)

Sensors are implemented by reading values from the IIO subsystem. The values in the “Linux” column of the table above are the prefix of the sysfs files Chrome searches for to provide data for a SensorType. The ABSOLUTE_ORIENTATION_EULER_ANGLES sensor type is provided by interpreting the value that can be read from the ACCELEROMETER and MAGNETOMETER. The ABSOLUTE_ORIENTATION_QUATERNION sensor type is provided by interpreting the value that can be read from the ABSOLUTE_ORIENTATION_EULER_ANGLES. The RELATIVE_ORIENTATION_EULER_ANGLES sensor type is provided by interpreting the value that can be read from the ACCELEROMETER and GYROSCOPE, or ACCELEROMETER. The RELATIVE_ORIENTATION_QUATERNION sensor type is provided by interpreting the value that can be read from the RELATIVE_ORIENTATION_EULER_ANGLES. LINEAR_ACCELEROMETER sensor type is provided by implementing a low-pass-filter over the values returned by the ACCELEROMETER in order to remove the contribution of the gravitational force.

macOS

On this platform there is limited support for sensors. The AMBIENT_LIGHT sensor type is provided by interpreting the value that can be read from the LMU. The ACCELEROMETER sensor type is provided by interpreting the value that can be read from the SMCMotionSensor. The RELATIVE_ORIENTATION_EULER_ANGLES sensor type is provided by interpreting the value that can be read from the ACCELEROMETER. The RELATIVE_ORIENTATION_QUATERNION sensor type is provided by interpreting the value that can be read from the RELATIVE_ORIENTATION_EULER_ANGLES.

Windows

Please refer to this document.

Testing

Sensors platform unit tests are located in the current directory and its subdirectories.

The sensors unit tests file for Android is android/junit/src/org/chromium/device/sensors/PlatformSensorAndProviderTest.java.

Sensors browser tests are located in content/test/data/generic_sensor.

Design Documents

Please refer to the design documentation for more details.