0

如何冻结/解冻root 设备上的应用程序,如Titanium Backup应用程序,以便我无法从 root 设备访问我的应用程序。有什么方法可以追踪设备是否已root?

4

2 回答 2

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();
于 2013-02-26T08:47:18.723 回答
1

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

这里获取代码并对其进行一些修改以满足您的需要,我认为它可以是这样的:

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

我没有对此进行测试,但我相信它会对您有所帮助。或者至少它会为你指明正确的方向。

于 2013-02-25T09:25:41.677 回答