Skip to content

Commit 368aa53

Browse files
author
Raphael Kubo da Costa
committed
Overhaul frequency management in the specification
This commit addresses a few issues with the way frequency management was handled in the specification: 1. "Sampling frequency" was interchangeably used as a number as well as an interval ("sampling frequency bounds"), and the latter was not even properly defined. 2. The actual bounds were not properly defined, and neither was the clamping process that used them. 3. There were too many frequency-related terms in use. Let us start with the changes in the concepts and definitions: - A platform sensor has a sampling frequency, a positive number or null. It represents the frequency at which the platform sensor attempts to retrieve data from the device sensor and it is calculated in an implementation-defined manner based on the `[[frequency]]` of the associated Sensor objects. It is therefore a mixture of the previous "sampling frequency" and "requested sampling frequency" definitions. . How the sampling process works is implementation-defined: it could be polling, or requesting updates at this interval, or something else entirely. - A device sensor has a sampling frequency. It is similar to the above, but operating system or hardware dependent and opaque to this specification. . As such, the device sensor may choose a sampling frequency that differs from the platform sensor's sampling frequency and we have no control over it. - A device sensor MAY report lower and/or upper sampling frequency bounds. With the above, the actual sampling bounds are defined and checked: - A sensor type MUST have lower and upper sampling frequency bounds. The lower bound is "max(implementation-defined value, optional spec-defined value)", and the upper bound is "min(implementation-defined value, optional spec-defined value)". - A new algorithm returns a platform sensor's lower and upper sampling bounds as a tuple "(max(optional device sensor lower bound, sensor type lower bound), min(optional device sensor upper bound, sensor type upper bound))". - A Sensor's `[[frequency]]` is always set to a value within a platform sensor's sampling bounds in "Connect to a sensor" (before that it might not have an associated platform sensor and should be in the "activated" state). - "Set sensor settings" requires that the platform sensor sampling value calculated based on its associated sensors' `[[frequency]]` values lies within its sampling bounds. The "optimal sampling frequency" and "requested sampling frequency" <dfn>s have been removed, and so has the "Find the reporting frequency of a sensor object" algorithm, which addresses point (3). The "Automation" section has only received enough changes to avoid Bikeshed errors and warnings, as the entire section is being rewritten. Related to w3c#463.
1 parent 9622f30 commit 368aa53

File tree

1 file changed

+109
-89
lines changed

1 file changed

+109
-89
lines changed

index.bs

+109-89
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,15 @@ etc.
466466

467467
<h4 id="limit-max-frequency" dfn>Limit maximum sampling frequency</h4>
468468

469-
User agents may mitigate certain threats by
470-
limiting the maximum [=sampling frequency=].
469+
User agents and [=extension specifications=] may mitigate certain threats by defining a [=sensor
470+
type=]'s [=sensor type/maximum sampling frequency=].
471+
471472
What upper limit to choose depends on the [=sensor type=],
472473
the kind of threats the user agent is trying to protect against,
473474
the expected resources of the attacker, etc.
474475

475-
Limiting the maximum [=sampling frequency=] prevents use cases
476-
which rely on low latency or high data density.
476+
Limiting the [=sensor type/maximum sampling frequency=] prevents use cases which rely on low
477+
latency or high data density.
477478

478479

479480
<h4 id="stop-sensor" dfn>Stop the sensor altogether</h4>
@@ -489,9 +490,9 @@ or in a different application.
489490

490491
An alternative to [=limit maximum sampling frequency|limiting the maximum sampling frequency=] is to
491492
limit the number of [=sensor readings=] delivered to Web application developer,
492-
regardless of what frequency the sensor is polled at.
493+
regardless of the [=sampling frequency=].
493494
This allows use cases which have low latency requirement
494-
to increase [=sampling frequency=]
495+
to increase the [=sampling frequency=]
495496
without increasing the amount of data provided.
496497

