Need help with some code - Android Software Development

Hey gust I need some help with converting this code. I've tried a few things but still no luck.
I do have programming experience just not with this.
.method public onPress()V
.registers 3
const-string v0, "Reboot"
invoke-static {v0}, Landroid/os/Power;->reboot(Ljava/lang/StringV
return-void
.end method
I know this reboots the phone. What I'm trying to do is have it reboot to recovery.
I've tried changing v0 to recovery no luck. If you can help I would be very thankful. And if you could help explain what going on that would be awesome. I get the general idea of whats happening I'm just not familiar with it.

What language is that? Try "reboot recovery". That's what adb takes as an argument.

I have tried that. Reboot recovery also works on any of the terminal emulators. I'm pritty sure it is Java. I'm not really familiar with it.

Code:
try {
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
{
os.writeBytes("reboot recovery\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
Something like that?

I have tried that. Reboot recovery also works on any of the terminal emulators. I'm pritty sure it is Java. I'm not really familiar with it.

It is a decompiled Android code.. somebody did reverse engineering on a reboot Android-java app

Related

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
adb logcat says nothing about.
What's wrong?
I'm running it directly on HTC Hero rooted of course
I've had this issue on several ROMs. I guess some just don't support the command.. *shrug*
It should work...
The reboot binary is present
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.
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
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?
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();
}
Meltus said:
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();
}
Click to expand...
Click to collapse
This requires a rooted phone. How does adbd reboot on a non rooted phone?
Meltus said:
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();
}
Click to expand...
Click to collapse
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.
Meltus said:
Try this, i can confirm it works fine
Code:
process.waitFor();
Click to expand...
Click to collapse
asdfasdf

[Q] Reboot, Su, App

Hi, i am trying to run adb and su commands in onclicklistener of my button of android app and here is my code
Code:
btnCheckSu.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Process p; String[] st = new String[3];
try {
st[0]="/system/bin/su";
st[1]="-c";
st[2]="reboot";
p = Runtime.getRuntime().exec(st);
Toast.makeText(SUCheck.this, "Rebooting...", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
I do get the prompt for su but then phone does not reboot...any help please
thanks
Well im not sure about the su commands but the reboot intent is restricted to processes signed with the same key as the platform you are using (essentially the key used to sign the rom you are using)
It could be the same with using su to reboot. Not sure though
--------
I tried it on the terminal emulator and it worked after entering the command twice for some reason
From something awesome
Try your commands via adb root shell first. If they work then u know the condemns are good and can try something else. All so without capturing process output there it's no way to know what's going on.
Sent from my MB860 using Tapatalk
Why not use the standard android api?
Code:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
pm.reboot("");
You'll need the REBOOT permission though.
HomerSp said:
Why not use the standard android api?
Code:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
pm.reboot("");
You'll need the REBOOT permission though.
Click to expand...
Click to collapse
Because as i said before the reboot permission is only valid on system apps signed with the platform key
From something awesome
killersnowman said:
Because as i said before the reboot permission is only valid on system apps signed with the platform key
From something awesome
Click to expand...
Click to collapse
You're right, sorry.
Try this instead, it worked fine for me.
Code:
Runtime.getRuntime().exec("su -c /system/bin/reboot");
i guys
thanks for the above replies...
but none of the above suggestion has worked for me...any other clues please
thanks
.../me repeats himself...
CAPTURE UR OUTPUT, without it we cant know what is going wrong.
Try your commands via adb shell first, if they work there they will also work via your phone.
yup, great.... adb working through my pc shell
capturing output...i have to work that out how...cheers
hisheeraz said:
yup, great.... adb working through my pc shell
capturing output...i have to work that out how...cheers
Click to expand...
Click to collapse
from your process create datastreams for your process.getInputStream() and process.getErrorStream(). After execution dump streams to file/logcat/w/e.
hisheeraz said:
yup, great.... adb working through my pc shell
capturing output...i have to work that out how...cheers
Click to expand...
Click to collapse
Try this:
Code:
btnCheckSu.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Process p; String[] st = new String[3];
try {
st[0]="/system/bin/su";
st[1]="-c";
st[2]="reboot";
p = Runtime.getRuntime().exec(st);
[COLOR="Red"] String s;
DataInputStream is=new DataInputStream(p.getInputStream());
DataInputStream er=new DataInputStream(p.getErrorStream());
Log.i("MyApp","stdout:\n");
while((s=is.readLine())!=null){
Log.i("MyApp",s+"\n");
}
Log.i("MyApp","stderr:\n");
while((s=er.readLine())!=null){
Log.i("MyApp",s+"\n");
}
[/COLOR]
Toast.makeText(SUCheck.this, "Rebooting...", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
sorry for being such a pain but my Log.i is empty there is absolutely nothing there
even after reinstalling the app in my phone nothing is in Log.i
help please...
EDIT:1
HERE IS THE LOG.I
sdtout:
stderr:
not permitted!
also i am using REBOOT permission in my manifest...i donot think i need it but just in case
hisheeraz said:
sorry for being such a pain but my Log.i is empty there is absolutely nothing there
even after reinstalling the app in my phone nothing is in Log.i
help please...
EDIT:1
HERE IS THE LOG.I
sdtout:
stderr:
not permitted!
Click to expand...
Click to collapse
bla,
try without -c. then also try...
reboot
reboot -f
busybox reboot
busybox reboot -f
hey thanks
/system/bin/su
-c
busybox reboot -f
is working...but
busybox reboot recovery -f
of
busybox reboot recovery
is not working. thanks for your effort and help,
i will dig into this tomorrow and will post you my feed back, it is really late here in AU :O
regards

{Q}Restart a system process

Hi
I'm developing a new app that make changes into SystemUi.apk and i don't want restart me device to see changes and I want just restart SystemUi.apk...
is there any way???
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plz take look at this...
http://forum.xda-developers.com/showthread.php?t=2434597
poria1999 said:
Hi
I'm developing a new app that make changes into SystemUi.apk and i don't want restart me device to see changes and I want just restart SystemUi.apk...
is there any way???
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plz take look at this...
http://forum.xda-developers.com/showthread.php?t=2434597
Click to expand...
Click to collapse
You can restart the service using adb's ActivityManager (am) using the following command
Code:
am startservice -n com.android.systemui/.SystemUIService
To execute the same command from your app, make use of Runtime.
Code:
final Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su -c am startservice -n com.android.systemui/.SystemUIService");
}
catch (IOException e) {
e.printStackTrace();
}
vijai2011 said:
You can restart the service using adb's ActivityManager (am) using the following command
Code:
am startservice -n com.android.systemui/.SystemUIService
To execute the same command from your app, make use of Runtime.
Code:
final Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su -c am startservice -n com.android.systemui/.SystemUIService");
}
catch (IOException e) {
e.printStackTrace();
}
Click to expand...
Click to collapse
tnx
I have one question more...
can u give me a example code to mount system and write sth on?
Edit:How i can start it again?
poria1999 said:
tnx
I have one question more...
can u give me a example code to mount system and write sth on?
Click to expand...
Click to collapse
Try below code. Cant test it ATM
Code:
runtime.exec("su -c mount -o remount,rw /system");
File myfile = new File(Environment.getExternalStorageDirectory() + File.separator + "test.txt");
myfile.createNewFile();
String data ="My test data";
//write the data in file
if(myfile.exists())
{
try {
OutputStream os = new FileOutputStream(myfile);
os.write(data);
os.close();
Toast.makeText(this, "File created successfully", Toast.LENGTH_SHORT).show();
}catch (IOException e)
{e.printStackTrace();}
runtime.exec("su -c" + Environment.getExternalStorageDirectory() + File.separator + "test.txt" + "/system/");
}
//deleting the temp file
file.delete();
Toast.makeText(this, "File copied and deleted from temp dir", Toast.LENGTH_SHORT).show();
To start it again, put that in a function and call that function whenever you want to execute it.
Example of function:
Code:
public void myfunc(){
//Your code to be executed more than once
}
And in some other function, say onCreate(), call
Code:
myfunc();
vijai2011 said:
You can restart the service using adb's ActivityManager (am) using the following command
Code:
am startservice -n com.android.systemui/.SystemUIService
To execute the same command from your app, make use of Runtime.
Code:
final Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su -c am startservice -n com.android.systemui/.SystemUIService");
}
catch (IOException e) {
e.printStackTrace();
}
Click to expand...
Click to collapse
this code doesn't work for me bro...
Edit:
vijai2011 said:
Try below code. Cant test it ATM
Code:
runtime.exec("su -c mount -o remount,rw /system");
File myfile = new File(Environment.getExternalStorageDirectory() + File.separator + "test.txt");
myfile.createNewFile();
String data ="My test data";
//write the data in file
if(myfile.exists())
{
try {
OutputStream os = new FileOutputStream(myfile);
os.write(data);
os.close();
Toast.makeText(this, "File created successfully", Toast.LENGTH_SHORT).show();
}catch (IOException e)
{e.printStackTrace();}
runtime.exec("su -c" + Environment.getExternalStorageDirectory() + File.separator + "test.txt" + "/system/");
}
//deleting the temp file
file.delete();
Toast.makeText(this, "File copied and deleted from temp dir", Toast.LENGTH_SHORT).show();
To start it again, put that in a function and call that function whenever you want to execute it.
Example of function:
Code:
public void myfunc(){
//Your code to be executed more than once
}
And in some other function, say onCreate(), call
Code:
myfunc();
Click to expand...
Click to collapse
if i want replace sth from into an apk to system dir what i suppose to do?
poria1999 said:
this code doesn't work for me bro...
Edit:
if i want replace sth from into an apk to system dir what i suppose to do?
Click to expand...
Click to collapse
That's gonna be different. You have to put the file in asserts and extract the file to system more or less the same why like creating the file and copying it to system.
And for systemUI restart, you can try this:
Code:
Process p;
p = Runtime.getRuntime().exec("sh");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("am startservice -n com.android.systemui/.SystemUIService\n");
Its pretty much the same but with a little different approach.
vijai2011 said:
That's gonna be different. You have to put the file in asserts and extract the file to system more or less the same why like creating the file and copying it to system.
And for systemUI restart, you can try this:
Code:
Process p;
p = Runtime.getRuntime().exec("sh");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("am startservice -n com.android.systemui/.SystemUIService\n");
Its pretty much the same but with a little different approach.
Click to expand...
Click to collapse
Bro codes don't work for me!!!
I tried all of codes that u gave me but they just make an app than ask me for root permission and don't do any thing...
Sent from my LT18i using Tapatalk 2
poria1999 said:
Bro codes don't work for me!!!
I tried all of codes that u gave me but they just make an app than ask me for root permission and don't do any thing...
Sent from my LT18i using Tapatalk 2
Click to expand...
Click to collapse
Let me try a working code today. Sorry for posting non working codes as I can not home yestersay to test 'em. BTW, you can also look for it in opensource xposed framework modules because many xposed modules needs to do a restart of systemui.
Sent from my GT-N7000 using xda app-developers app
Ok...a friend of mine who has more experience than me said, the code is correct but is not working with recent builds. Searching doesnt give me any convincing results. So thought to provide you code to hot reboot. This code is tested and works well.
Code:
try {
Process proc = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "setprop ctl.restart zygote"});
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
This will cause the zygote to restart which will in turn makes the whole system core reboot. Works well on my Galaxy note running 4.1.2. This the easiest method I can think although I could restart systemui by killing SystemUI process by "kill pid" But it would be lots of work to find systemui pid because it is not static
vijai2011 said:
Let me try a working code today. Sorry for posting non working codes as I can not home yestersay to test 'em. BTW, you can also look for it in opensource xposed framework modules because many xposed modules needs to do a restart of systemui.
Sent from my GT-N7000 using xda app-developers app
Click to expand...
Click to collapse
Tnx bro,that is no problem...
Do u know how to use xposed framework?
Sent from my LT18i using Tapatalk 2
vijai2011 said:
Ok...a friend of mine who has more experience than me said, the code is correct but is not working with recent builds. Searching doesnt give me any convincing results. So thought to provide you code to hot reboot. This code is tested and works well.
Code:
try {
Process proc = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "setprop ctl.restart zygote"});
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
This will cause the zygote to restart which will in turn makes the whole system core reboot. Works well on my Galaxy note running 4.1.2. This the easiest method I can think although I could restart systemui by killing SystemUI process by "kill pid" But it would be lots of work to find systemui pid because it is not static
Click to expand...
Click to collapse
But I don't want reboot whole device
Where I can find system ui pid and how I use from?
Tnx
Sent from my LT18i using Tapatalk 2
poria1999 said:
Tnx bro,that is no problem...
Do u know how to use xposed framework?
Sent from my LT18i using Tapatalk 2
Click to expand...
Click to collapse
You need to use xposed framework for?
poria1999 said:
But I don't want reboot whole device
Where I can find system ui pid and how I use from?
Tnx
Sent from my LT18i using Tapatalk 2
Click to expand...
Click to collapse
That's not a whole system reboot. It only restarts core system services. So its already fast than normal reboot.
Anyway, NVM, found a better working method which is working on my Galaxy Note N7000 running 4.1.2
Code:
try {
Process proc = Runtime.getRuntime()
.exec("su -c pkill com.android.systemui ");
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
vijai2011 said:
You need to use xposed framework for?
That's not a whole system reboot. It only restarts core system services. So its already fast than normal reboot.
Anyway, NVM, found a better working method which is working on my Galaxy Note N7000 running 4.1.2
Code:
try {
Process proc = Runtime.getRuntime()
.exec("su -c pkill com.android.systemui ");
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
Click to expand...
Click to collapse
woks great!!!
so now how I can start it(SystemUI) again?
and one question more...
how i can change wallpaper?
EDIT:How i can check a process is running or not?
poria1999 said:
woks great!!!
so now how I can start it(SystemUI) again?
and one question more...
how i can change wallpaper?
EDIT:How i can check a process is running or not?
Click to expand...
Click to collapse
That would automatically restart the SystemUI. for wallpaper try this. Will help u a lot.

java.nio.bufferoverflowexception sending APK to tablet with Java

I am trying to install an APK using a simple Java application, the file is local to my (Linux) pc and the tablet is connected via USB.
If I run this command with adb then the apk installs fine:
adb install -r /home/apk.apk
So I know the apk file is valid and works fine.
The Java application is giving me java.nio.bufferoverflowexeception errors, the apk is fairly large at 700Mb but it pushes and installs fine from the terminal.
The code I am using is:
Code:
public void wiredsyncapk(){
abdsourcesync = apkpath;
progress.setString("Sync in progress");
System.out.println("Starting Sync via adb with command " + "adb" + " install -r "+ apkpath);
Process process = Runtime.getRuntime().exec("adb" + " install -r "+ apkpath);
InputStreamReader reader = new InputStreamReader(process.getInputStream());
Scanner scanner = new Scanner(reader);
scanner.close();
int exitCode = process.waitFor();
System.out.println("Process returned: " + exitCode);
if (exitCode==1){
System.out.println("an error has occured!");
}else{
System.out.println("it all worked fine");
}
} catch(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
How can I fix the bufferoverflow issue? I have searched and searched but not found a simple way to set a large buffer.
Thanks for the help;
Andy
where is it overflowing at? a logcat should tell this info.
zalez said:
where is it overflowing at? a logcat should tell this info.
Click to expand...
Click to collapse
Yep, logcat, please.

Android mediarecorder error

Hi!
I have been developing android app which records sounds from the phones mic. Error happens when trying to excecute this method:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void startRecording(View view) {
System.out.println("Start recording");
final Button aloita = (Button) findViewById(R.id.button3);
final Button lopeta = (Button) findViewById(R.id.button2);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(tiedostonimi);
try {
recorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() kusi");
}
System.out.println(LOG_TAG);
recorder.start();
aloita.setEnabled(false);
lopeta.setEnabled(true);
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Error: Unfortunately myapp has stopped
LogCat: Could not excecute method of the activity and then some onClick errors
If I comment all the recorder.* from this method the app works fine. (I use also System.out.println as a debug tool)
I need help!
Update:
I changed the outputfiles variable and now I've got error: start called in an invalid state: 4.

Categories

Resources