Bug 871916 - Add empty event listener for devicemotion for devices depending on this. r=fabrice

This commit is contained in:
Alexandre Lissy 2013-08-03 12:50:18 +02:00
parent e0a50dcca6
commit 1d187f9272

View File

@ -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