497498
Discarding intermediary readings prevents certain use cases,
@@ -721,32 +722,52 @@ define ways to uniquely identify each one.
721722

722723
## Sampling Frequency and Reporting Frequency ## {#concepts-sampling-and-reporting-frequencies}
723724

724-
For the purpose of this specification, <dfn>sampling frequency</dfn> for a [=platform sensor=] is
725-
defined as a frequency at which the user agent obtains [=sensor readings=] from the underlying
726-
platform.
725+
For the purpose of this specification, a [=platform sensor=]'s <dfn>sampling frequency</dfn> is
726+
defined as a frequency at which a [=platform sensor=] obtains [=sensor readings=] from the
727+
underlying [=device sensor=]. The way such [=sensor readings=] are obtained is
728+
[=implementation-defined=].
727729

728-
The user agent can request the underlying platform to deliver [=sensor readings|readings=] at a certain
729-
rate which is called <dfn>requested sampling frequency</dfn>.
730+
Note: The user agent can, for example, poll the operating system/[=device sensor=], or register for
731+
operating system notifications.
730732

731-
The [=sampling frequency=] is equal to the [=requested sampling frequency=] if the underlying platform
732-
can support it.
733+
The [=platform sensor=]'s [=sampling frequency=] may not correspond to the [=device sensor=]'s
734+
actual sampling rate, which, for the purpose of this specification, is opaque.
733735

734-
The [=sampling frequency=] differs from the [=requested sampling frequency=] in the following cases:
735-
- the [=requested sampling frequency=] exceeds upper or lower [=sampling frequency=] bounds
736-
supported by the underlying platform.
737-
- the operating system and/or the [=device sensor=] automatically discard
738-
readings that do not differ enough (in absolute or relative terms) from the
739-
previously reported ones via a hardware or operating system filter.
740-
- the [=platform sensor=]'s associated [=sensor type=]'s [=threshold check
741-
algorithm=] fails and the [=platform sensor=]'s [=latest readings=] are not
742-
updated.
736+
A [=device sensor=] may provide bounds for the sampling frequency value it can accept from a
737+
[=platform sensor=] in the form of a <dfn for="device sensor">minimum sampling frequency</dfn> and a
738+
<dfn for= "device sensor">maximum sampling frequency</dfn>. A [=platform sensor=]'s [=sampling
739+
frequency=] must not be less than the [=device sensor=]'s [=device sensor/minimum sampling
740+
frequency=] or greater than its [=device sensor/maximum sampling frequency=].
741+
742+
A [=platform sensor=]'s [=sampling frequency=] is determined based on the provided
743+
{{Sensor/[[frequency]]}} of the [=set/items=] in its [=ordered set|set=] of [=activated sensor
744+
objects=]. The calculation is [=implementation-defined=], but the outcome value must lie within the
745+
bounds set by the [=platform sensor=]'s [=sensor type=]'s [=sensor type/minimum sampling
746+
frequency|minimum=] and [=sensor type/maximum sampling frequency|maximum=] sampling frequencies and
747+
its [=device sensor=]'s [=device sensor/minimum sampling frequency|minimum=] and [=device
748+
sensor/maximum sampling frequency|maximum=] sampling frequencies.
749+
750+
Note: For example, the user agent may estimate the [=sampling frequency=] as a Least Common
751+
Denominator (LCD) for a set of provided {{Sensor/[[frequency]]}} capped by [=sampling frequency=]
752+
bounds defined by the underlying platform.
743753

744754
The <dfn>reporting frequency</dfn> for a concrete {{Sensor}} object is defined as a frequency at which
745755
the "reading" event is [=fire an event|fired=] at this object.
746756

