mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
Bug 871916 - Add empty event listener for devicemotion for devices depending on this. r=fabrice
This commit is contained in:
parent
e0a50dcca6
commit
1d187f9272
@ -1236,3 +1236,50 @@ Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.prefs.setIntPref("browser.cache.disk.capacity", size);
|
||||
}) ()
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
let SensorsListener = {
|
||||
sensorsListenerDevices: ['crespo'],
|
||||
device: libcutils.property_get("ro.product.device"),
|
||||
|
||||
deviceNeedsWorkaround: function SensorsListener_deviceNeedsWorkaround() {
|
||||
return (this.sensorsListenerDevices.indexOf(this.device) != -1);
|
||||
},
|
||||
|
||||
handleEvent: function SensorsListener_handleEvent(evt) {
|
||||
switch(evt.type) {
|
||||
case 'devicemotion':
|
||||
// Listener that does nothing, we need this to have the sensor being
|
||||
// able to report correct values, as explained in bug 753245, comment 6
|
||||
// and in bug 871916
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
observe: function SensorsListener_observe(subject, topic, data) {
|
||||
// We remove the listener when the screen is off, otherwise sensor will
|
||||
// continue to bother us with data and we won't be able to get the
|
||||
// system into suspend state, thus draining battery.
|
||||
if (data === 'on') {
|
||||
window.addEventListener('devicemotion', this);
|
||||
} else {
|
||||
window.removeEventListener('devicemotion', this);
|
||||
}
|
||||
},
|
||||
|
||||
init: function SensorsListener_init() {
|
||||
if (this.deviceNeedsWorkaround()) {
|
||||
// On boot, enable the listener, screen will be on.
|
||||
window.addEventListener('devicemotion', this);
|
||||
|
||||
// Then listen for further screen state changes
|
||||
Services.obs.addObserver(this, 'screen-state-changed', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SensorsListener.init();
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user