scottyab / rootbeer

Simple to use root checking Android library and sample app
Apache License 2.0
2.48k stars 440 forks source link

Frequently getPackageInfo in `RootBeer.isRooted()` #218

Open KiBa1215 opened 1 year ago

KiBa1215 commented 1 year ago
    public boolean isRooted() {
        return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary(BINARY_SU)
                || checkForDangerousProps() || checkForRWPaths()
                || detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
    }

In every detect method will finally call

    /**
     * Check if any package in the list is installed
     * @param packages - list of packages to search for
     * @return true if any of the packages are installed
     */
    private boolean isAnyPackageFromListInstalled(List<String> packages){
        boolean result = false;

        PackageManager pm = mContext.getPackageManager();

        for (String packageName : packages) {
            try {
                // Root app detected
                pm.getPackageInfo(packageName, 0);
                QLog.e(packageName + " ROOT management app detected!");
                result = true;
            } catch (PackageManager.NameNotFoundException e) {
                // Exception thrown, package is not installed into the system
            }
        }

        return result;
    }

pm.getPackageInfo(packageName, 0); this method may be not allowed to be called frequently to some other policies (because it's in a for loop).

Myabe cache an installed app list in RootBeer class, and do some local List operations to check if any package is installed, this would be better?

Thanks!