747757
A {{Sensor}} object cannot access new [=sensor readings|readings=] at a higher rate than the
748758
user agent obtains them from the underlying platform, therefore the [=reporting frequency=] can
749-
never exceed the [=sampling frequency=] for the given [=sensor type=].
759+
never exceed a [=platform sensor=]'s [=sampling frequency=], which in turn can never exceed a
760+
[=device sensor=]'s [=device sensor/maximum sampling frequency=] (when specified).
761+
762+
The [=reporting frequency=] differs from the {{Sensor}}'s {{Sensor/[[frequency]]}} in cases such as:
763+
- the requested {{Sensor/[[frequency]]}} lies outside the bounds returned by invoking [=get a
764+
platform sensor's sampling bounds=] with {{Sensor}}'s associated [=platform sensor=].
765+
- the operating system and/or the [=device sensor=] automatically discard
766+
readings that do not differ enough (in absolute or relative terms) from the
767+
previously reported ones via a hardware or operating system filter.
768+
- the {{Sensor}} instance's associated [=sensor type=]'s [=threshold check
769+
algorithm=] fails and the [=platform sensor=]'s [=latest readings=] are not
770+
updated.
750771

751772
## Conditions to expose sensor readings ## {#concepts-can-expose-sensor-readings}
752773

@@ -781,6 +802,15 @@ A <dfn>sensor type</dfn> must have the following associated data:
781802
- An [=set/is empty|nonempty=] [=ordered set=] of associated [=policy-controlled feature=] tokens
782803
referred to as <dfn export>sensor feature names</dfn>.
783804
- A [=permission revocation algorithm=].
805+
- A <dfn export for="sensor type">minimum sampling frequency</dfn>, a positive number. It is either
806+
[=implementation-defined=] or defined by an [=extension specification=]. If both are set, the
807+
largest value is used.
808+
- A <dfn export for="sensor type">maximum sampling frequency</dfn>, a positive number. It is either
809+
[=implementation-defined=] or defined by an [=extension specification=]. If both are set, the
810+
smallest value is used.
811+
812+
The [=sensor type/minimum sampling frequency=] must not be greater than the [=sensor type/maximum
813+
sampling frequency=].
784814

785815
A [=sensor type=] may have the following associated data:
786816
- A [=default sensor=].
@@ -839,17 +869,21 @@ Note: There are additional privacy concerns when using cached [=sensor readings|
839869
which predate either [=navigating=] to resources in the current [=origin=],
840870
or being granted permission to access the [=platform sensor=]. -->
841871

842-
A [=platform sensor=] has an associated [=requested sampling frequency=] which is initially null.
843-
844-
For a non-[=set/is empty|empty=] [=ordered set|set=] of [=activated sensor objects=] the
845-
[=requested sampling frequency=] is equal to the <dfn>optimal sampling frequency</dfn>, which is estimated
846-
by the user agent by taking into account the {{[[frequency]]|provided frequencies}}
847-
of [=activated sensor objects|activated=] {{Sensor|Sensors}} and the [=sampling frequency=] bounds
848-
defined by the underlying platform.
849-
850-
Note: For example, the user agent may estimate [=optimal sampling frequency=] as a Least Common
851-
Denominator (LCD) for a set of {{[[frequency]]|provided frequencies}} capped
852-
by [=sampling frequency=] bounds defined by the underlying platform.
872+
<div algorithm>
873+
To <dfn>get a platform sensor's sampling bounds</dfn> given a [=platform sensor=]
874+
|platformSensor|:
875+
1. Let |minimumFrequency| be |platformSensor|'s [=sensor type=]'s [=sensor type/minimum sampling
876+
frequency=].
877+
1. If |platformSensor|'s connected [=device sensor=] has a [=device sensor/minimum sampling
878+
frequency=], set |minimumFrequency| to the maximum of |minimumFrequency| and the [=device
879+
sensor/minimum sampling frequency=].
880+
1. Let |maximumFrequency| be |platformSensor|'s [=sensor type=]'s [=sensor type/maximum sampling
881+
frequency=].
882+
1. If |platformSensor|'s connected [=device sensor=] has a [=device sensor/maximum sampling
883+
frequency=], set |maximumFrequency| to the minimum of |maximumFrequency| and the [=device
884+
sensor/maximum sampling frequency=].
885+
1. Return a [=tuple=] (|minimumFrequency|, |maximumFrequency|).
886+
</div>
853887

