如果设备已获得 root 权限,是否有任何方法可以阻止安装 android 应用程序?

Is there any method to block the installation of an android app, if the device is rooted?

我想知道是否有任何方法可以在安装时阻止 android 应用程序的安装。我知道有一些方法可以像下面列出的方法那样阻止执行,但我想知道是否可以在应用程序的安装阶段应用一些控制。

private static boolean checkRootMethod1() {
String buildTags = android.os.Build.TAGS;     
return buildTags != null && buildTags.contains("test-keys"); }  


private static boolean checkRootMethod2() {     
String[] paths = { "/system/app/Superuser.apk", 
"/sbin/su", "/system/bin/su", "/system/xbin/su",  
"/data/local/xbin/su", "/data/local/bin/su", 
"/system/sd/xbin/su",              
"/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};     
for (String path : paths) {         
if (new File(path).exists()) return true;}     
return false; } 

private static boolean checkRootMethod3() {     
Process process = null;     try {          
process = new ProcessBuilder("/system/xbin/which", "su").start(); 
        BufferedReader in = new BufferedReader(new 
InputStreamReader(process.getInputStream()));         
return in.readLine() != null;     }  
catch (Throwable t) {         return false;     } 
finally {         if (process != null) process.destroy();     } }

执行此方法并查看状态码

Runtime.getRuntime().exec("su");

如果它 returns 是一个进程对象,那么您将知道该设备已获得 root 权限,如果没有,您可以让用户使用该应用程序。