Skip to content

Commit

Permalink
[sensors] Round off Ambient Light Sensor readouts to the nearest 50 Lux.
Browse files Browse the repository at this point in the history
There have been some concerns regarding the precision of readouts from the
Ambient Light Sensor. To decrease the entropy, we are rounding off the
illuminance value to the nearest 50 Lux to mitigate the known attack
vectors as summarized in [1].

sensor-helpers.js now has a small RingBuffer class that is used to wrap the
readings passed via MockSensor.setSensorReading() so that we iterate over
the array of readings (and wrap around) and every time a reading event is
fired a potentially different value is emitted. This is useful for ALS
because we will no longer be able to use the same value in succession and
expect two reading events to be fired (only one will).

In order to make it easier to implement those changes in sensor-helpers.js,
runGenericSensorTests()'s signature has been simplified and all raw readings
and expected values have a standardized format, an array of arrays, where
each item corresponds to one reading. This also allows us to stop using
Function.prototype.bind() for the reading verification function and be more
explicit in telling which expected value we want in a specific reading
callback.

[1] w3c/ambient-light#13 (comment)

Co-author: Raphael Kubo da Costa

Bug: 642731, 606766
Change-Id: Icc4cfa6b87bd5a87c2cac6ebe322201d7dda6c33
  • Loading branch information
riju authored and chromium-wpt-export-bot committed Aug 16, 2019
1 parent c1e8936 commit b749854
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resources/chromium/generic_sensor_mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ var GenericSensorTest = (() => {
const maxFrequencyHz = this.requestedFrequencies_[0];
const timeoutMs = (1 / maxFrequencyHz) * 1000;
this.sensorReadingTimerId_ = window.setInterval(() => {
// Put an actual value in the buffer so that multiple readings return
// different values.
this.buffer_.set([window.performance.now() * 100], 2);

// For all tests sensor reading should have monotonically
// increasing timestamp in seconds.
this.buffer_[1] = window.performance.now() * 0.001;
Expand Down

0 comments on commit b749854

Please sign in to comment.