简体   繁体   中英

How to freeze applications on rooted android device

How can I Freeze/Unfreeze applications on the rooted device like Titanium Backup app so that i make my app non-accessable from a rooted device. Any method to trace whether the device is rooted or not?

i am using RootTools library to do disable/enable command

CommandCapture command_enable = new CommandCapture(0,"pm enable "+ Package_Name);                           
RootTools.getShell(true).add(command_enable).waitForFinish();

CommandCapture command_disable = new CommandCapture(0,"pm disable "+ Package_Name);
RootTools.getShell(true).add(command_disable).waitForFinish();

You could actually try to run a root command and catch the response and determine if the device is rooted.

Taking code from here and modifying it a little to suit your needs, I think it could go like this:

public static boolean canRunRootCommands()
       {
          boolean retval = false;
          Process suProcess;

          try
          {
             suProcess = Runtime.getRuntime().exec("su");

             DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
             DataInputStream osRes = new DataInputStream(suProcess.getInputStream());

             if (null != os && null != osRes)
             {
                retval = true;

                /*
                 *if got to this point, its safe to assume the 
                 *device is rooted and here you can do something 
                 *to tell your app that su is present. Or you could 
                 *use the bool return of this function to know that the 
                 *device is rooted and make the app act different.
                 */

             }
          }
          catch (Exception e)
          {
             // Can't get root !
             // [...] meaning that the device is not rooted

             retval = false;
          }

          return retval;
       }

I have not tested this but I'm sure it will help you. Or at least it will point you in the right way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM