[DEV GUIDE][2016.12.22] How-To SU

Search This thread

goto50

New member
Dec 12, 2017
4
1
I have a Huawei phone, can i also use this method? I need to remove the bloatware away, any other way that i don't need to root my phone? Thanks.:eek:
 
  • Like
Reactions: Namcuanam

mcnamaragio

Senior Member
Dec 26, 2011
85
60
www.aboutmycode.com
I am trying to read content of "/data/system/appops.xml" file so I issue
Code:
 chmod 666
before trying to open the file but I still get FileNotFoundException exception which says "/data/system/appops.xml (Permission denied)". I can see that the permissions is changed to rw-rw-rw by using root explorer. Target sdk of the app is 22 (before runtime permissions). Android device version is 23. Any suggestions how to open the file for reading?
 
  • Like
Reactions: enteharah6

AxelBlaz3

Senior Member
Jan 9, 2013
139
141
Hyderabad
Nice thread! Pretty helpful. Well, I was planning to flash a kernel (made with AnyKernel2 zip) automatically within the app. May I know how do to this? Thank you :p
 

patientx

Member
Oct 25, 2008
40
3
My tv box came rooted BUT there was no su app at all. I installed from google play store and now, there is no app on the launcher or anywhere else... I saw there was a dialer trick to make it visible yet since this is a tv box there is no dialer no phone service... What can I do ?
 

Lion_ofJUDA777@

New member
Jul 29, 2020
1
0
HELP... $

I generally work with desktop apps. Is there a reason to not use Runnable?

Code:
public void liveBackgroundShellCommand() {


        Runnable r = new Runnable() {

            public void run() {
                boolean LinkLaunched = false;
                try {
                    String[] params = (String[]) Statics.LiveSendCommand.toArray(new String[0]);
                    Process process = new ProcessBuilder(params).start();
                    BufferedReader STDOUT = new BufferedReader(new InputStreamReader(process.getInputStream()));
                    BufferedReader STDERR = new BufferedReader(new InputStreamReader(process.getErrorStream()));

This is how I set up a background shell. Then I just pass in the su -c command. Is there a disadvantage to this?

I know this not a help desk but could please post link to secure desk for security question on my systems. I've been chasing my tail and have hit a major platform block at this point. . .or email me at Lion_ofJUDA777@outlook.com I am willing to donate to whobwhere ever may help thank you...
***$$$
 

Top Liked Posts

  • There are no posts matching your filters.
  • 62
    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.

    I also did a presentation on this stuff at the Big Android BBQ 2012, so if you're looking for the article and code promised there, here it is!

    The text is too long to copy here, but you can find it here:

    http://su.chainfire.eu/

    Example code is located on GitHub:

    https://github.com/Chainfire/libsuperuser

    If you are not an app developer, you have no business posting in this thread. This thread is for developer discussion on the article/example code only. In fact, I do not expect many posts in this thread at all - it's all rather straightforward, and this is not a helpdesk.

    Moderators: Do not move this thread to a development subsection, 0-posters need to be able to reply to it.
    15
    No it isn't acceptable, but the reason is not what you might think.

    Using a generic AsyncTask derived class to run su calls can be a solution. As long as your code ends up running in the background, all is good. However, in my experience what usually happens is that you have to do a lot of things in the background.

    For example, imagine that during your app's startup, you need to check some files, perform some su calls, check some more files, do some computations, etc. Those should all go in a single AsyncTask's doInBackground method. That way you can use onPreExecute and onPostExecute to show and dismiss a dialog that tells the user you are busy.

    Furthermore, if you had 10 su commands to run, would you just call new BackgroundThread ... 10 times? As the call should return before the su command is finished executing, the order of the executions of those commands becomes semi-random, you can't depend on them being run in any specific order, it even differs between Android versions (some versions run AsyncTasks serially, others run X of them in parallel). Not to mention that you shouldn't create 10 separate su processes to run 10 commands unless you have a good reason. Batching commands together == much higher performance.

    The above does depend on which commands you need to execute, the needs of your application, and how you use it. If you only have to execute a single su command, it can be done that way, but I think in general this is not an ideal solution.

    Now, the reason why your solution is truly unacceptable is because you are calling doInBackground. This does not make the code run in the background. You override doInBackground and insert your code, but you call the execute method. You should call your code like this:

    Code:
    new BackgroundThread(command).execute();

    Else you're still calling on the main thread !

    If you really want to keep using this method, keep in mind that you can actually pass parameters to the execute() function that in turn will be passed to doInBackground. Look in the AsyncTask documentation ... :)
    5
    Awesome job man, I definitely learned some new stuff. I've done a little bit differently than your implementation: instead of doing AsyncTask -> run su code inside I did this in my Root class:

    Code:
    class BackgroundThread extends AsyncTask<String, Void, Void> {
    		private String s;
    		public BackgroundThread(String command) {
    			s = command;
    		}
    		@Override
    		protected Void doInBackground(String... command) {
    			Process process = null;
    			DataOutputStream os = null;
    			try {
    				process = Runtime.getRuntime().exec("su");
    				os = new DataOutputStream(process.getOutputStream());
    				os.writeBytes(s+"\n");
    				os.writeBytes("exit\n");
    				os.flush();
    				process.waitFor();
    			} catch (Exception e) {
    			}
    			finally {
    				try {
    					if (os != null)
    						os.close();
    					else
    						process.destroy();
    				} catch (Exception e) {
    
    				}
    			}
    			return null;
    		}
    	}

    And then receive the command in the parameter:

    Code:
    public void run(String command) {
    		new BackgroundThread(command).doInBackground();
    	}

    Is this acceptable from your point of view?
    3
    No it isn't acceptable, but the reason is not what you might think.

    Using a generic AsyncTask derived class to run su calls can be a solution. As long as your code ends up running in the background, all is good. However, in my experience what usually happens is that you have to do a lot of things in the background.

    For example, imagine that during your app's startup, you need to check some files, perform some su calls, check some more files, do some computations, etc. Those should all go in a single AsyncTask's doInBackground method. That way you can use onPreExecute and onPostExecute to show and dismiss a dialog that tells the user you are busy.

    Furthermore, if you had 10 su commands to run, would you just call new BackgroundThread ... 10 times? As the call should return before the su command is finished executing, the order of the executions of those commands becomes semi-random, you can't depend on them being run in any specific order, it even differs between Android versions (some versions run AsyncTasks serially, others run X of them in parallel). Not to mention that you shouldn't create 10 separate su processes to run 10 commands unless you have a good reason. Batching commands together == much higher performance.

    The above does depend on which commands you need to execute, the needs of your application, and how you use it. If you only have to execute a single su command, it can be done that way, but I think in general this is not an ideal solution.

    Now, the reason why your solution is truly unacceptable is because you are calling doInBackground. This does not make the code run in the background. You override doInBackground and insert your code, but you call the execute method. You should call your code like this:

    Code:
    new BackgroundThread(command).execute();

    Else you're still calling on the main thread !

    If you really want to keep using this method, keep in mind that you can actually pass parameters to the execute() function that in turn will be passed to doInBackground. Look in the AsyncTask documentation ... :)

    Hmm... I thought calling new BackgroundThread(command).doInBackground(); was doing it in the background thread... if I call new BackgroundThread(command).execute; the commands won't be called at all until I close the application/activity.

    I don't do X new calls, for example in the BootService I just batch commands together and execute it once.

    I'll use your code and see how it works.
    3
    Lots of 5.0 info added the document.