Comment 53 for bug 604635

Revision history for this message
In , Kchen-d (kchen-d) wrote :

(In reply to Justin Lebar [:jlebar] from bug 708964 comment #7)
> > nsIDOMMozWakeLock requestWakeLock(in ACString topic);
>
> Is this not the function exposed to content? I expected we'd expose this to
> content (maybe privileged content only, but at least apps) and then have
> some API for our "chrome" to tell whether wake locks are held (see e.g.
> https://github.com/andreasgal/gaia/issues/167#issuecomment-3101666).

It is only for locking the CPU. I think apps should use a full-fledged pw mgmt implemented in JS.

Apps can lock some resources (cpu, screen, peripherals, etc)

Power manager could turn off the resource after some period of idle
time, if nobody is using them. Something like:

   #+begin_example
   PowerManager = function() {}
   PowerManager.prototype = {
     screenTimeout: 30,
     init: function () {
       idle.addIdleObserver(this, screenTimeout);
     },
     lock: function (aTopic, aWho) {
       let wl = {};
       switch (aTopic) {
       case "cpu":
         wl = mozPower.requestWakeLock(aWho);
         break;
       default:
         wl = {isHeld: true, topic: aTopic};
         break;
       }
       locks.push(wl);
       return wl;
     },
     observe: function(aSubject, aTopic, aData) {
       switch (aTopic) {
       case "idle":
         for (let i = 0; i < locks.length; i++) {
           if (locks[i].isHeld) {
             return;
           }
         }
         mozPower.sleep();
       }
     }
   }
   #+end_example

Should apps be able to turn on/off the peripherals as well?
If yes then they should also check the locks.