platform_sensor_util.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_UTIL_H_
  5. #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_UTIL_H_
  6. #include "services/device/public/cpp/generic_sensor/sensor_reading.h"
  7. namespace device {
  8. // Sensors are accurate enough that it is possible to sample sensor data to
  9. // implement a "fingerprint attack" to reveal the sensor calibration data.
  10. // This data is effectively a unique number, or fingerprint, for a device. To
  11. // combat this, sensor values are rounded to the nearest multiple of some small
  12. // number. This is still accurate enough to satisfy the needs of the sensor
  13. // user, but guards against this attack.
  14. //
  15. // Additional info can be found at https://crbug.com/1018180.
  16. //
  17. // Rounding also protects against using the gyroscope as a primitive microphone
  18. // to record audio. Additional info at https://crbug.com/1031190.
  19. // Units are SI meters per second squared (m/s^2).
  20. constexpr double kAccelerometerRoundingMultiple = 0.1;
  21. // Units are luxes (lx).
  22. constexpr int kAlsRoundingMultiple = 50;
  23. // Units are radians/second. This value corresponds to 0.1 deg./sec.
  24. constexpr double kGyroscopeRoundingMultiple = 0.00174532925199432963;
  25. // Units are degrees.
  26. constexpr double kOrientationEulerRoundingMultiple = 0.1;
  27. // Units are radians. This value corresponds to 0.1 degrees.
  28. constexpr double kOrientationQuaternionRoundingMultiple = 0.0017453292519943296;
  29. // Some sensor types also ignore value changes below a certain threshold to
  30. // avoid exposing whether a value is too close to the limit between one
  31. // rounded value and the next.
  32. constexpr int kAlsSignificanceThreshold = kAlsRoundingMultiple / 2;
  33. // Round |value| to be a multiple of |multiple|.
  34. //
  35. // NOTE: Exposed for testing. Please use other Rounding functions below.
  36. //
  37. // Some examples:
  38. //
  39. // ( 1.24, 0.1) => 1.2
  40. // ( 1.25, 0.1) => 1.3
  41. // (-1.24, 0.1) => -1.2
  42. // (-1.25, 0.1) => -1.3
  43. double RoundToMultiple(double value, double multiple);
  44. // Round accelerometer sensor reading to guard user privacy.
  45. void RoundAccelerometerReading(SensorReadingXYZ* reading);
  46. // Round gyroscope sensor reading to guard user privacy.
  47. void RoundGyroscopeReading(SensorReadingXYZ* reading);
  48. // Round ambient light sensor reading to guard user privacy.
  49. void RoundIlluminanceReading(SensorReadingSingle* reading);
  50. // Round orientation Euler angle sensor reading to guard user privacy.
  51. void RoundOrientationEulerReading(SensorReadingXYZ* reading);
  52. // Round orientation quaternion sensor reading to guard user privacy.
  53. // |reading| is assumed to be unscaled (unit length).
  54. void RoundOrientationQuaternionReading(SensorReadingQuat* reading);
  55. // Round the sensor reading to guard user privacy.
  56. void RoundSensorReading(SensorReading* reading, mojom::SensorType sensor_type);
  57. } // namespace device
  58. #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_UTIL_H_