© 2013 Samsung Electronics Co., Ltd. All rights reserved.
This API provides support for requesting power management related resource states.
For more information on the Power features, see Power Guide.
Interface | Method |
---|---|
PowerManagerObject | |
PowerManager | void request(PowerResource resource, PowerState state) void release(PowerResource resource) void setScreenStateChangeListener(ScreenStateChangeCallback listener) void unsetScreenStateChangeListener() double getScreenBrightness() void setScreenBrightness(double brightness) boolean isScreenOn() void restoreScreenBrightness() void turnScreenOn() void turnScreenOff() |
ScreenStateChangeCallback | void onchanged(PowerScreenState previousState, PowerScreenState changedState) |
An enumerator that defines power resources with values aligned with SystemInfo property values.
enum PowerResource { "SCREEN", "CPU" };
We support screen and cpu resources for now. Supported power resource states are provided in PowerScreenState and PowerCpuState enums respectively prefixed by the corresponding resource type.
An enumerator that indicates the power state for screen resource.
enum PowerScreenState { "SCREEN_OFF", "SCREEN_DIM", "SCREEN_NORMAL", "SCREEN_BRIGHT" };
The supported values are:
DIM state refers to the screen that the backlight is turned off NORMAL state refers to the default screen brightness that a user has configured for the device. BRIGHT(Deprecated) state refers to the maximum screen brightness that the device provides. Note that the change in brightness does not affect the system brightness setting, i.e., the system brightness value is automatically restored when the resource is released or the process is completed.
An enumerator that indicates the power state for cpu resource.
enum PowerCpuState { "CPU_AWAKE" };
The supported values are:
The supported power states in general. It can be either a PowerScreenState or a PowerCpuState.
typedef (PowerScreenState or PowerCpuState) PowerState;
This interface defines what is instantiated by the webapis object.
[NoInterfaceObject] interface PowerManagerObject { readonly attribute PowerManager power; };
WebAPIs implements PowerManagerObject;
There will be a webapis.powerobject that allows accessing of a functionality of the Power API.
This interface is used to request resource states, however, these requests can be overridden by the system. If the requests are overridden, the application is notified with the provided listener callback.
[NoInterfaceObject] interface PowerManager { void request(PowerResource resource, PowerState state) raises(WebAPIException); void release(PowerResource resource) raises(WebAPIException); void setScreenStateChangeListener(ScreenStateChangeCallback listener) raises(WebAPIException); void unsetScreenStateChangeListener() raises(WebAPIException); double getScreenBrightness() raises(WebAPIException); void setScreenBrightness(double brightness) raises(WebAPIException); boolean isScreenOn() raises(WebAPIException); void restoreScreenBrightness() raises(WebAPIException); void turnScreenOn() raises(WebAPIException); void turnScreenOff() raises(WebAPIException); };
request
Requests the minimum-state for a power resource.
void request(PowerResource resource, PowerState state);
with error type UnknownError in any other error case.
with error type SecurityError, if this functionality is not allowed.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type NotSupportedError, if this feature is not supported.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
webapis.power.request("SCREEN", "SCREEN_NORMAL");
release
Releases the power state request for the given resource.
void release(PowerResource resource);
with error type UnknownError in any other error case.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type SecurityError, if this functionality is not allowed.
with error type NotSupportedError, if this feature is not supported.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Release SCREEN resource. webapis.power.release("SCREEN");
setScreenStateChangeListener
Sets the screen state change callback and monitors its state changes.
void setScreenStateChangeListener(ScreenStateChangeCallback listener);
with error type UnknownError in any other error case.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type SecurityError, if this functionality is not allowed.
with error type NotSupportedError, if this feature is not supported.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
function onScreenStateChanged(previousState, changedState) { console.log("Screen state changed from " + previousState + " to " + changedState); } // Set the screen state change listener. webapis.power.setScreenStateChangeListener(onScreenStateChanged);
unsetScreenStateChangeListener
Unsets the screen state change callback and stop monitoring it.
void unsetScreenStateChangeListener();
with error type UnknownError in any other error case.
with error type NotSupportedError, if this feature is not supported.
with error type SecurityError, if this functionality is not allowed.
// Unset the screen state change listener. webapis.power.unsetScreenStateChangeListener();
getScreenBrightness
Gets the screen brightness level of an application, from 0 to 1.
double getScreenBrightness();
with error type UnknownError in any other error case.
with error type NotSupportedError, if this feature is not supported.
with error type SecurityError, if this functionality is not allowed.
// Get the current screen brightness value. var screenBrightness = webapis.power.getScreenBrightness();
setScreenBrightness
Sets the screen brightness level for an application, from 0 to 1.
void setScreenBrightness(double brightness);
with error type UnknownError in any other error case.
with error type SecurityError, if this functionality is not allowed.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type NotSupportedError, if this feature is not supported.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Set the screen brightness value for the application. webapis.power.setScreenBrightness(1);
isScreenOn
Returns true if the screen is on.
boolean isScreenOn();
with error type UnknownError in any other error case.
with error type NotSupportedError, if this feature is not supported.
with error type SecurityError, if this functionality is not allowed.
// Check whether the screen is on or off. var isScreenOn = webapis.power.isScreenOn();
restoreScreenBrightness
Restores the screen brightness to the system default setting value.
void restoreScreenBrightness();
with error type UnknownError in any other error case.
with error type NotSupportedError, if this feature is not supported.
with error type SecurityError, if this functionality is not allowed.
// Restore the screen brightness value to the system default setting value. webapis.power.restoreScreenBrightness();
turnScreenOn
Turns on the screen.
void turnScreenOn();
with error type UnknownError in any other error case.
with error type SecurityError, if this functionality is not allowed.
with error type NotSupportedError, if this feature is not supported.
// Turn on the screen. webapis.power.turnScreenOn();
turnScreenOff
Turns off the screen.
void turnScreenOff();
with error type UnknownError in any other error case.
with error type SecurityError, if this functionality is not allowed.
with error type NotSupportedError, if this feature is not supported.
// Turn off the screen. webapis.power.turnScreenOff();
This callback interface defines notification for the screen state changes.
[Callback=FunctionOnly, NoInterfaceObject] interface ScreenStateChangeCallback { void onchanged(PowerScreenState previousState, PowerScreenState changedState); };
onchanged
Called on screen state change.
void onchanged(PowerScreenState previousState, PowerScreenState changedState);
module Power { enum PowerResource { "SCREEN", "CPU" }; enum PowerScreenState { "SCREEN_OFF", "SCREEN_DIM", "SCREEN_NORMAL", "SCREEN_BRIGHT" }; enum PowerCpuState { "CPU_AWAKE" }; typedef (PowerScreenState or PowerCpuState) PowerState; [NoInterfaceObject] interface PowerManagerObject { readonly attribute PowerManager power; }; WebAPIs implements PowerManagerObject; [NoInterfaceObject] interface PowerManager { void request(PowerResource resource, PowerState state) raises(WebAPIException); void release(PowerResource resource) raises(WebAPIException); void setScreenStateChangeListener(ScreenStateChangeCallback listener) raises(WebAPIException); void unsetScreenStateChangeListener() raises(WebAPIException); double getScreenBrightness() raises(WebAPIException); void setScreenBrightness(double brightness) raises(WebAPIException); boolean isScreenOn() raises(WebAPIException); void restoreScreenBrightness() raises(WebAPIException); void turnScreenOn() raises(WebAPIException); void turnScreenOff() raises(WebAPIException); }; [Callback=FunctionOnly, NoInterfaceObject] interface ScreenStateChangeCallback { void onchanged(PowerScreenState previousState, PowerScreenState changedState); }; };