Requesting root access for android app -
i know there questions here, tried answers given without success.
there's simple checkboxpreference (titled "root"):
<checkboxpreference android:key="root" android:title="@string/root" android:summary="@string/root_summary" android:defaultvalue="false" />
now need set onpreferencechangelistener on , gain root access. if checkbox should checked, otherwise should not:
public class settings extends preferenceactivity implements onpreferencechangelistener { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); addpreferencesfromresource(r.xml.settings); findpreference("root").setonpreferencechangelistener(this); } @override public boolean onpreferencechange(preference preference, object newvalue) { string key = preference.getkey(); if ("root".equals(key) && !((checkboxpreference) preference).ischecked()) { seek { process p = runtime.getruntime().exec("su"); p.waitfor(); log.d("settings", integer.tostring(p.exitvalue())); if (p.exitvalue() == 255) { log.d("settings", "###no root###"); homecoming false; } } grab (exception e) { log.d("settings", "###no root###"); log.d("settings", e.getmessage()); homecoming false; } log.d("settings", "!!!root!!!"); } homecoming true; } }
superuser prompts correctly root access. denying returns true, exitvalue 1 (???) , allowing freezes whole app (i guess @ p.waitfor).
i'm running superuser 3.1.3 su binary 3.1.1 (newest versions).
taking logcat can see next message: activity pause timeout activityrecord{42c0ebb8 com.example/.gui.settings}
the command you're running su
will, suspect, run shell superuser. you're waiting (indefinitely) shell finish.
you need specify su some-command-here-which-needs-to-run-as-root
.
unfortunately, there no way accomplish superuser permissions java code within android project. root-ness applies commands spawned su
itself.
android
No comments:
Post a Comment