Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SU does sometimes not respond #50

Open
janis605 opened this issue Jul 8, 2012 · 2 comments
Open

SU does sometimes not respond #50

janis605 opened this issue Jul 8, 2012 · 2 comments

Comments

@janis605
Copy link

janis605 commented Jul 8, 2012

Ok, so I am developing an app at the moment, my first on actually, so the problem in this case meight be myself.

basically my application tries to gain su permissions and then execute some commands by sending it to a method called ShellInterface in my case:
Example of calling the method:

Code:

String[] commands = { "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system", };
sendShell(commands, true, 250);


Part of the ShellInterface class:

Code:

try {
System.out.println("ShellInterface got the job.");
System.out.println("Requesting SU permissions");
processx = Runtime.getRuntime().exec("su");
System.out.println("Granted?!");

        os = new DataOutputStream(processx.getOutputStream());
        System.out.println("Stream created?!");

        // Doing Stuff ;)

   for (String single : commands) {
            System.out.println("Doing the commands...");
                os.writeBytes("\n" + single + "\n");
                os.flush();
                System.out.println("Sending exit-signal!");
                os.writeBytes("exit\n");
                os.flush();
                os.close();
                Thread.sleep(sleeptime);
        }

} catch (Exception e) {
System.out.println("Failure in SU command: " + e.getMessage());
Log.d("Unexpected error - Here is what I know: "
+ e.getMessage(), null, e);
e.printStackTrace();
msg = Message.obtain();
msg.arg1 = 1;
msg.arg2 = 0;
res.add(e.getMessage());
}


The Problem is that, from my perspective it only randomly works. I am executing about 10 commands, after e few ones to processX terminates and it will respawn as intended, but sometimes it does simply not finish the command:

processx = Runtime.getRuntime().exec("su");

It gets stuck there and there is no toast notification showing up the access has been granted or not. Just nothing happens. I found the possibility of not running into this increases when I kill the Superuser.apk in the Settings before executing the commands. But still it does often just randomly run into this state of "nothing" happening anymore. (Su request not granted or rejected)

In the logcat I can't find anything interesting. I just noticed that this happens not only in my app but sometimes even in the SU application:

http://dl.dropbox.com/u/39401915/Screenshot_2012-07-08-18-43-04.png
http://dl.dropbox.com/u/39401915/Screenshot_2012-07-08-18-42-44.png

@git-core
Copy link

logcat on the stuck op is needed anyway.

@janis605
Copy link
Author

I already found the specific problem:

It happens when your app is running a webview, that is using JavaScript. Then the processes will randomly get stuck, but as far as I know this is not specific to SU. Anyway, Android is behaving very strange here. This is applicable to any application, when JavaScript is enabled. To slove the problem, use webview.destroy(); before executing the commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants