tree: 162b8843c048a307116ac94ad3c901d185357f12 [path history] [tgz]
  1. android/
  2. linux/
  3. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer.cc
  4. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer.h
  5. absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer_unittest.cc
  6. BUILD.gn
  7. DEPS
  8. fake_platform_sensor_and_provider.cc
  9. fake_platform_sensor_and_provider.h
  10. fake_platform_sensor_fusion.cc
  11. fake_platform_sensor_fusion.h
  12. generic_sensor_consts.h
  13. generic_sensor_service_unittest.cc
  14. linear_acceleration_fusion_algorithm_using_accelerometer.cc
  15. linear_acceleration_fusion_algorithm_using_accelerometer.h
  16. linear_acceleration_fusion_algorithm_using_accelerometer_unittest.cc
  17. orientation_euler_angles_fusion_algorithm_using_quaternion.cc
  18. orientation_euler_angles_fusion_algorithm_using_quaternion.h
  19. orientation_euler_angles_fusion_algorithm_using_quaternion_unittest.cc
  20. orientation_quaternion_fusion_algorithm_using_euler_angles.cc
  21. orientation_quaternion_fusion_algorithm_using_euler_angles.h
  22. orientation_quaternion_fusion_algorithm_using_euler_angles_unittest.cc
  23. orientation_test_data.h
  24. orientation_util.cc
  25. orientation_util.h
  26. OWNERS
  27. platform_sensor.cc
  28. platform_sensor.h
  29. platform_sensor_accelerometer_mac.cc
  30. platform_sensor_accelerometer_mac.h
  31. platform_sensor_ambient_light_mac.cc
  32. platform_sensor_ambient_light_mac.h
  33. platform_sensor_and_provider_unittest.cc
  34. platform_sensor_and_provider_unittest_linux.cc
  35. platform_sensor_and_provider_unittest_win.cc
  36. platform_sensor_android.cc
  37. platform_sensor_android.h
  38. platform_sensor_fusion.cc
  39. platform_sensor_fusion.h
  40. platform_sensor_fusion_algorithm.cc
  41. platform_sensor_fusion_algorithm.h
  42. platform_sensor_fusion_unittest.cc
  43. platform_sensor_linux.cc
  44. platform_sensor_linux.h
  45. platform_sensor_provider.cc
  46. platform_sensor_provider.h
  47. platform_sensor_provider_android.cc
  48. platform_sensor_provider_android.h
  49. platform_sensor_provider_base.cc
  50. platform_sensor_provider_base.h
  51. platform_sensor_provider_linux.cc
  52. platform_sensor_provider_linux.h
  53. platform_sensor_provider_mac.cc
  54. platform_sensor_provider_mac.h
  55. platform_sensor_provider_unittest_android.cc
  56. platform_sensor_provider_win.cc
  57. platform_sensor_provider_win.h
  58. platform_sensor_reader_linux.cc
  59. platform_sensor_reader_linux.h
  60. platform_sensor_reader_win.cc
  61. platform_sensor_reader_win.h
  62. platform_sensor_win.cc
  63. platform_sensor_win.h
  64. README.md
  65. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.cc
  66. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer.h
  67. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope.cc
  68. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope.h
  69. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope_unittest.cc
  70. relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_unittest.cc
  71. sensor_impl.cc
  72. sensor_impl.h
  73. sensor_provider_impl.cc
  74. 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_illuminanceAppleLMUControllerSENSOR_TYPE_AMBIENT_LIGHT
PROXIMITY
ACCELEROMETERTYPE_ACCELEROMETERin_accelSMCMotionSensorSENSOR_TYPE_ACCELEROMETER_3D
LINEAR_ACCELEROMETERSee belowACCELEROMETER (*)ACCELEROMETER (*)
GYROSCOPETYPE_GYROSCOPEin_anglvelSENSOR_TYPE_GYROMETER_3D
MAGNETOMETERTYPE_MAGNETIC_FIELDin_magnSENSOR_TYPE_COMPASS_3D
PRESSURE
ABSOLUTE_ORIENTATION_EULER_ANGLESSee belowACCELEROMETER and MAGNETOMETER (*)SENSOR_TYPE_INCLINOMETER_3D
ABSOLUTE_ORIENTATION_QUATERNIONSee belowABSOLUTE_ORIENTATION_EULER_ANGLES (*)SENSOR_TYPE_AGGREGATED_DEVICE_ORIENTATION
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

Sensors are implemented by passing through values provided by the Sensor API. The values in the “Windows” column of the table above correspond to the names of the sensor type GUIDs used to provide data for a SensorType. The 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.

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.