Forum

Com.webos.service.power


#1

I want to reboot the device from the application, tried LS2 API Service

com.webos.service.power

Below in the Code Snippet

<script type="text/javascript">
			
   //sample code for calling LS2 API
   var lunaReq= webOS.service.request("luna://com.webos.service.power/shutdown/machineOff",{ 
        parameters:{
        "reason":"power off"
},
        onSuccess: function (args) {
			console.log("SUCCESS");
        },
        onFailure: function (args) {
			console.log(JSON.stringify(args));
        }
    });
</script>

The above code fails with following error

{"returnValue":false,"errorCode":-1,"errorText":"Denied method call \"machineOff\" for category \"/shutdown\""}

Now I want to know why this happens and if its a permission problem than what should I do ?


#2

I haven’t looked into it, but I would assume that’s just a protected method. You wouldn’t want any app to be able to power off or reboot your device, right? In the old days, your app would need to be in the com.palm.appdomain to get access to all the system APIs. That’s what some of us homebrew developers did to get around it. I don’t know if that’s still true for webOS OSE.


#3

Garredow is right there. If you look in https://github.com/webosose/luna-service2-security-conf/blob/761191b1ff6ce4465e62109f8c9a0d018108d435/files/sysbus/compat.api.json you’ll see that it’s in the private api, so that means only com.webos or com.palm apps would have access to this.

Previously you could “fool” it a bit by either giving your app an appid that starts with com.palm or com.webos. Alternatively you could try to pretend to be sending the command from another app.

Best would be to try with the luna-send command in ssh.

luna-send accepts -a and -h parameters if I recall correctly to put the caller. Some mor example of luna-send can be found on WebOS Internals site: http://www.webos-internals.org/wiki/Luna_Send

This is legacy webOS used on phones, but should work similarly.

See https://github.com/webOS-ports/org.webosports.messaging/blob/71ee04d6139997676a8d659d0ea42fbe8b37893f/service/javascript/assistants/PutMessage.js#L17 for an example on how to use -a.


#4

@Herrie

How can I access these private API’s do I need to build my application as Built-in-Web-Apps as suggested by http://webosose.org/develop/web-app-dev/built-in-web-app/build-test-web-app/ or is there any other way ?


#5

@Junil Could you let us know how to access private API?


#6

I had to create a dynamic JS service running as root that uses a shell command to luna-send to get around the private restriction. I guess you could recompile the whole image changing up the compat.api.json file that was mentioned before as well.