FORUMS
Remove All Ads from XDA

[DEV GUIDE][2016.12.22] How-To SU

11,217 posts
Thanks Meter: 85,996
 
By Chainfire, XDA Ad-Free Senior Moderator / Senior Recognized Developer - Where is my shirt? on 29th October 2012, 08:38 PM
Post Reply Email Thread
8th November 2012, 12:42 AM |#11  
Quote:
Originally Posted by Chainfire

Ok, yeah that's fine. AsyncTask is pretty much a Thread wrapper with handy utility functions (onPreExecute, onPostExecute, onProgressUpdate) that is specifically aimed at running a short-lived task away from the UI thread, often with UI feedback (it's brilliant for use with progress dialogs, for example).

Ah ha! its like a SwingWorker() but with better functionality... Thanks Chainfire! I just looked and apparently it's not available on desktop or I would be switching immediately. That's a wonderful class.
The Following User Says Thank You to AdamOutler For This Useful Post: [ View ]
 
 
9th November 2012, 08:33 PM |#12  
Inactive Recognized Developer
Flag Ottawa/Gatineau, Canada
Thanks Meter: 4,145
 
Donate to Me
More
Quote:
Originally Posted by Chainfire

Guidelines for problem-free su usage

How-To SU is my guide on using "su" in your own programs (to execute commands as root). The guide covers the major common pitfalls and also provides example code, as I have been asked by several developers to provide.

Great & sorely needed topic, thank you. I rarely check this forum, but stumbled in here. Hopefully busy devs of SU apps will be pointed here by someone.

I continue to have lots of problems with SuperUser/SuperSU apps that seem to be pre-configured or something to prevent SU access; and the user is never even prompted. But I don't think this is being discussed here.

At some point in the early development of ICS ROMs I noted that SU calls were taking much longer, perhaps about 0.1 seconds. So I optimized the 4-5 seconds and 40 or 50 calls (including blind chmod's for files that didn't exist on many devices) to about 2-4 calls for most devices.

I know I continue to be guilty of calling SU, and shell, and various other things from improper places, such as UI threads, onCreate etc. But I don't think these cause too much trouble in general, so putting these in threads or wherever is an exercise I save for an app re-design.

My app currently allows selection of "SU Type", but it doesn't seem to be needed anymore, now that I'm avoiding the quoting problems I've had previously.

I use the system() call from C/JNI in a lib. My best/default is like this, where CMD is the command, and noting that \" is " escaped in C:
system ("echo \"CMD\" | su -c sh");


This works, but writes to the filesystem every time:
system ("su -c \"sh /data/local/cmd\""); // Write CMD to cmd file first.


The simplest, but I was having more problems with this for whatever reason; perhaps quoting issues:
system ("su -c \"CMD\"");
The Following User Says Thank You to mikereidis For This Useful Post: [ View ] Gift mikereidis Ad-Free
9th November 2012, 10:03 PM |#13  
pisy3's Avatar
Junior Member
Flag Oslo
Thanks Meter: 3
 
More
thx

---------- Post added at 11:03 PM ---------- Previous post was at 10:58 PM ----------

it is great
20th November 2012, 10:29 PM |#14  
andrewpmoore's Avatar
Senior Member
Flag Leeds
Thanks Meter: 686
 
Donate to Me
More
Quote:
Originally Posted by pisy3

thx

---------- Post added at 11:03 PM ---------- Previous post was at 10:58 PM ----------

it is great

I'm trying to convert my app to use your example classes for running root commands, as most of my app was implemented ok, but I needed to change a couple of bits based on your document. Once chaning I keep running into the following error:

11-20 22:16:39.770: I/System(31924): libcore.io.ErrnoException: kill failed: ESRCH (No such process)
11-20 22:16:39.770: I/System(31924): at libcore.io.Posix.kill(Native Method)
11-20 22:16:39.770: I/System(31924): at libcore.io.ForwardingOs.kill(ForwardingOs.java:77)
11-20 22:16:39.770: I/System(31924): at java.lang.ProcessManager$ProcessImpl.destroy(Proce ssManager.java:257)
11-20 22:16:39.770: I/System(31924): at eu.chainfire.libsuperuser.Shell.run(Shell.java:100 )
11-20 22:16:39.770: I/System(31924): at eu.chainfire.libsuperuser.Shell$SH.run(Shell.java: 149)
11-20 22:16:39.770: I/System(31924): at com.rageconsulting.android.lightflow.util.RootUtil .runRootUnixCommand(RootUtil.java:49)

I'm calling my own helper method which is just a wrapper around your Shell class and it's getting called from an IntentService so I'm not quite sure why this happens.
21st November 2012, 07:48 PM |#15  
Dark3n's Avatar
Recognized Developer
Thanks Meter: 4,355
 
More
You can ignore that.

By calling exit here, the process is usually gone.
When it tries to destroy the process in this line, the process is already gone, so it throws that error message as there is nothing to kill/destroy.
Before Android 4.0 this message was not even printed into the log.
17th December 2012, 11:29 PM |#16  
Chainfire's Avatar
OP Senior Moderator / Senior Recognized Developer - Where is my shirt?
Thanks Meter: 85,996
 
Donate to Me
More
Update the library code with some changes (like proper gobbling). See GitHub
25th December 2012, 09:09 PM |#17  
maluus's Avatar
Senior Member
Flag Ankara
Thanks Meter: 44
 
More
Hello dear developers of the supersu. first thanks for good work. I don't know if anyone informed but after htc one s jb update there seem to be some compatibility problems.
23rd January 2013, 01:32 PM |#18  
Chainfire's Avatar
OP Senior Moderator / Senior Recognized Developer - Where is my shirt?
Thanks Meter: 85,996
 
Donate to Me
More
The article has been updated to v1.20.

Changes are clearly marked in the "Table of Contents"

http://su.chainfire.eu/
5th April 2013, 07:35 PM |#19  
Member
Thanks Meter: 55
 
More
Does the library support other superuser apps too?
6th April 2013, 10:06 AM |#20  
Chainfire's Avatar
OP Senior Moderator / Senior Recognized Developer - Where is my shirt?
Thanks Meter: 85,996
 
Donate to Me
More
Quote:
Originally Posted by mcnamaragio

Does the library support other superuser apps too?

Yes, it's all about best practises when calling the su binary - it should work with all superuser apps.
18th May 2013, 07:38 PM |#21  
Member
Thanks Meter: 55
 
More
Quote:
Originally Posted by Chainfire

Yes, it's all about best practises when calling the su binary - it should work with all superuser apps.

At Supporting multiple icons in your app you mention you plan to write a blog post about changing application theme and locale at runtime. Do you still plan to publish it ? I am very interested in those techniques.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes