Com.webos.service.power

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 ?

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.

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.

1 Like

@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 ?

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

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.

Hi, I would like to know how you create the JS service running as root priviledge.

Check Below Solution..

a temporary solution, but got it to work in a pinch:

/usr/bin/sudo /bin/bash -lc 'bundle exec rails server -e demo -p 80'


Can run with a user who has sudo privileges in a systemd unit file like so:

[Unit]
Description=Rails Webserver
After=syslog.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/var/www/webserver
ExecStart=/usr/bin/sudo /bin/bash -lc 'bundle exec rails server -e demo -p 80'
Restart=always
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target


Showbox

Speaking of which doesn't webOS have any capability similar to what Android has with their Device Administration feature?
I was working on writing a webOS agent for an EMM product some time back and this struck me as odd considering how valuable it would be for use cases such as TVs in hotels.