Closed Bug 1055939 Opened 10 years ago Closed 10 years ago

Use a proper sensor delay hint when registering sensors callbacks

Categories

(Firefox for Android Graveyard :: General, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 34

People

(Reporter: mfinkle, Assigned: mfinkle)

References

Details

Attachments

(1 file)

Bug 733653 landed a change for some sensors that doesn't look right:
http://hg.mozilla.org/mozilla-central/rev/2aef3c754ff5
https://bugzilla.mozilla.org/show_bug.cgi?id=733653

We are basically changing:
-                sm.registerListener(GeckoApp.mAppContext, gOrientationSensor,   SensorManager.SENSOR_DELAY_GAME);
+                sm.registerListener(GeckoApp.mAppContext, gOrientationSensor,   sDefaultSensorHint);

We assumed that "registerListener" takes a value in milliseconds and we used sDefaultSensorHint set to 100. But "registerListener" uses microseconds:
http://developer.android.com/reference/android/hardware/SensorManager.html#registerListener%28android.hardware.SensorEventListener,%20android.hardware.Sensor,%20int%29

Android docs say that SENSOR_DELAY_NORMAL is 200,000 microseconds. SENSOR_DELAY_GAME is 20,000 microseconds.
http://developer.android.com/guide/topics/sensors/sensors_overview.html

If we really want 100 milliseconds, we should change sDefaultSensorHint to 100000. However, I see the docs say some conflicting information about using the named constants (SENSOR_DELAY_XXX) and passing a custom delay, like sDefaultSensorHint. One doc says custom delays are Android 2.3 (API 9) and higher. The other doc says Android 3.0 (API 11).

To play it safe, I think we should use SENSOR_DELAY_GAME, which is 60 milliseconds or ~17 Hz.
Note that the Android docs don't say that the hint is strictly enforced and that sensor changes can still happen faster than the hint.

We still might want a new bug to add real throttling so we can lower power consumption.
Assignee: nobody → mark.finkle
Attachment #8475704 - Flags: review?(snorp)
Attachment #8475704 - Flags: review?(snorp) → review+
Try run looks fine. The testRetrictedProfiles issue is from a different patch.

https://hg.mozilla.org/integration/fx-team/rev/30c1ec16554a
https://hg.mozilla.org/mozilla-central/rev/30c1ec16554a
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 34
(In reply to Mark Finkle (:mfinkle) from comment #0)
> SENSOR_DELAY_GAME is 20,000 microseconds.
> ...
> To play it safe, I think we should use SENSOR_DELAY_GAME, which is 60
> milliseconds or ~17 Hz.

btw, if SENSOR_DELAY_GAME is 20,000 microseconds, then its sampling rate is 50 Hz, not 17 Hz. Bug 1085789 links to a research paper (about using the device's gyroscope as a side channel to record speech) which unknon stumbled upon the Fennec bug fixed here. The paper says Chrome on Android's sampling rate is 25 Hz and Safari on iOS's is 20 Hz. So Fennec's 50 Hz may be overachieving here because web content will be designed to work with these 20–25 Hz browsers. :)
Blocks: 733653
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: