繁体   English   中英

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

[英]How to freeze applications on rooted android device

我如何冻结/取消冻结 root用户设备(如Titanium Backup应用程序)上的应用程序,以便无法从root用户设备访问我的应用程序。 有什么方法可以跟踪设备是否已植根?

我正在使用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();

您实际上可以尝试运行root命令并捕获响应并确定设备是否已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;
       }

我尚未对此进行测试,但是我相信它将为您提供帮助。 或至少它将以正确的方式指出您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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