• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

How to revoke superuser after user has enabled it?

Search This thread

nex7er

Senior Member
Feb 3, 2008
449
163
Bergen
I have a switch where, when isChecked is called the app requests superuser the normal way. I however want to also add the ability to disable root when the switch is toggled back to off. How can I do this?

My Switch's onCheckedChanged:

Code:
if (isChecked) {
                    edit_status.putBoolean("rootEnabled", true).commit();
                    edit_status.putInt("customVisible", 1);

                    Process p;
                    try {
                        p = Runtime.getRuntime().exec("su");
                        DataOutputStream os = new DataOutputStream(p.getOutputStream());
                        os.writeBytes("exit\n");
                        os.flush();
                    } catch (IOException e) {
                        // TODO Code to run in input/output exception

                    }

                sensitivity_layout.setVisibility(View.VISIBLE);


                } else {
                    edit_status.putBoolean("rootEnabled", false).commit();
                    edit_status.putInt("customVisible", 0);
                    sensitivity_layout.setVisibility(View.INVISIBLE);

                }