檢查android手機是否root過


package com.example.diaoyong;

import java.io.File;
import java.util.Arrays;
import java.util.List;

public class AExecuteAsRoot {
    
    public static boolean isRootSystem() {        
        if(isRootSystem1()||isRootSystem2()){
            //TODO 可加其他判斷 如是否裝了權限管理的apk,大多數root 權限 申請需要app配合,也有不需要的,這個需要改su源碼。因為管理su權限的app太多,無法列舉所有的app,特別是國外的,暫時不做判斷是否有root權限管理app
            //多數只要su可執行就是root成功了,但是成功后用戶如果刪掉了權限管理的app,就會造成第三方app無法申請root權限,此時是用戶刪root權限管理app造成的。
            //市場上常用的的權限管理app的包名   com.qihoo.permmgr  com.noshufou.android.su  eu.chainfire.supersu   com.kingroot.kinguser  com.kingouser.com  com.koushikdutta.superuser
            //com.dianxinos.superuser  com.lbe.security.shuame com.geohot.towelroot 。。。。。。
            return true;
        }else{
            return false;
        }
    }
    private static boolean isRootSystem1() {        
        File f = null;        
        final String kSuSearchPaths[] = { "/system/bin/", "/system/xbin/",
                "/system/sbin/", "/sbin/", "/vendor/bin/" };
        try {
            for (int i = 0; i < kSuSearchPaths.length; i++) {
                f = new File(kSuSearchPaths[i] + "su");
                if (f != null && f.exists()&&f.canExecute()) {
                    return true;
                }
            }
        } catch (Exception e) {
        }
        return false;
    }
    private static boolean isRootSystem2() {        
        List<String> pros = getPath();
        File f = null;        
        try {
            for (int i = 0; i < pros.size(); i++) {
                f = new File(pros.get(i),"su");
                System.out.println("f.getAbsolutePath():"+f.getAbsolutePath());
                if (f != null && f.exists()&&f.canExecute()) {
                    return true;
                }
            }
        } catch (Exception e) {
        }
        return false;
    }
    
    private static List<String> getPath() {
        return Arrays.asList(System.getenv("PATH").split(":"));
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM