New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
mopodo
Old
#1  
Senior Member - OP
Thanks Meter 50
Posts: 131
Join Date: Aug 2009
Default execute reboot command from application

Hi

I'm trying to get a reboot application working.

It should get root through "su" and then execute "reboot".
It does, but nothing happens (su request shows up)

I used several ways to execute the commands.
The ShellInterface classs from MarketEnabler and this snippet http://www.anddev.org/root_access_snippet-t8384.html
"su" then "reboot" -> nothing
"su -c reboot" -> nothing...

Always the same, it looks like it worked but the device is still up :P
adb logcat says nothing about.

What's wrong?

I'm running it directly on HTC Hero rooted of course
AdrianK Old
#2  
Guest
Thanks Meter
Posts: n/a
I've had this issue on several ROMs. I guess some just don't support the command.. *shrug*
 
mopodo
Old
#3  
Senior Member - OP
Thanks Meter 50
Posts: 131
Join Date: Aug 2009
It should work...

The reboot binary is present :P
 
IConrad01
Old
#4  
Senior Member
Thanks Meter 0
Posts: 215
Join Date: Mar 2009
Hello out there. Looks like you just have a tiny error with your code.

"su -c reboot" needs to look like so: "su -c 'reboot'" -- the actual command to be executed has to be in quotes.
|T-Mobile G2 (HTC Vision)|
 
mopodo
Old
#5  
Senior Member - OP
Thanks Meter 50
Posts: 131
Join Date: Aug 2009
That sould work without the quotes

Still can't find the problem.

I chowned and chmodded the reboot binary like the su binary still no change
 
letolkki
Old
#6  
Junior Member
Thanks Meter 2
Posts: 23
Join Date: Dec 2010
Default how does adbd do it without root permission?

the adb daemon on the device has to be able to do it to be able to respond to 'adb reboot' on a non-rooted phone. Anybody know how it is able to perform the reboot?
 
Meltus
Old
#7  
Meltus's Avatar
Senior Member
Thanks Meter 888
Posts: 1,909
Join Date: Jan 2009
Location: Manchester

 
DONATE TO ME
Try this, i can confirm it works fine

Code:
try {
            Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new  DataOutputStream(process.getOutputStream());
         {
           os.writeBytes("reboot\n");
           os.flush();
        process.waitFor();
        }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
 
letolkki
Old
#8  
Junior Member
Thanks Meter 2
Posts: 23
Join Date: Dec 2010
Quote:
Originally Posted by Meltus View Post
Try this, i can confirm it works fine

Code:
try {
            Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new  DataOutputStream(process.getOutputStream());
         {
           os.writeBytes("reboot\n");
           os.flush();
        process.waitFor();
        }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
This requires a rooted phone. How does adbd reboot on a non rooted phone?
 
martino2k6
Old
#9  
Senior Member
Thanks Meter 208
Posts: 694
Join Date: Jul 2009
Location: London
Quote:
Originally Posted by Meltus View Post
Try this, i can confirm it works fine

Code:
try {
            Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new  DataOutputStream(process.getOutputStream());
         {
           os.writeBytes("reboot\n");
           os.flush();
        process.waitFor();
        }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
It works on some, doesn't work on others. Seems to be something with how the phone is rooted, or how permissions are set, not exactly sure. Either way, just because it works for you doesn't mean it will work for everyone, however the code up there is probably a very good example for an implementation.

Some apps like ROM Manager have their reboot written using the NDK, so that may be a reason why they can reboot whereas other apps which try to reboot fail.
Samsung Galaxy i7500 (CM7) -> HTC Desire (CM7) -> Samsung Galaxy S (CM9) -> Samsung Galaxy S3 (CM10.1) -> Sony Xperia ZL (stock/rooted)
Asus Transformer TF101 (CM9) -> Galaxy Tab 7.7 WiFi (stock/rooted) -> Galaxy Tab 7.7 3G (PA) + Toshiba AT201 (stock)
Font Changer - change your default system font (now works on MIUI too)
Clipboard Contents - extend your clipboard's functionality
VM Heap Tool - change the size of the heap for your device
 
Fr4gg0r
Old
#10  
Fr4gg0r's Avatar
Recognized Developer
Thanks Meter 662
Posts: 643
Join Date: Aug 2010

 
DONATE TO ME
Quote:
Originally Posted by Meltus View Post
Try this, i can confirm it works fine

Code:
        process.waitFor();
asdfasdf

Tags
reboot, root, sdk

XDA PORTAL POSTS

Forum Added for the Samsung Galaxy Mega

What do you do when the Galaxy Note line is simply not big enough? You get theSamsung Galaxy Mega. … more

Voice Control Your Phone with Tasker and AutoVoice – XDA Developer TV

XDA Developer TV Producer Kevin set up his phone to respond to … more

Guide to Take Better Control of Your Volume Levels

Would you like to know one of the things that really annoys me on a daily basis? Tough, … more

Get the Android 4.2.2 Status Bar on Your Gingerbread-Based Samsung

There are still quite a few of folks who run Gingerbread on their … more