854888
<div class=example>
855889

@@ -866,7 +900,7 @@ The {{Sensor}} object in "idle" [[#sensor-lifecycle|state]] is not among the [=p
866900
In this example there is a [=platform sensor=] instance per [=browsing context=].
867901

868902
The [=latest reading=] [=ordered map|map=] is shared between {{Sensor}} objects from the
869-
same [=browsing context|context=] and is updated at a rate equal to the [=requested sampling frequency=]
903+
same [=browsing context|context=] and is updated at a rate equal to the requested [=sampling frequency=]
870904
of the corresponding [=platform sensor=].
871905

872906
</div>
@@ -1063,12 +1097,10 @@ with the internal slots described in the following table:
10631097
<tr>
10641098
<td><dfn attribute for=Sensor>\[[frequency]]</dfn></td>
10651099
<td>A double representing frequency in Hz that is used to calculate
1066-
the [=requested sampling frequency=] for the associated [=platform sensor=]
1100+
the [=sampling frequency=] for the associated [=platform sensor=]
10671101
and to define the upper bound of the [=reporting frequency=] for this
1068-
{{Sensor}} object.
1069-
1070-
This slot holds the provided {{SensorOptions}}.{{frequency!!dict-member}} value.
1071-
It is initially unset.</td>
1102+
{{Sensor}} object. It is initially null.
1103+
</td>
10721104
</tr>
10731105
<tr>
10741106
<td><dfn attribute for=Sensor>\[[lastEventFiredAt]]</dfn></td>
@@ -1256,8 +1288,8 @@ to {{SensorErrorEventInit}}.
12561288
1. Set |sensor_instance|.{{[[frequency]]}} to |options|["{{frequency!!dict-member}}"].
12571289

12581290
Note: There is no guarantee that the requested |options|["{{frequency!!dict-member}}"]
1259-
can be respected. The actual [=sampling frequency=] can be calculated using
1260-
{{Sensor}} {{Sensor/timestamp!!attribute}} attributes.
1291+
can be respected. See [[#concepts-sampling-and-reporting-frequencies]] for constraints that
1292+
may be applied.
12611293
</div>
12621294

12631295
<h3 dfn export>Check sensor policy-controlled features</h3>
@@ -1283,24 +1315,30 @@ to {{SensorErrorEventInit}}.
12831315
<div algorithm="connect to sensor">
12841316

12851317
: input
1286-
:: |sensor_instance|, a {{Sensor}} object.
1318+
:: |sensor|, a {{Sensor}} object.
12871319
: output
1288-
:: True if sensor instance was associated with a [=platform sensor=],
1320+
:: True if |sensor| was associated with a [=platform sensor=],
12891321
false otherwise.
12901322

1291-
1. Let |type| be the [=sensor type=] of |sensor_instance|.
1323+
1. Let |platformSensor| be null.
1324+
1. Let |type| be |sensor|'s associated [=sensor type=].
12921325
1. If the device has a single [=device sensor=] which can provide [=sensor readings|readings=]
12931326
for |type|, then
1294-
1. Associate |sensor_instance| with a [=platform sensor=] corresponding
1327+
1. Set |platformSensor| to a [=platform sensor=] corresponding
12951328
to this [=device sensor=].
1296-
1. Return true.
12971329
1. If the device has multiple [=device sensors=] which can provide [=sensor readings|readings=]
12981330
for |type|, then
12991331
1. If |type| has an associated [=default sensor=], then
1300-
1. Associate |sensor_instance| with a [=platform sensor=] corresponding
1301-
to [=default sensor=].
1302-
1. Return true.
1303-
1. Return false.
1332+
1. Set |platformSensor| to a [=platform sensor=] corresponding
1333+
to this [=default sensor|default device sensor=].
1334+
1. If |platformSensor| is null, return false.
1335+
1. Let |bounds| be the result of invoking [=get a platform sensor's sampling bounds=] with
1336+
|platformSensor|.
1337+
1. If |sensor|.{{Sensor/[[frequency]]}} is null, set it to an [=implementation-defined=] value
1338+
dependent on |type|.
1339+
1. If |sensor|.{{Sensor/[[frequency]]}} is less than |bounds|[0], set it to |bounds|[0].
1340+
1. If |sensor|.{{Sensor/[[frequency]]}} is greater than |bounds|[1], set it to |bounds|[1].
1341+
1. Return true.
13041342
</div>
13051343

13061344
<h3 dfn export>Activate a sensor object</h3>
@@ -1361,18 +1399,24 @@ to {{SensorErrorEventInit}}.
13611399
<div algorithm="set sensor settings">
13621400

13631401
: input
1364-
:: |sensor|, a [=platform sensor=].
1402+
:: |platformSensor|, a [=platform sensor=].
13651403
: output
13661404
:: None
13671405

1368-
1. If |sensor|'s set of [=activated sensor objects=] [=set/is empty=],
1369-
1. Set [=requested sampling frequency=] to null.
1370-
1. [=map/For each=] |key| → <var ignore>value</var> of [=latest reading=].
1371-
1. [=map/Set=] [=latest reading=][|key|] to null.
1372-
1. Update the user-agent-specific way in which [=sensor readings=] are obtained from |sensor|
1373-
to no longer provide [=sensor readings|readings=].
1406+
1. If |platformSensor|'s set of [=activated sensor objects=] [=set/is empty=],
1407+
1. Set |platformSensor|'s [=sampling frequency=] to null.
1408+
1. [=map/For each=] |key| → <var ignore>value</var> of |platformSensor|'s [=latest reading=].
1409+
1. [=map/Set=] |platformSensor|'s [=latest reading=][|key|] to null.
1410+
1. Update the [=implementation-defined=] way in which [=sensor readings=] are obtained
1411+
from |platformSensor| to no longer provide [=sensor readings|readings=].
13741412
1. Return.
1375-
1. Set [=requested sampling frequency=] to [=optimal sampling frequency=].
1413+
1. Set |platformSensor|'s [=sampling frequency=] to an [=implementation-defined=] value based
1414+
on the {{Sensor/[[frequency]]}} values of the items in its [=activated sensor objects=]
1415+
[=ordered set|set=].
1416+
1. Let |bounds| be the result of invoking [=get a platform sensor's sampling bounds=] with
1417+
|platformSensor|.
1418+
1. [=Assert=]: |platformSensor|'s [=sampling frequency=] is greater than or equal to
1419+
|bounds|[0] and less than or equal to |bounds|[1].
13761420
</div>
13771421

13781422
<h3 dfn export>Update latest reading</h3>
@@ -1400,25 +1444,6 @@ to {{SensorErrorEventInit}}.
14001444
1. Invoke [=report latest reading updated=] with |s| as an argument.
14011445
</div>
14021446

1403-
<h3 dfn export>Find the reporting frequency of a sensor object</h3>
1404-
1405-
<div algorithm="find the reporting frequency of a sensor object">
1406-
1407-
: input
1408-
:: |sensor_instance|, a {{Sensor}} object.
1409-
: output
1410-
:: [=reporting frequency=] in Hz.
1411-
1412-
1. Let |frequency| be null.
1413-
1. Let |f| be |sensor_instance|.{{[[frequency]]}}.
1414-
1. if |f| is set,
1415-
1. set |frequency| to |f| capped by the upper and lower [=sampling frequency=]
1416-
bounds for the associated [=platform sensor=].
1417-
1. Otherwise,
1418-
1. user agent can assign |frequency| to an appropriate value.
1419-
1. return |frequency|.
1420-
</div>
1421-
14221447
<h3 dfn export>Report latest reading updated</h3>
14231448

14241449
<div algorithm="report latest reading updated">
@@ -1435,11 +1460,9 @@ to {{SensorErrorEventInit}}.
14351460
1. If |lastReportedTimestamp| is not set
14361461
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
14371462
1. Return.
1438-
1. Let |reportingFrequency| be result of invoking [=Find the reporting frequency of a sensor object=].
1439-
1. If |reportingFrequency| is null
1440-
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
1441-
1. Return.
1442-
1. Let |reportingInterval| be the result of 1 / |reportingFrequency|.
1463+
1. [=Assert=]: |sensor_instance|.{{Sensor/[[frequency]]}} is not null.
1464+
1. [=Assert=]: |sensor_instance|.{{Sensor/[[frequency]]}} is greater than 0.
1465+
1. Let |reportingInterval| be the result of 1 / |sensor_instance|.{{Sensor/[[frequency]]}}.
14431466
1. Let |timestampDelta| be the result of [=latest reading=]["timestamp"] - |lastReportedTimestamp|.
14441467
1. If |timestampDelta| is greater than or equal to |reportingInterval|
14451468
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
@@ -1566,13 +1589,10 @@ and whose initial [=map/values=] are implementation-dependent.
15661589

15671590
Note: The user agent must provide the [=mock sensor reading=] that are initially exposed to the {{Sensor}} objects.
15681591

1569-
A [=mock sensor=] has an associated [=requested sampling frequency=]. Its default value is implementation-dependent
1570-
but must be set within a [=mock sensor=]'s associated [=sampling frequency=] bounds.
1571-
15721592
A [=mock sensor=] has an associated [=sampling frequency=] with supported bounds. The default values of
15731593
supported bounds are implementation-dependent.
15741594

1575-
A [=mock sensor=] must report the [=mock sensor reading=] at the rate of its [=requested sampling frequency=]
1595+
A [=mock sensor=] must report the [=mock sensor reading=] at the rate of its [=sampling frequency=]
15761596
if the user agent [=can expose sensor readings=] to the [=current browsing context=]'s [=active document=].
15771597

15781598
Note: The [=mock sensor=] defined in this specification is not intended be used by non-testing-related web content.
@@ -1624,7 +1644,7 @@ The {{MockSensor}} dictionary provides information about a [=mock sensor=].
16241644
:: A double representing frequency in Hz that indicates the minimum supported [=sampling frequency=] of the associated [=mock sensor=].
16251645

16261646
: {{MockSensor/requestedSamplingFrequency}} member
1627-
:: A double representing frequency in Hz that indicates the [=requested sampling frequency=] of the associated [=mock sensor=].
1647+
:: A double representing frequency in Hz that indicates the [=sampling frequency=] of the associated [=mock sensor=].
16281648

16291649
A <dfn>serialized mock sensor</dfn> is a JSON [=Object=] where a [=mock sensor=]'s fields listed in the {{MockSensor}} dictionary are mapped
16301650
using the <i>JSON Key</i> and the associated field's value from the available [=mock sensor=] in [=current browsing context=].
@@ -2002,7 +2022,7 @@ creating multiple instances of the same [=sensor type=] and using simple {{Senso
20022022
handler.
20032023

20042024
Conversely, multiple {{Sensor|Sensors}} of the same [=sensor type=] can be created when they
2005-
are intended to be used with different settings, such as: [=requested sampling frequency=],
2025+
are intended to be used with different settings, such as: {{SensorOptions/frequency}},
20062026
accuracy or other settings defined in [=extension specifications=].
20072027

20082028
<h3 id="definition-reqs">Definition Requirements</h3>

0 commit comments

Comments
 (0)