How to replace a file from assets to System - Java for Android App Development

Hi again...
I want replace a file (depend on user choose) to system/framework and set permissions for that file...
but i don't know:
1-How to mount system as rw...
2-How to replace a file from assets to system(switch between 7 files depend on user choose)...
3-How to set permission of file to rw- r— r—?
plz just tell me the ways that work for u...
tnx

So have you decided to get everything from here without doing a little research? Simple google search gives me ample of example rom stackoverflow and documentation from developer.android.com

vijai2011 said:
So have you decided to get everything from here without doing a little research? Simple google search gives me ample of example rom stackoverflow and documentation from developer.android.com
Click to expand...
Click to collapse
I searched alot and i did alot of topics guides but they don't work fro me...
like:
http://stackoverflow.com/questions/14559068/android-how-to-set-rw-r-r-permissions-programmatically
http://stackoverflow.com/questions/11268717/write-files-to-system
http://stackoverflow.com/questions/...tem-in-rw-from-within-my-apk-rooted-of-course
and a lot of more that i cant remember....
usually i search for what i want and if i don't find any result for, i ask my question here...

Sorry to ask this, but have you learnt java basics first? Because I feel, you lack basis - Its not humiliation but this something you need on first hand to be a good developer.
1. I have already answered how to mount system as RW:
Code:
Runtime runtime = Runtime.getRuntime();
runtime.exec("su -c mount -o remount,rw /system");
2. The first link you gave has answer for setting permission in 1st answer.
3. To extract assert, refer this answer:
Hint: put up a dialog asking which file to extract and then adopt the above answer to extract it to sdcard first them copy it to system using runtime and cp command.

vijai2011 said:
Sorry to ask this, but have you learnt java basics first? Because I feel, you lack basis - Its not humiliation but this something you need on first hand to be a good developer.
1. I have already answered how to mount system as RW:
Code:
Runtime runtime = Runtime.getRuntime();
runtime.exec("su -c mount -o remount,rw /system");
2. The first link you gave has answer for setting permission in 1st answer.
3. To extract assert, refer this answer:
Hint: put up a dialog asking which file to extract and then adopt the above answer to extract it to sdcard first them copy it to system using runtime and cp command.
Click to expand...
Click to collapse
tnx my friend
yeah i know java about j2se as well!!
and i did about 5 swing projects...
i will try ur answer now thanks...

