PowerManager

Did you know that you can read content offline by using one of these tools? If you would like to read offline MDN content in another format, let us know by commenting on Bug 665750.

Dash App
この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

« DOM Reference

Non-standard

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

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

Interface overview

callback wakeLockListener = void (DOMString topic, DOMString state);

interface PowerManager
{
  attribute boolean cpuSleepAllowed
  attribute double screenBrightness
  attribute boolean screenEnabled

  void addWakeLockListener(wakeLockListener listener);
  void factoryReset();
  DOMString getWakeLockState(DOMString topic);
  void powerOff();
  void reboot();
  void removeWakeLockListener(wakeLockListener listener);  
};

Properties

PowerManager.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.
PowerManager.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.
PowerManager.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

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

Example

var screenTimeout;
var power = window.navigator.mozPower;
var powerAction = /old?u=https%3A%2F%2Fdeveloper.mozilla.org%2Fja%2Fdocs%2FWeb%2FAPI%2F%7B&y=1999
  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

タグ (8)