Note
- Empty curly braces (
'{}'
) after the method URI indicate that no parameters are passed to the method.
LS2 API is a JSON-based API provided by webOS platform services. You can use LS2 API to create apps or services that use webOS platform features.
This page explains the basic concepts of LS2 API using the example of com.webos.service.systemservice, which provides access to system settings such as preferences and time/time zone information.
The following outlines the key terms and concepts that you will come across while using LS2 API.
A service URI is a unique address that makes each platform service accessible via Luna Bus. A service URI follows the format of luna://<service name>
.
Therefore, the clients (other apps or services) can make a request to com.webos.service.systemservice
using the address luna://com.webos.service.systemservice
.
Each service provides one or more methods that are categorized by the feature they provide. Methods common to the service are grouped under the root category, whereas methods related to a specific feature are grouped under the relevant category.
com.webos.service.systemservice
provides the following methods to retrieve or set system preference values, which are grouped under the root category.
getPreferences
setPreferences
In addition, com.webos.service.systemservice
provides time-based methods, which are grouped under the time
category. For instance, you can retrieve or set the system time using the following methods:
time/getSystemTime
time/setSystemTime
Parameters are service request options and are passed as a JSON object. Parameters consist of a set of properties required for the service request as well as a few reserved properties that are common to all service requests.
One example of such reserved properties is the subscribe
property, which can be sent to services that allow subscriptions. If the subscription is successful, the service will return subscription responses either at periodic intervals or when its data is updated.
The following describes the parameters for time-based methods of com.webos.service.systemservice
.
time/getSystemTime
subscribe
property can be sent.time/setSystemTime
utc
(Coordinated Universal Time) as an input parameter.timestamp
object can be sent.A call response is a JSON object containing the service’s response data to a method call. It has a reserved property returnValue
to indicate the success or failure of a call.
returnValue
is true, the call is a success and the response object might have additional properties depending on the API call being made.subscribe
property in the parameters was set to true, the response object will return a property subscribed
to indicate the success or failure of the subscription. If subscribed
is true
, it indicates that the subscription was a success.returnValue
is false, it means the call failed and the response object might contain further properties such as errorCode
and errorText
that give more information about the error.A subscription response is a JSON object containing the service’s response data to a subscription. It has two reserved properties subscribed
and returnValue
, where subscribed
indicates the status of subscription and returnValue
indicates the status of operation.
This section explains the basics of how to use LS2 API.
Clients can make a request to a platform service using methods. In return to the request, the service provides a call response in JSON format.
The following shows an example of calling the time/getSystemTime
method, using the luna-send
command. The luna-send
command accepts the complete method URI as its argument, which follows the format of <service URI>/<method name>
. In case of the time/getSystemTime
method, the method URI becomes luna://com.webos.service.systemservice/time/getSystemTime
.
$ luna-send -n 1 -f luna://com.webos.service.systemservice/time/getSystemTime '{}'
Call response:
{
"timezone": "Asia/Seoul",
"returnValue": true,
"utc": 1557280839,
"localtime": {
"month": 5,
"day": 8,
"hour": 11,
"minute": 0,
"year": 2019,
"second": 39
},
"TZ": "KST",
"systemTimeSource": "ntp",
"timestamp": {
"source": "monotonic",
"sec": 730,
"nsec": 472935963
},
"timeZoneFile": "/var/luna/preferences/localtime",
"offset": 540,
"isDST": false
}
Clients can subscribe for notifications of some methods. In this case, the client makes a subscription request for the method and gets notified when any updates are available. This works well for operations where the information is likely to change and where the client needs the latest information.
The following shows an example of subscribing to the time/getSystemTime
method, using the luna-send
command. To test subscription with the luna-send
command, use -i
option for interactive mode.
$ luna-send -i -f luna://com.webos.service.systemservice/time/getSystemTime '{"subscribe": true}'
Call response:
{
"timezone": "Asia/Seoul",
"returnValue": true,
"utc": 1561617075,
"localtime": {
"month": 6,
"day": 27,
"hour": 15,
"minute": 31,
"year": 2019,
"second": 15
},
"subscribed": true,
"TZ": "KST",
"systemTimeSource": "ntp",
...
}
By setting the subscribe
parameter to true
, the client subscribes to the time/getSystemTime
method in order to get notifications in the following situations:
If you make one of the above changes in the Settings app, subscription responses will be received as follows:
System time changed |
---|
|
Time zone changed |
---|
|
Contents