如何冻结root设备上的应用程序

时间:2013-02-25 06:44:32

标签: android root android-package-managers

如何冻结/解冻根设备上的应用程序,例如 Titanium Backup 应用程序,以便让我的应用程序无法从root设备访问。跟踪设备是否已植根的任何方法?

2 个答案:

答案 0 :(得分:4)

我正在使用RootTools库来执行禁用/启用命令

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();

答案 1 :(得分:1)

您实际上可以尝试运行root命令并捕获响应并确定设备是否已植根。

here获取代码并稍微修改它以满足您的需求,我认为它可能是这样的:

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;
       }

我没有测试过这个,但我相信它会对你有所帮助。或者至少它会以正确的方式指出你。