• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
B2G OS
  1. MDN
  2. Archive of obsolete content
  3. B2G OS
  4. B2G OS APIs
  5. MozPowerManager

MozPowerManager

In This Article
  1. Properties
  2. Methods
  3. Example
  4. Specification
  5. See also

This API is available on Firefox OS for internal applications only.

The MozPowerManager interface allows to explicitly control the part of the device that uses power.

Properties

MozPowerManager.screenEnabled
This property allows to know if the device's screen is currently enabled (true). This property also controls the device's screen, so setting it to false will turn off the screen.
MozPowerManager.screenBrightness
This property defines how bright the screen's backlight is, on a scale from 0 (very dim) to 1 (full brightness). Setting this attribute modifies the screen's brightness.
MozPowerManager.cpuSleepAllowed
This property determines if the device's CPU will sleep after the screen is disabled. Setting this attribute to false will prevent the device from entering a suspend state.

Methods

MozPowerManager.addWakeLockListener()
Register a handler to be called each time a resource changes its lock state.
MozPowerManager.factoryReset()
Reset the device to its factory state (all the user data will be lost).
MozPowerManager.getWakeLockState()
Return the current lock state of a given topic on the device.
MozPowerManager.powerOff()
Shut off the device.
MozPowerManager.reboot()
Completely shut down and boot the device.
MozPowerManager.removeWakeLockListener()
Remove a handler previously set with addWakeLockListener.

Example

var screenTimeout;
var power = window.navigator.mozPower;
var powerAction = {
  unlocked: function suspendDevice() {
    power.cpuSleepAllowed = true;
    power.screenEnabled   = false;
  },
  'locked-background': function shutOffOnlyScreen() {
    power.cpuSleepAllowed = false;
    power.screenEnabled   = false;
  }
}
function screenLockListener(topic, state) {
  if ('screen' !== topic) return;
  window.clearTimeout(screenTimeout);
  if (powerAction[state]) {
    screenTimeout = window.setTimeout(powerAction[state], 3000);
  }
}
power.addWakeLockListener(screenLockListener);

Specification

Not part of any specification

See also

  • navigator.mozPower
  • navigator.requestWakeLock()

Document Tags and Contributors

Tags: 
  • API
  • B2G
  • Firefox OS
  • Non-standard
  • Power Management
  • Reference
  • Référence
 Contributors to this page: chrisdavidmills, teoli, abhishekp, kscarfone, darnuria, Sheppy, Jeremie
 Last updated by: chrisdavidmills, Feb 27, 2017, 2:07:39 AM
See also
  1. Power Management API
  2. Archive
  3. Related pages for Power Management API
    1. PowerManager