Power Management
To conserve power, webOS devices sleep after a period of inactivity - primarily, the absence of user interaction such as gestures, touches, or keyboard input.
The user can set a preference to trigger sleep after a minimum of 30 seconds or a maximum of 3 minutes. Some system services, such as audio or video playback, will sleep. If your app needs to keep the device awake, it can use the Power Management service's activityStart and activityEnd methods.
Use these methods if your application performs an extended operation, such as syncing or downloading a lot of data. You could also use this in background applications where you need more than the few seconds allotted during an alarm wakeup.
Methods
-
activityStart - Alert the Power Management service that your app is starting an activity.
-
activityEnd - Alert the Power Management service that your app is ending an activity.
activityStart
Alerts the Power Management service that your app is starting an activity that requires the device to stay awake.
URI is com.palm.power/com/palm/power/acitivityStart
Syntax
{
"id" : string,
"duration_ms" : number
}
Parameters
| Parameter | Required | Type | Description |
| id | Yes | string |
Format: [App ID].[activity name]-[count] Your application ID with an activity name and an occurrence count, i.e., "com.palm.app.news.update-1". This format allows you to distinguish between requests and manage multiple requests if needed. The only requirement is that the App ID string be unique. |
| duration_ms | Yes | number | Activity's expected duration provided in milliseconds; cannot exceed 900,000 milliseconds (15 minutes). The Power Management service automatically terminates your activity request at the end of its duration or 15 minutes, whichever is shorter. |
Returns
{
returnValue : boolean
}
| Attribute | Required | Type | Description |
| returnValue | Yes | boolean | true (success) or false (failure) |
Examples
Enyo
enyo.kind({
name : "enyo.powermng",
kind : enyo.VFlexBox,
components : [
{ flex : 1,
kind : "Pane",
components : [{
flex : 1,
kind : "Scroller",
components : [{
name : "startActivity",
kind : "PalmService",
service : "palm://com.palm.power/com/palm/power",
method : "activityStart",
onSuccess : "startActivitySuccess",
onFailure : "startActivityFailure",
subscribe : true
},
{kind : "Button", name : "startAcitivityButton", caption : "Start Activity", onclick : "startActivityClick"}
]
}]
}],
startActivityClick: function() {
this.$.startActivity.call({"id": "com.palmdts.enyo.powermng.example-1", "duration_ms":5000});
},
startActivitySuccess: function(inSender, inResponse) {
this.log("Start activity success, results=" + enyo.json.stringify(inResponse));
},
// Log errors to the console for debugging
startActivityFailure: function(inSender, inError, inRequest) {
this.log(enyo.json.stringify(inError));
}
});
Mojo
this.controller.serviceRequest("palm://com.palm.power/com/palm/power", {
method: "activityStart",
parameters: {
id: "com.palm.app.news.update-1",
duration_ms: 120000
},
onSuccess: this.activitySuccess.bind(this),
onFailure: this.activityFailure.bind(this)
});
activityEnd
Notifies the service when your activity completes, as every bit of power efficiency is important. Activities are not canceled when an application is closed, so you should use activityEnd in your cleanup method when there are any outstanding activity requests.
URI is com.palm.power/com/palm/power/acitivityEnd
Syntax
{
"id" : string
}
Parameters
| Parameter | Required | Type | Description |
| id | Yes | string |
ID provided to the activityStart method.
|
Returns
{
returnValue : boolean
}
| Attribute | Required | Type | Description |
| returnValue | Yes | boolean | true (success) or false (failure) |
Examples
Enyo
enyo.kind({
name : "enyo.powermng",
kind : enyo.VFlexBox,
components : [
{ flex : 1,
kind : "Pane",
components : [{
flex : 1,
kind : "Scroller",
components : [{
name : "endActivity",
kind : "PalmService",
service : "palm://com.palm.power/com/palm/power",
method : "activityEnd",
onSuccess : "endActivitySuccess",
onFailure : "endtActivityFailure",
subscribe : true
},
{kind : "Button", name : "endAcitivityButton", caption : "End Activity", onclick : "endActivityClick"}
]
}]
}],
endActivityClick: function() {
this.$.endActivity.call({"id": "com.palmdts.enyo.powermng.example-1"});
},
endActivitySuccess: function(inSender, inResponse) {
this.log("End activity success, results=" + enyo.json.stringify(inResponse));
},
// Log errors to the console for debugging
endActivityFailure: function(inSender, inError, inRequest) {
this.log(enyo.json.stringify(inError));
}
});
Mojo
this.controller.serviceRequest("palm://com.palm.power/com/palm/power", {
method: "activityEnd",
parameters: {
id: "com.palm.app.news.update-1"
},
onSuccess: this.activitySuccess.bind(this),
onFailure: this.activityFailure.bind(this)
});