tree: 210eda9c56508d4aa0d409c9c55c0b3737ce234a [path history] [tgz]
  1. BUILD.gn
  2. DEPS
  3. OWNERS
  4. README.md
  5. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer.cc
  6. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer.h
  7. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer_unittest.cc
  8. android/
  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. linux/
  19. orientation_euler_angles_fusion_algorithm_using_quaternion.cc
  20. orientation_euler_angles_fusion_algorithm_using_quaternion.h
  21. orientation_euler_angles_fusion_algorithm_using_quaternion_unittest.cc
  22. orientation_quaternion_fusion_algorithm_using_euler_angles.cc
  23. orientation_quaternion_fusion_algorithm_using_euler_angles.h
  24. orientation_quaternion_fusion_algorithm_using_euler_angles_unittest.cc
  25. orientation_test_data.h
  26. orientation_util.cc
  27. orientation_util.h
  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_win.cc
  71. platform_sensor_win.h
  72. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.cc
  73. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.h
  74. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope.cc
  75. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope.h
  76. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope_unittest.cc
  77. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_unittest.cc
  78. sensor_impl.cc
  79. sensor_impl.h
  80. sensor_provider_impl.cc
  81. sensor_provider_impl.h
  82. windows/
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.