File: platform_sensor_util.h

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 3,309 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_UTIL_H_
#define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_UTIL_H_

#include "services/device/public/cpp/generic_sensor/sensor_reading.h"
#include "services/device/public/mojom/sensor.mojom-shared.h"

namespace device {

// Sensors are accurate enough that it is possible to sample sensor data to
// implement a "fingerprint attack" to reveal the sensor calibration data.
// This data is effectively a unique number, or fingerprint, for a device. To
// combat this, sensor values are rounded to the nearest multiple of some small
// number. This is still accurate enough to satisfy the needs of the sensor
// user, but guards against this attack.
//
// Additional info can be found at https://crbug.com/1018180.
//
// Rounding also protects against using the gyroscope as a primitive microphone
// to record audio. Additional info at https://crbug.com/1031190.

// Units are SI meters per second squared (m/s^2).
inline constexpr double kAccelerometerRoundingMultiple = 0.1;

// Units are luxes (lx).
inline constexpr int kAlsRoundingMultiple = 50;

// Units are radians/second. This value corresponds to 0.1 deg./sec.
inline constexpr double kGyroscopeRoundingMultiple = 0.00174532925199432963;

// Units are degrees.
inline constexpr double kOrientationEulerRoundingMultiple = 0.1;

// Units are radians. This value corresponds to 0.1 degrees.
inline constexpr double kOrientationQuaternionRoundingMultiple =
    0.0017453292519943296;

// Units are micro Teslas (μT).
inline constexpr double kMagnetometerRoundingMultiple = 0.01;

// Some sensor types also ignore value changes below a certain threshold to
// avoid exposing whether a value is too close to the limit between one
// rounded value and the next.
inline constexpr int kAlsSignificanceThreshold = kAlsRoundingMultiple / 2;

// Round |value| to be a multiple of |multiple|.
//
// NOTE: Exposed for testing. Please use other Rounding functions below.
//
// Some examples:
//
// ( 1.24, 0.1) => 1.2
// ( 1.25, 0.1) => 1.3
// (-1.24, 0.1) => -1.2
// (-1.25, 0.1) => -1.3
double RoundToMultiple(double value, double multiple);

// Round accelerometer sensor reading to guard user privacy.
void RoundAccelerometerReading(SensorReadingXYZ* reading);

// Round gyroscope sensor reading to guard user privacy.
void RoundGyroscopeReading(SensorReadingXYZ* reading);

// Round ambient light sensor reading to guard user privacy.
void RoundIlluminanceReading(SensorReadingSingle* reading);

// Round orientation Euler angle sensor reading to guard user privacy.
void RoundOrientationEulerReading(SensorReadingXYZ* reading);

// Round orientation quaternion sensor reading to guard user privacy.
// |reading| is assumed to be unscaled (unit length).
void RoundOrientationQuaternionReading(SensorReadingQuat* reading);

// Round magnetometer reading to guard user privacy.
void RoundMagnetometerReading(SensorReadingXYZ* reading);

// Round the sensor reading to guard user privacy.
void RoundSensorReading(SensorReading* reading, mojom::SensorType sensor_type);

}  // namespace device

#endif  // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_UTIL_H_