vijai2011 said:
Sorry to ask this, but have you learnt java basics first? Because I feel, you lack basis - Its not humiliation but this something you need on first hand to be a good developer.
1. I have already answered how to mount system as RW:
Code:
Runtime runtime = Runtime.getRuntime();
runtime.exec("su -c mount -o remount,rw /system");
2. The first link you gave has answer for setting permission in 1st answer.
3. To extract assert, refer this answer:
Hint: put up a dialog asking which file to extract and then adopt the above answer to extract it to sdcard first them copy it to system using runtime and cp command.
Click to expand...
Click to collapse
I tried this code but my device restart...
Code:
package com.android.justtest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import java.io.DataOutputStream;
public class MainActivity extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MainActivity mainActivity = new MainActivity();
mainActivity.mainActionAmber();
mainActivity.close();
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void close()
{
try {
Process proc = Runtime.getRuntime()
.exec("su -c pkill com.android.systemui ");
Thread.sleep(1000);
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void mainActionAmber()
{
try {
Runtime runtime = Runtime.getRuntime();
Process proc = Runtime.getRuntime()
.exec("su");
DataOutputStream os = new DataOutputStream(proc.getOutputStream());
runtime.exec("su -c mount -o remount,rw -t yaffs2 /dev/block/mtdblock4 /system");
os.writeBytes("find /sdcard/we/Amber -exec mv '{}' /system/framework +\n");
os.writeBytes("chmod 644 /system/framework" + "\n");
os.writeBytes("exit\n");
os.flush();
}catch (Exception e){e.printStackTrace();}
}}
where is the problem?

poria1999 said:
I tried this code but my device restart...
where is the problem?
Click to expand...
Click to collapse
This simply means the framework file you're trying to replace is crucial to the system, and thus the device will reboot if it is deleted.

Androguide.fr said:
This simply means the framework file you're trying to replace is crucial to the system, and thus the device will reboot if it is deleted.
Click to expand...
Click to collapse
I can replace that file manually without any damage!!!
i want to replace SemcGenericUxpRes.apk....

Do you have logcat error?
I use
try {
suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes("\n");
os.flush();
os.close();
suProcess.waitFor();
Sent from my GT-I9505G using Tapatalk 4

Related

[HowTo]Execute Root Commands and read output

You can learn here how to execute shell commands as root and read output and errors
What you will need:
Eclipse with ADT plugin
Basic knowledge of java
Rooted android device
Note
Root commands should always be executed in background thread, you can use AsyncTask for example
I won't explain here how to use AsyncTask, maybe in another tut.
Also note that I'm a relative beginner myself so I won't use professional terms I'll try to explain in my own words, so I'm sorry in advance if you have no idea what I'm talking about
1. First thing that we need to do is open a new root shell like this:
Code:
Process process = Runtime.getRuntime().exec("su");
Make sure to destroy this process after finished
2. Open input output and error streams to write commands and read output
Code:
OutputStream stdin = process.getOutputStream();
stdin is used to write commands to shell. This is OutputStream, which means that using this stream we can execute command(like writing command in terminal)
Code:
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
stderr and stdout are used to read output and error of a command which we executed.
3. Now we actually execute commands
Code:
stdin.write(("ls\n").getBytes());
//after you exec everything that you want exit shell
stdin.write("exit\n".getBytes());
"\n" at the end of the command means new line(like when you press enter in terminal). This is important, if you dont add new line it same like you didn't press enter
4. Flush and close OutputStream
Code:
stdin.flush(); //flush stream
stdin.close(); //close stream
5. Read output and error of a executed command
Code:
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while ((line = br.readLine()) != null) {
Log.d("[Output]", line);
}
br.close();
br =
new BufferedReader(new InputStreamReader(stderr));
while ((line = br.readLine()) != null) {
Log.e("[Error]", line);
}
br.close();
We read output and error (if any) line by line and write it to logcat
You can of course do anything with output(display in TextView for example)
6. Finally we destroy opened shell
Code:
process.waitFor();//wait for process to finish
process.destroy();
You need to handle InteruptedException and IOException.
Hope this helps someone. Again sorry for stupid explanations. I totally understand all this but English isn't my primary language so its a but hard to explain...
Here is whole code;
Code:
try {
String line;
Process process = Runtime.getRuntime().exec("su");
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
stdin.write(("ls\n").getBytes());
stdin.write("exit\n".getBytes());
stdin.flush();
stdin.close();
BufferedReader br =
new BufferedReader(new InputStreamReader(stdout));
while ((line = br.readLine()) != null) {
Log.d("[Output]", line);
}
br.close();
br =
new BufferedReader(new InputStreamReader(stderr));
while ((line = br.readLine()) != null) {
Log.e("[Error]", line);
}
br.close();
process.waitFor();
process.destroy();
} catch (Exception ex) {
}
Yea roottools is better solution, it handles opening shell for you, its easier, less code, and in my experience a little bit faster.
Here is an example:
Code:
Command command = new Command(0, "ls")
{
@Override
public void output(int id, String line)
{
// Handle output here
}
};
RootTools.getShell(true).add(command).waitForFinish();
And also do this when exiting application
Code:
RootTools.closeAllShells();
Sent from my Evo 3D GSM using Tapatalk 2
Everyone should read the How-To SU guide by Chainfire:
http://su.chainfire.eu/
Usable example code is on Github. In the meanwhile there's an interactive shell (like in RootTools) available too:
https://github.com/Chainfire/libsuperuser
I noticed that you called your InputStream stdout and your OutputStream stdin. Is there any reason that you chose to reverse the usual naming?
Great work but i would be delighted if op mentioned root commands and how to use them
octobclrnts said:
I noticed that you called your InputStream stdout and your OutputStream stdin. Is there any reason that you chose to reverse the usual naming?
Click to expand...
Click to collapse
Its confusing I know.
I'll try to explain
You use InputStream to read output of the shell so I called it stdout
Output of a shell/terminal is called stdout
You use OutputStream to write to shell(input to shell) so its stdin
Passing commands to terminal is stdin
It stands for standard output/input
More about stdin, stdout, stderr
http://en.m.wikipedia.org/wiki/Standard_streams
Sent from my Evo 3D GSM using Tapatalk 2
sak-venom1997 said:
Great work but i would be delighted if op mentioned root commands and how to use them
Click to expand...
Click to collapse
There is no such thing as root command.
commands can be executed as root user or as normal user.
Sent from my Evo 3D GSM using Tapatalk 2
pedja1 said:
There is no such thing as root command.
commands can be executed as root user or as normal user.
Sent from my Evo 3D GSM using Tapatalk 2
Click to expand...
Click to collapse
You didn't get me sir I ment the commands which run as root and how can developers utilize them
Sent from my GT-S5302 using Tapatalk 2
Hit Thanx Button if i helped you!
sak-venom1997 said:
You didn't get me sir I ment the commands which run as root and how can developers utilize them
Sent from my GT-S5302 using Tapatalk 2
Hit Thanx Button if i helped you!
Click to expand...
Click to collapse
I'm not really sure what you are asking. Any command can be executed as root.
Maybe you should read a bit about linux and shell
Sent from my Evo 3D GSM using Tapatalk 2
pedja1 said:
I'm not really sure what you are asking. Any command can be executed as root.
Maybe you should read a bit about linux and shell
Sent from my Evo 3D GSM using Tapatalk 2
Click to expand...
Click to collapse
No I was talking about the commands which require root to run like ifconfig
Sry for trouble I have no linux knowledge
Sent from my GT-S5302 using Tapatalk 2
Hit Thanx Button if i helped you!
sak-venom1997 said:
No I was talking about the commands which require root to run like ifconfig
Sry for trouble I have no linux knowledge
Sent from my GT-S5302 using Tapatalk 2
Hit Thanx Button if i helped you!
Click to expand...
Click to collapse
There are some commands that will just make sense as root. However, why should anyone write a tutorial about how to use some commands very few persons will need. Google "Linux command <what you want to do>" and you will find explanations. Many commands are just more flexible when executed like this.
I really recommend that. You will need it when you develop a root app. And you can use the adb shell! Great help.
@OP: What's about mentioning that you should use the busybox commands as the system's implementation of the shell commands differs from device to device and from ROM to ROM?
I also recommend RootTools. One of the best libraries in my opinion!
nikwen said:
.
@OP: What's about mentioning that you should use the busybox commands as the system's implementation of the shell commands differs from device to device and from ROM to ROM?
I also recommend RootTools. One of the best libraries in my opinion!
Click to expand...
Click to collapse
Purpose of this tutorial is to show how to execute commands as root, not how to use certain Linux commands.
And besides, using busybox is not always best solution, what if device doesn't have it installed, what if busybox doesn't have that command.
For example you would definitely not use "busybox echo" or "busybox ls".
Devs should already know how to use Linux, this is just to show how to do it from java.
Sent from my Evo 3D GSM using Tapatalk 2
pedja1 said:
Purpose of this tutorial is to show how to execute commands as root, not how to use certain Linux commands.
And besides, using busybox is not always best solution, what if device doesn't have it installed, what if busybox doesn't have that command.
For example you would definitely not use "busybox echo" or "busybox ls".
Click to expand...
Click to collapse
You are right. It is true that nobody would use busybox for very simple commands.
However, RootTools has the RootTools.offerBusyBox(Activity activity) Method which opens Google Play to download a busybox installer.
Devs should already know how to use Linux, this is just to show how to do it from java.
Sent from my Evo 3D GSM using Tapatalk 2
Click to expand...
Click to collapse
I understood what you wanted to do.
Great job, btw. Would have been glad if I had had this when I started with root apps.
Great Work!!!
I found how to execute root commands before. But this post has the best explanation. Thanks a lot!
pedja1 said:
Purpose of this tutorial is to show how to execute commands as root, not how to use certain Linux commands.
And besides, using busybox is not always best solution, what if device doesn't have it installed, what if busybox doesn't have that command.
For example you would definitely not use "busybox echo" or "busybox ls".
Devs should already know how to use Linux, this is just to show how to do it from java.
Sent from my Evo 3D GSM using Tapatalk 2
Click to expand...
Click to collapse
I once did run into troubles parsing the results of "ls" command. Usually 'ls' is just the short table-style list, while you could get all the details with 'ls -l'. This is what I needed. But when testing on the Motorola Milestone unfortunately 'ls' was sym-linked to 'ls -l', therefore calling 'ls -l' would result in an error message. Don't know if more devices act like that (didn't test on any other Motorola phones, and the Milestone is quite old by now), but maybe it still makes sense to use busybox for 'normal' command in some cases...
Hello,
I am trying to run a script kept in my assests folder of my app. It is Root.sh which contains -
Code:
su
cd system
mkdir abcdjdj
This is my java code:-
Code:
String path = "file:///android_asset/Root.sh";
Process p = new ProcessBuilder().command(path).start();
But now I get a runtime error -
Code:
04-22 15:08:03.144: E/AndroidRuntime(785): Caused by: java.io.IOException: Error running exec(). Command: [file:///android_asset/Root.sh] Working Directory: null Environment: [ANDROID_SOCKET_zygote=9, ANDROID_STORAGE=/storage, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar, ANDROID_DATA=/data, LD_LIBRARY_PATH=/vendor/lib:/system/lib, ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=8,32768]
Can anyone please help me?
Thanks.
abcdjdj said:
Hello,
I am trying to run a script kept in my assests folder of my app. It is Root.sh which contains -
Code:
su
cd system
mkdir abcdjdj
This is my java code:-
Code:
String path = "file:///android_asset/Root.sh";
Process p = new ProcessBuilder().command(path).start();
But now I get a runtime error -
Code:
04-22 15:08:03.144: E/AndroidRuntime(785): Caused by: java.io.IOException: Error running exec(). Command: [file:///android_asset/Root.sh] Working Directory: null Environment: [ANDROID_SOCKET_zygote=9, ANDROID_STORAGE=/storage, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar, ANDROID_DATA=/data, LD_LIBRARY_PATH=/vendor/lib:/system/lib, ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=8,32768]
Can anyone please help me?
Thanks.
Click to expand...
Click to collapse
Why don't you do it this way?
Code:
Runtime.getRuntime().exec("su", "-c", "cd system; mkdir abcdjdj");
Note that you need to pass the commands you want to execute to the command method, not the path.
nikwen said:
Why don't you do it this way?
Code:
Runtime.getRuntime().exec("su", "-c", "cd system; mkdir abcdjdj");
Note that you need to pass the commands you want to execute to the command method, not the path.
Click to expand...
Click to collapse
It gives a syntax error. I guess it should have been - Runtime.getRuntime().exec(new String[] { "su", "-c", "cd system; mkdir abcdjdj" });
It runs fine on my phone but I still don't see a folder called abcdjdj is /system
abcdjdj said:
It gives a syntax error. I guess it should have been - Runtime.getRuntime().exec(new String[] { "su", "-c", "cd system; mkdir abcdjdj" });
It runs fine on my phone but I still don't see a folder called abcdjdj is /system
Click to expand...
Click to collapse
You are right, it should have been that.
Try to add the full path:
Code:
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(new String[] {"su", "-c", "mkdir /system/abcdef"});
runtime.exec(new String[] {"su", "-c", "mkdir /system/aaab; mkdir /system/aaac"});
} catch (IOException e) {
e.printStackTrace();
}
I think that executing your first idea should work if you execute
Code:
runtime.exec("su");
and then write the commands to the outputstream as described in the first post of this thread.
---------- Post added at 06:13 PM ---------- Previous post was at 06:06 PM ----------
However, I recommend using roottools.
If you need to execute commands rarely it will be fine that way, but if you need to execute commands often, there will be annoying Toast messages every time. Using roottools, there will be such a message just once when the app requests SU rigths for the first time after the launch.
Ichigo said:
Yes, root tools is a great alternative. I use it a lot in my app. If you want, check my github for examples.
Click to expand...
Click to collapse
For a very basic tutorial, check this: http://code.google.com/p/roottools/wiki/Usage

Terminal command for reboot in recovery

Hi,
what is the command to reboot in recovery bootloader ecc?
I will insert in my app through this library
rampo said:
Hi,
what is the command to reboot in recovery bootloader ecc?
I will insert in my app through this library
Click to expand...
Click to collapse
The command for rebooting is
Code:
reboot
Use that to reboot into recovery:
Code:
reboot recovery
For bootloader you need to use adb:
Code:
adb reboot-bootloader
Runtime.getRuntime().exec(new String[]{"su","-c","reboot bootloader"});
Sent from my HTC One using xda premium
Not permitted
Not permitted!
Click to expand...
Click to collapse
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
pinpong said:
Runtime.getRuntime().exec(new String[]{"su","-c","reboot bootloader"});
Sent from my HTC One using xda premium
Click to expand...
Click to collapse
He wants to use RootTools.
For that use:
Code:
Command command = new Command(0, "reboot bootloader") {
[user=439709]@override[/user]
public void output(int id, String line) {
//TODO: Do something with the output here
}
};
RootTools.getShell(true).add(command).waitForFinish();
EDIT: @override: The first letter needs to be upper case (Doesn't let me as it thinks of it as a mentioning function.)
---------- Post added at 10:02 PM ---------- Previous post was at 10:00 PM ----------
rampo said:
Click to expand...
Click to collapse
First you need to be a root user.
Type "su" as the first command.
If you use RootTools you can execute commands as root without having to type "su" the way I gave you above.
Second adb commands must be launched from your computer.
nikwen said:
He wants to use RootTools.
For that use:
Code:
Command command = new Command(0, "reboot bootloader") {
[user=439709]@override[/user]
public void output(int id, String line) {
//TODO: Do something with the output here
}
};
RootTools.getShell(true).add(command).waitForFinish();
Click to expand...
Click to collapse
Same logcat : "Not permited!"
First you need to be a root user.
Click to expand...
Click to collapse
Don't warry man
Type "su" as the first command.
Click to expand...
Click to collapse
Already done.
If you use RootTools you can execute commands as root without having to type "su" the way I gave you above.
Click to expand...
Click to collapse
Ok, thanks.
Second adb commands must be launched from your computer.
Click to expand...
Click to collapse
Yes, i know, but i've tried
pinpong said:
Runtime.getRuntime().exec(new String[]{"su","-c","reboot bootloader"});
Sent from my HTC One using xda premium
Click to expand...
Click to collapse
Same "Not permited!"
rampo said:
Same logcat : "Not permited!"
Don't warry man
Already done.
Click to expand...
Click to collapse
In the screenshot you did not.
Ok, thanks.
Yes, i know, but i've tried
Click to expand...
Click to collapse
If I type "su", then press enter and then "reboot recovery", everything works fine.
Look at this for rebooting into bootloader: http://www.androidcentral.com/android-201-10-basic-terminal-commands-you-should-know
EDIT: You can see whether you typed "su" by looking at the last character of one line. If it is a # instead of a $, you typed "su".
EDIT: You can see whether you typed "su" by looking at the last character of one line. If it is a # instead of a $, you typed "su".
Click to expand...
Click to collapse
There is a "#"
If I type "su", then press enter and then "reboot recovery", everything works fine.
Click to expand...
Click to collapse
.
Not for me, i said this in my second post
HTC One, stock rooted ROM
rampo said:
There is a "#"
.
Not for me, i said this in my second post
HTC One, stock rooted ROM
Click to expand...
Click to collapse
Then it is because of the implementation of the reboot command of your ROM. On my Samsung Galaxy Ace with AOKP it is working fine.
Maybe you could compile your own busybox and include the reboot command. Then copy it into the data directory of your app and run the commands by typing their full path like this:
Code:
/data/data/com.example.app/files/busybox reboot recovery
Maybe you could compile your own busybox and include the reboot command. Then copy it into the data directory of your app and run the commands by typing their full path like this:
Click to expand...
Click to collapse
Mmm, if i add this myself-compiled busybox version to my app, this will work with all devices?
Because as you can read in the first post, the command should be written in the app I'm working on.
Or there is a universal another command or another way to do it?
rampo said:
Mmm, if i add this myself-compiled busybox version to my app, this will work with all devices?
Because as you can read in the first post, the command should be written in the app I'm working on.
Or there is a universal another command or another way to do it?
Click to expand...
Click to collapse
I really thought that you could use the "reboot recovery" on every device.
However, this is one of the best examples for different implementations on different devices. For example on some phones the "ls" command is linked to "ls -l" (Source). That is why busybox is always the better way. It is working the same on all devices and ROMs.
You need to compile it yourself because the one which is installed by this app does not include the reboot command.
I think that there is no other way as the "universal" did not work on your device. Maybe anotherone has a better idea, but I do not think so.
I really thought that you could use the "reboot recovery" on every device.
However, this is one of the best examples for different implementations on different devices. For example on some phones the "ls" command is linked to "ls -l" (Source). That is why busybox is always the better way. It is working the same on all devices and ROMs.
Click to expand...
Click to collapse
Thanks man, I've tried
Code:
su
reboot recovery
and
Code:
su
reboot bootloader
in my Galaxy Nexus, it works.
I will develop and test the app on Nexus, pure Google software
You could grab the reboot binary (I attached mine from the nexus 7), put it in /system/xbin then do this in terminal :
Code:
su
chmod 775 /system/xbin/reboot
After which, reboot/reboot-recovery/reboot-bootloader should work.
If this works, you can include the binary in the assets folder of your app, then copy it to /system/xbin and chmod it in your code.
Code:
File sdCard = Environment.getExternalStorageDirectory().toString();
File update = new File( sdCard + "reboot");
if (update.exists()) {
System.out.println("reboot binary already exists on sdcard");
} else {
try {
update.createNewFile();
System.out.println("File created successfully");
InputStream is = getAssets().open("reboot");
FileOutputStream fos = new FileOutputStream(update);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
System.out.println("reboot binary successfully moved to sdcard");
// Close the streams
fos.flush();
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("busybox mount -o remount,rw /system"+"\n");
os.writeBytes("cp -f " + sdCard + "/reboot /system/xbin/reboot" + "\n");
os.writeBytes("chmod 775 /system/xbin/reboot" + "\n");
os.writeBytes("rm -f " + sdCard + "/reboot " + "\n");
os.writeBytes("busybox mount -o remount,ro /system"+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
private void rebootToRecovery() {
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("reboot recovery"+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
}
Damn, we really need syntax highlighting and indentation in the code forum tags...
Androguide.fr said:
You could grab the reboot binary (I attached mine from the nexus 7), put it in /system/xbin then do this in terminal :
Code:
su
chmod 775 /system/xbin/reboot
After which, reboot/reboot-recovery/reboot-bootloader should work.
If this works, you can include the binary in the assets folder of your app, then copy it to /system/xbin and chmod it in your code.
Code:
File sdCard = Environment.getExternalStorageDirectory();
sdCard.toString();
File update = new File( sdCard + "reboot");
if (update.exists()) {
System.out.println("reboot binary already exists on sdcard");
} else {
try {
update.createNewFile();
System.out.println("File created successfully");
InputStream is = getAssets().open("xbin");
FileOutputStream fos = new FileOutputStream(update);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
System.out.println("reboot binary successfully moved to sdcard");
// Close the streams
fos.flush();
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("busybox mount -o remount,rw /system"+"\n");
os.writeBytes("cp -f " + sdCard + "/reboot /system/xbin/reboot" + "\n");
os.writeBytes("chmod 775 /system/xbin/reboot");
os.writeBytes("busybox mount -o remount,ro /system"+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
private void rebootToRecovery() {
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("reboot recovery"+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
}
Damn, we really need syntax highlighting and indentation in the code forum tags...
Click to expand...
Click to collapse
Genial
And there is a command for SafeMode reboot?
rampo said:
Genial
And there is a command for SafeMode reboot?
Click to expand...
Click to collapse
What do you mean by SafeMode ?
Androguide.fr said:
You could grab the reboot binary (I attached mine from the nexus 7), put it in /system/xbin then do this in terminal :
Code:
su
chmod 775 /system/xbin/reboot
After which, reboot/reboot-recovery/reboot-bootloader should work.
If this works, you can include the binary in the assets folder of your app, then copy it to /system/xbin and chmod it in your code.
Code:
File sdCard = Environment.getExternalStorageDirectory();
sdCard.toString();
File update = new File( sdCard + "reboot");
if (update.exists()) {
System.out.println("reboot binary already exists on sdcard");
} else {
try {
update.createNewFile();
System.out.println("File created successfully");
InputStream is = getAssets().open("xbin");
FileOutputStream fos = new FileOutputStream(update);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
System.out.println("reboot binary successfully moved to sdcard");
// Close the streams
fos.flush();
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("busybox mount -o remount,rw /system"+"\n");
os.writeBytes("cp -f " + sdCard + "/reboot /system/xbin/reboot" + "\n");
os.writeBytes("chmod 775 /system/xbin/reboot" + "\n");
os.writeBytes("rm -f " + sdCard + "/reboot " + "\n");
os.writeBytes("busybox mount -o remount,ro /system"+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
private void rebootToRecovery() {
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("reboot recovery"+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
}
Damn, we really need syntax highlighting and indentation in the code forum tags...
Click to expand...
Click to collapse
Really great idea. :good: Respect!
Just one thing I would do another way: I would copy the reboot binary to the data folder of the app so that the system is not modyfied.
If the default reboot binary has some additional functions which the system needs, there could go something wrong.
rampo said:
Click to expand...
Click to collapse
Simply type
Code:
su
reboot
PhAkEer said:
Simply type
Code:
su
reboot
Click to expand...
Click to collapse
nikwen said:
Really great idea. :good: Respect!
Just one thing I would do another way: I would copy the reboot binary to the data folder of the app so that the system is not modyfied.
If the default reboot binary has some additional functions which the system needs, there could go something wrong.
Click to expand...
Click to collapse
Yeah you're definitely right, would be better practice :good:
PhAkEer said:
Simply type
Code:
su
reboot
Click to expand...
Click to collapse
Dude, just read the thread...

{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.

[Q] Help with Chainfire's libsuperuser./Progressbar for asyncactivity

Hello there,
I know this is a noob question but I am unable to implement libsuperuser by chainfire for my app, I can't understand the Asyncactivity he creates in his example project. I have tried that way for a simple Root Checker app, but i am unable to do it, beacuse my app doesn't ask for superuser permissions
So, could anyone please point me to any sample program using his libs, which is simple enough for a beginner to understand .
Thanks in Advance.
RootTools
gh0stslayer said:
Hello there,
I know this is a noob question but I am unable to implement libsuperuser by chainfire for my app, I can't understand the Asyncactivity he creates in his example project. I have tried that way for a simple Root Checker app, but i am unable to do it, beacuse my app doesn't ask for superuser permissions
So, could anyone please point me to any sample program using his libs, which is simple enough for a beginner to understand .
Thanks in Advance.
Click to expand...
Click to collapse
Why don't you try roottools library? It's really simple, and intuitive. Lots of documentations also available!
Here is a link for you : http://code.google.com/p/roottools/
For su request on start, you must have:
Code:
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
in your manifest.
To check for su :
Code:
if(RootTools.isRootAvailable())
Log.e("YourTag","We have root!");
else Log.e("YourTag","No root access :( !");
nerroSS said:
Why don't you try roottools library? It's really simple, and intuitive. Lots of documentations also available!
Here is a link for you : http://code.google.com/p/roottools/
For su request on start, you must have:
Code:
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
in your manifest.
To check for su :
Code:
if(RootTools.isRootAvailable())
Log.e("YourTag","We have root!");
else Log.e("YourTag","No root access :( !");
Click to expand...
Click to collapse
Thanks for your reply. I tried adding the permission but it didn't work with libsuperuser. It must be something I wrote in the program.
I am now trying with roottools -
so if I have to copy a file from data/app to sdcard, how will I pass the shell command using RootTools ?
gh0stslayer said:
Thanks for your reply. I tried adding the permission but it didn't work with libsuperuser. It must be something I wrote in the program.
I am now trying with roottools -
so if I have to copy a file from data/app to sdcard, how will I pass the shell command using RootTools ?
Click to expand...
Click to collapse
Code:
CommandCapture command1 = new CommandCapture(0,"echo 1 > /sdcard/mycommandouput");
try {
RootTools.getShell(true).add(command1).waitForFinish();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Or for multi-command
Code:
CommandCapture command1 = new CommandCapture(0,"first command","second command here");
try {
RootTools.getShell(true).add(command1).waitForFinish();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Keep in mind that commands are as super-user, so no need to "su -c" / "su"..
nerroSS said:
Code:
CommandCapture command1 = new CommandCapture(0,"echo 1 > /sdcard/mycommandouput");
try {
RootTools.getShell(true).add(command1).waitForFinish();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Or for multi-command
Code:
CommandCapture command1 = new CommandCapture(0,"first command","second command here");
try {
RootTools.getShell(true).add(command1).waitForFinish();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Keep in mind that commands are as super-user, so no need to "su -c" / "su"..
Click to expand...
Click to collapse
How do I get past this error -
The method waitForFinish() is undefined for the type Command
Sorry for so many stupid questions, i am trying to learn
gh0stslayer said:
How do I get past this error -
The method waitForFinish() is undefined for the type Command
Sorry for so many stupid questions, i am trying to learn
Click to expand...
Click to collapse
I didn't close try{}, sorry! Put a "}" at the end of my code and it should work!
If you have any questions, feel free to pm me.
Edit 3: I have corrected my post. Copy paste the code above and should work now.
Here's a great RootTools tutorial: http://forum.xda-developers.com/showthread.php?t=2226664
nikwen said:
Here's a great RootTools tutorial: http://forum.xda-developers.com/showthread.php?t=2226664
Click to expand...
Click to collapse
nerroSS said:
I didn't close try{}, sorry! Put a "}" at the end of my code and it should work!
If you have any questions, feel free to pm me.
Edit 3: I have corrected my post. Copy paste the code above and should work now.
Click to expand...
Click to collapse
Thanks for your replies gentlemen. I finally settled for CMDProcessor and succeeded in making my command to work.
Now the command takes a long time to finish as it involves copying quite a few files and as it froze the main UI thread I used ASyncTask to take the heavy work to background thread.
Now I can't find a way to show a progress bar for the activities going on in the background thread. Can you please shed some light on how I could set some kind of progress update ... Thanks In Advance.
Edit : Should I use something other than ASyncActivity as the file copy opeartion takes several minutes and android developer website suggests to use executor or futuretask for tasks that require too long to complete
gh0stslayer said:
Thanks for your replies gentlemen. I finally settled for CMDProcessor and succeeded in making my command to work.
Now the command takes a long time to finish as it involves copying quite a few files and as it froze the main UI thread I used ASyncTask to take the heavy work to background thread.
Now I can't find a way to show a progress bar for the activities going on in the background thread. Can you please shed some light on how I could set some kind of progress update ... Thanks In Advance.
Edit : Should I use something other than ASyncActivity as the file copy opeartion takes several minutes and android developer website suggests to use executor or futuretask for tasks that require too long to complete
Click to expand...
Click to collapse
If it really takes that much time, I would use a remote service (a remote service runs in another process).
Using a remote service, closing the app using the recent apps menu won't stop that. The same applies for UI crashes. The copy operation won't stop if the UI crashes for whatever reason. You won't have to worry about orientation changes as well.
nikwen said:
If it really takes that much time, I would use a remote service (a remote service runs in another process).
Using a remote service, closing the app using the recent apps menu won't stop that. The same applies for UI crashes. The copy operation won't stop if the UI crashes for whatever reason. You won't have to worry about orientation changes as well.
Click to expand...
Click to collapse
Thanks for your reply again, I was trying to find a way to visualize the progress with a progress bar or something. Although I could not make a progress bar to work I was able to implement a spinner . . . Although a progressbar still would have been better, but for now, it serves the purpose of creating a sense of the activity happening in the background .
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I will try to understand and implement the remote service that you linked, lets hope it isn't too much work .
Edit : The advantages you stated for remote service are all here too, even when I killed tha app from recents menu, the file copying operation still went on in the background .
Edit 2 : Orientation change only removes the spinner dialog, but the file copy operation proceeds until it's complete. The only thing that seems to stop the operation is when i uninstall the app from my device, while its still being executed. So I would say this baby is rock solid, just an addition of a progress bar would serve it well. :victory:
gh0stslayer said:
Thanks for your reply again, I was trying to find a way to visualize the progress with a progress bar or something. Although I could not make a progress bar to work I was able to implement a spinner . . . Although a progressbar still would have been better, but for now, it serves the purpose of creating a sense of the activity happening in the background .
I will try to understand and implement the remote service that you linked, lets hope it isn't too much work .
Edit : The advantages you stated for remote service are all here too, even when I killed tha app from recents menu, the file copying operation still went on in the background .
Click to expand...
Click to collapse
Well, you could try to do it like this:
Copy the files one by one or copy 5 at once. And afterwards set the progress to a higher value. That would, however, be more time consuming as the IPC (InterProcessCommunication) takes much time.
You could also do the copying using a script and "echo" some output after every 5 copied files. Then you would need to constantly listen for output and if you receive any, increase the progress value.
I would go with the spinner for performance though.
nikwen said:
Well, you could try to do it like this:
Copy the files one by one or copy 5 at once. And afterwards set the progress to a higher value. That would, however, be more time consuming as the IPC (InterProcessCommunication) takes much time.
You could also do the copying using a script and "echo" some output after every 5 copied files. Then you would need to constantly listen for output and if you receive any, increase the progress value.
I would go with the spinner for performance though.
Click to expand...
Click to collapse
Hmmm, interesting idea. I am using a shell command , which one would be better, guess I could echo some output to a dialog box.
On the contrary it would slow down the performance of app, so like you said spinner would be better for performance.
Still I would try to make some sort of progress bar work, please suggest which method should i use. I am using a shell command
"cp -r /data/app/ /sdcard/backup/apps" , to copy a whole directory to sdcard .
gh0stslayer said:
Hmmm, interesting idea. I am using a shell command , which one would be better, guess I could echo some output to a dialog box.
On the contrary it would slow down the performance of app, so like you said spinner would be better for performance.
Still I would try to make some sort of progress bar work, please suggest which method should i use. I am using a shell command
"cp -r /data/app/ /sdcard/backup/apps" , to copy a whole directory to sdcard .
Click to expand...
Click to collapse
This one would be slower but would give you an output after every copied file:
Code:
find /data/app -exec cp {} /sdcard/backup/apps \; -exec echo copy \;
It doesn't work properly with subdirectories though. However, that won't be important for you as /data/app doesn't contain subdirectories.
---------- Post added at 11:06 PM ---------- Previous post was at 10:58 PM ----------
Use this to get the total number of files in /data/app/:
Code:
ls /data/app/ | wc -l
---------- Post added at 11:09 PM ---------- Previous post was at 11:06 PM ----------
Using
Code:
ls -f /data/app | wc -l
will make it even faster because the list (whose lines are counted) won't be sorted.
nikwen said:
This one would be slower but would give you an output after every copied file:
Code:
find /data/app -exec cp {} /sdcard/backup/apps \; -exec echo copy \;
It doesn't work properly with subdirectories though. However, that won't be important for you as /data/app doesn't contain subdirectories.
---------- Post added at 11:06 PM ---------- Previous post was at 10:58 PM ----------
Use this to get the total number of files in /data/app/:
Code:
ls /data/app/ | wc -l
Click to expand...
Click to collapse
I was using this to get the no of files in the directory
find /data/app -type f -print| wc -l
But i couldn't figure out how to monitor the no of files copied to the sdcard to make a progressbar out of it.
And for this find /data/app -exec cp {} /sdcard/backup/apps \; -exec echo copy \ i assume the output will have to be shown in a dialog box.
On another note, thanks a lot for helping a nobody like me out. I am trying to learn app development and people like you are making it easier for me, means a lot to me. Keep up your awesome work and keep spreading your knowledge. :good:
gh0stslayer said:
I was using this to get the no of files in the directory
find /data/app -type f -print| wc -l
But i couldn't figure out how to monitor the no of files copied to the sdcard to make a progressbar out of it.
And for this find /data/app -exec cp {} /sdcard/backup/apps \; -exec echo copy \ i assume the output will have to be shown in a dialog box.
On another note, thanks a lot for helping a nobody like me out. I am trying to learn app development and people like you are making it easier for me, means a lot to me. Keep up your awesome work and keep spreading your knowledge. :good:
Click to expand...
Click to collapse
The new and faster version I posted above (ls -f /data/app | wc -l) should be the best (i.e. fastest) way to get the number of files.
Then you would need to constantly check the output of the java.lang.Process which runs your command. Change the progress value of the ProgressBar after every line of output.
I'll look into that tomorrow if you post a link to your CMDProcessor version in the meantime. Got to get some sleep now.
Thank you very much for the compliments... and welcome.
nikwen said:
The new and faster version I posted above (ls -f /data/app | wc -l) should be the best (i.e. fastest) way to get the number of files.
Then you would need to constantly check the output of the java.lang.Process which runs your command. Change the progress value of the ProgressBar after every line of output.
I'll look into that tomorrow if you post a link to your CMDProcessor version in the meantime. Got to get some sleep now.
Thank you very much for the compliments... and welcome.
Click to expand...
Click to collapse
Yeah man, I should get some sleep too. Been at this since 6 PM and its 4 AM now.
BTW here is the link for CMDProcessor I used
http://forum.xda-developers.com/showpost.php?p=40579474&postcount=23
gh0stslayer said:
Yeah man, I should get some sleep too. Been at this since 6 PM and its 4 AM now.
BTW here is the link for CMDProcessor I used
http://forum.xda-developers.com/showpost.php?p=40579474&postcount=23
Click to expand...
Click to collapse
My idea would be to add another run method to the SH class:
Code:
public CommandResult runWaitForWithProgress(final String s) {
s += "; echo This is the end of the command";
if (DEBUG)
Log.d(TAG, "runWaitFor( " + s + " )");
final Process process = run(s);
Integer exit_value = null;
String stdout = null;
String stderr = null;
if (process != null) {
try {
final DataInputStream dis = new DataInputStream(process.getInputStream());
while (true) {
if (dis.available() > 0) {
if (dis.readLine().equals("This is the end of the command")) {
break;
} else {
//TODO: Increase progress here
}
}
try {
Thread.sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
}
exit_value = process.waitFor();
stdout = getStreamLines(process.getInputStream());
stderr = getStreamLines(process.getErrorStream());
} catch (final InterruptedException e) {
Log.e(TAG, "runWaitFor " + e.toString());
} catch (final NullPointerException e) {
Log.e(TAG, "runWaitFor " + e.toString());
}
}
return new CommandResult(exit_value, stdout, stderr);
}
I've written this in a text editor and haven't tested it. So no guarantee that it will work. You'll probably have to fix some errors. But it should explain my idea.
nikwen said:
My idea would be to add another run method to the SH class:
Code:
public CommandResult runWaitForWithProgress(final String s) {
s += "; echo This is the end of the command";
if (DEBUG)
Log.d(TAG, "runWaitFor( " + s + " )");
final Process process = run(s);
Integer exit_value = null;
String stdout = null;
String stderr = null;
if (process != null) {
try {
final DataInputStream dis = new DataInputStream(process.getInputStream());
while (true) {
if (dis.available() > 0) {
if (dis.readLine().equals("This is the end of the command")) {
break;
} else {
//TODO: Increase progress here
}
}
try {
Thread.sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
}
exit_value = process.waitFor();
stdout = getStreamLines(process.getInputStream());
stderr = getStreamLines(process.getErrorStream());
} catch (final InterruptedException e) {
Log.e(TAG, "runWaitFor " + e.toString());
} catch (final NullPointerException e) {
Log.e(TAG, "runWaitFor " + e.toString());
}
}
return new CommandResult(exit_value, stdout, stderr);
}
I've written this in a text editor and haven't tested it. So no guarantee that it will work. You'll probably have to fix some errors. But it should explain my idea.
Click to expand...
Click to collapse
Is there a way to assign the output given by
Code:
ls /data/app/ | wc -l
to a variable ???
gh0stslayer said:
Is there a way to assign the output given by
Code:
ls /data/app/ | wc -l
to a variable ???
Click to expand...
Click to collapse
In a script or in Java?
nikwen said:
In a script or in Java?
Click to expand...
Click to collapse
In Java :silly:
I m trying to write the output of the command to a text file in sdcard
Code:
cmd.su.runWaitFor("ls /data/app/ | wc -l > /sdcard/bck.txt");
My aim is to use it to store the no of apps from the text file to a variable , and then use it for the progressbar .
Although It writes a text file with the no of apps as its content, i am unable to assign it to a variable in java
Code:
FileInputStream is = null;
BufferedInputStream bis = null;
try {
is = new FileInputStream(new File("sdcard/backovery/bck.txt"));
bis = new BufferedInputStream(is);
nFiles = bis.read();
}catch (IOException e) {
e.printStackTrace();
tv.setText(""+nFiles);
It works but shows the value for nFiles in textview as 0 .
But it will be less messy if I could just store the shell command's output to a variable instead of storing it on a text file .

NTFS on your android with full read write support

How to install this:
1. put copymodulecrc to the /data/local/tmp folder and chmod them to 755
(adb shell chmod 755 /data/local/tmp/copymodulecrc)
2. put ntfs-3g and ntfsmount to the folder /system/bin and chmod them to 755
(adb shell chmod 755 /system/bin/ntfs-3g)
(adb shell chmod 755 /system/bin/ntfsmount)
3. put sdcardfs.ko to the folder /system/lib/modules and chmod them to 644
(adb shell chmod 644 /system/lib/modules/sdcardfs.ko)
What is next? Next:
1. in order to get it working, sdcardfs.ko must be patched to match your kernel version since every kernel modules is paired with kernel by version string, so if version string not match module version it will not work! So you must patch sdcardfs.ko module using tool called copymodulecrc! Copymodulecrc will extract version string from any module of the your stockrom kernel modules and copy them directly to the sdcardfs.ko (patch them). First of all you need to look into your /system/lib/modules folder and use any .ko file NAME for referencie in next commands:
Code:
adb shell /data/local/tmp/copymodulecrc /system/lib/modules/PUT_NAME_OF_THE_KO_YOU_FOUND_IN_STOCK_ROM_KERNEL_MODULES /system/lib/modules/sdcardfs.ko
So replace PUT_NAME_OF_THE_KO_YOU_FOUND_IN_STOCK_ROM_KERNEL_MODULES with the name of the any module you found in modules folder! Done.
2. if you completed step 1 without errors you are ready for this step. You need to locate script called install-recovery.sh (on most devices it is in folder /system/etc) and add next lines:
Code:
insmod /system/lib/modules/sdcardfs.ko
Done. On every next reboot sdcardfs kernel module will be automatically included in your kernel.
3. if you get error in patching sdcardfs.ko whole thing will not work! So these step is important! You can verify success by command: (su -c "insmod /system/lib/modules/sdcardfs.ko") , if you see error than sdcardfs is not working, if you see nothing than it is working
Since you completed these 3 things, you are ready to use NTFS volumes on your device! To understand these things:
1. first of all, you can not mount ntfs volume regulary trought settings menu since android not support ntfs by default! You must mount/umount your ntfs volume manually (you can use for example android terminal emulator when you need to mount/umount ntfs). You will not see any details about ntfs volume in settings menu since android not support ntfs by default, you can see details in most file managers only.
How to mount and unmount:
1. to mount (first connect your usb ntfs volume to your device usb port) :
Code:
su -c "ntfsmount mount"
Done! Your ntfs volume by these command is mounted and you are ready to read/write them using your faworite file manager
2. To umount (do in mind - every time before you going to remove ntfs volume from your device you must unmount it!):
Code:
su -c "ntfsmount umount"
Done! You are ready to remove ntfs volume from your usb port.
NTFS on sdcard? Yes but you need to modify a bit ntfsnount script! Don't ask me how ypu can modify them, do it byself!
Since somebody complain here about gpl licence, I am not ready ready to share sdcardfs source code with you since it is not gpl licenced, instead it is apache 2.0 licenced by Samsung guys @ 2013 and I no need to share it with you since you wanted to see them forced! I not like when somebody forcing me for something! Find it, patch them, make module of them byself
ntfs-3g is not compiled by me, it is used from here -> http://forum.xda-developers.com/showthread.php?t=1724078
ntfsmount script is created by me.
Copymodulecrc I do not know where I found them but here is source code:
Code:
/* copymodulecrc */
/*
* Copyright (C) 2014 CUBE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
int main(int argc, char **argv) {
struct stat st;
off_t filesize;
int fd;
char *data, *pos;
unsigned int i;
int bFound;
unsigned long crcval;
if (argc != 3) {
printf("usage: copymodulecrc [modulename(src)] [modulename(dst)]\n");
return -1;
}
if (stat(argv[1], &st) != 0) {
fprintf(stderr, "module1 stat failed.\n");
return -1;
}
filesize = st.st_size;
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "module1 open failed.\n");
return -1;
}
data = mmap(NULL, filesize, PROT_READ, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "module1 mmap failed.\n");
close(fd);
return -1;
}
pos = data;
bFound = 0;
for (i = 0; i < (filesize - 12); ++i) {
if (memcmp((void *)pos, (void *)"module_layout", 13) == 0) {
bFound = 1;
break;
}
pos++;
}
if (bFound == 0) {
fprintf(stderr, "module1 crc not found.\n");
munmap(data, filesize);
close(fd);
return -1;
}
pos -= 4;
memcpy((void *)&crcval, (void *)pos, 4);
munmap(data, filesize);
close(fd);
printf("module crc=%08x\n", (unsigned int)crcval);
if (stat(argv[2], &st) != 0) {
fprintf(stderr, "module2 stat failed.\n");
return -1;
}
filesize = st.st_size;
fd = open(argv[2], O_RDWR);
if (fd < 0) {
fprintf(stderr, "module2 open failed.\n");
return -1;
}
data = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "module2 mmap failed.\n");
close(fd);
return -1;
}
pos = data;
bFound = 0;
for (i = 0; i < (filesize - 12); ++i) {
if (memcmp((void *)pos, (void *)"module_layout", 13) == 0) {
bFound = 1;
break;
}
pos++;
}
if (bFound == 0) {
fprintf(stderr, "module2 crc not found.\n");
munmap(data, filesize);
close(fd);
return -1;
}
pos -= 4;
memcpy((void *)pos, (void *)&crcval, 4);
munmap(data, filesize);
close(fd);
printf("module crc copied.\n");
return 0;
}
And finaly, files you need to install is in attachment, enjoy!
Will try late-night. Just asking, will it work on Galaxy S3-GTi9300?
Just need some clarification, when you say NTFS support, do you mean read and write or just read-only?
munjeni said:
Not going to explain in details, here is my tool which will add ntfs support to your android, run them and folow instructions! If you unable to patch sdcardfs.ko kernel module (giving you error when you doing insmod) than the whole things will not work on your device Curntly tested device is Xperia Z1 Compact on android version 14.4.A.0.108! Important thing is having sdcardfs installable, the rest is easy.
In order to have sdcardfs module insmoded on every reboot, you need to add one line into /system/etc/install-recovery.sh :
The rest of the tutorial you can see under application. Enjoy if you find this usefull!
Click to expand...
Click to collapse
/system/etc/install-recovery.sh :-
- install-recovery.sh file is not available at /system/etc/.
- Is it possible to create the file and then we can insert the line?
Am using AOSP - Carbon ROM on Xperia Z..
Thank you!!
'A Munjeni Work' again!
Thanks a lot! :victory:
Looking forward for what all can I do with it.
Wow this will be amazing, cant wait to try...
anonyo said:
Just need some clarification, when you say NTFS support, do you mean read and write or just read-only?
Click to expand...
Click to collapse
+1
anonyo said:
Just need some clarification, when you say NTFS support, do you mean read and write or just read-only?
Click to expand...
Click to collapse
Quote!
Just a heads up..
On Xperia Z2 tablet with 4.4.2, connected to 1tb NTFS drive.
After modding the ko and setting all permissions, rebooting, will only "half-mount" the drive. It sees it, recognizes it, but claims drive is empty (wants to format it).
Status bar displays "Empty USB Storage"
In settings, when selecting Mount USB Storage, it briefly acts like it will mount. for a split second.
Any files I can get that can possibly help?
UPDATE: After running the mount commands via terminal, now it seems to mount it via ES File explorer. Although it sometimes still gives me the message in statusbar.
But seems to be working well.
Seeing as this patches a kernel module will it work on rooted phones with a locked bootloader?
Aborto said:
Seeing as this patches a kernel module will it work on rooted phones with a locked bootloader?
Click to expand...
Click to collapse
My Z2 Tablet has a locked bootloader. So yes, it should. There's nothing going on that warrants an unlocked bootloader. Just the addition of some files and permission changes, which are normal with a rooted device.
Also note, that in the Settings\Storage, it will not show up as being "mounted". At least not in my case. However, ES File Explorer has no issue with it, and shows as a USB 1052 drive under the "Local" menu. Navigation seems normal within the drive.
I get the "USB Drive Empty or Unsupported" message in the status bar, for a few seconds, but the ES FE displays the drive contents, and the message goes away after it reads drive contents. Note that it may assign a different drive identifier each time you use it.
In testing I have found apps from the market;
StickMount does not work at all on my Stock OS.
Paragon NTFS mount works, but it runs as a system process using memory and probably battery.
This mod seems to work, for the most part, as long as you use ES File Explorer.
OP - you must provide the source for any modified code covered by the GPL that you are distributing - that includes the sdcardfs kernel module, and the ntfs-3g binary. Packing them in an encrypted Windows executable does not help.
spoidar said:
OP - you must provide the source for any modified code covered by the GPL that you are distributing - that includes the sdcardfs kernel module, and the ntfs-3g binary. Packing them in an encrypted Windows executable does not help.
Click to expand...
Click to collapse
No he doesn't. Only the zimage (kernel) is covered under GPL.
UPDATE: Just to clarify, the matter "Has" been brought to the Developers Committee to address any possible GPL violations. The DC is more informed on GPL.
Moscow Desire said:
No he doesn't. Only the zimage (kernel) is covered under GPL.
Click to expand...
Click to collapse
What? No. The ntfs-3g project is licensed under the GPL. And so is the sdcardfs driver. You can't generate binaries from GPL code and distribute them without providing the source.
Need help here
After i Copy copymodulecrc and sdcardfs.ko to /data/local/tmp and gave the permission as rwx-r-r to copymodulecrc. how to run it? can anybody help me here to patch sdcardfs.ko
coolrevi said:
After i Copy copymodulecrc and sdcardfs.ko to /data/local/tmp and gave the permission as rwx-r-r to copymodulecrc. how to run it? can anybody help me here to patch sdcardfs.ko
Click to expand...
Click to collapse
First off, permissions must be set to 755 (rwx-rx-rx) if I'm not mistaken. Root Explorer converts it to the numerical format when you change permissions.
Next, use a terminal program (available from the play store) Make sure you run it as SU. (type SU + Enter, you will get the # sign) Then type in the commands and paths as indicated. (I copied and pasted my paths)
Moscow Desire said:
First off, permissions must be set to 755 (rwx-rx-rx) if I'm not mistaken. Root Explorer converts it to the numerical format when you change permissions.
Next, use a terminal program (available from the play store) Make sure you run it as SU. (type SU + Enter, you will get the # sign) Then type in the commands and paths as indicated. (I copied and pasted my paths)
Click to expand...
Click to collapse
I got it till replacing a line in install-recovery.sh but i am stuck there as there is no line called ntfs.ko to replace with
Thanks for posting this up, can't wait to get home and test this out.
I am recieving the error in the screenshot
The device that i am using is Lenovo A3500HV which contains a Jellybean 4.2.2 AOSP ROM (Hardly any modification)
Please Help
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}

Categories

Resources