private List<String> existingRootPackages() {
        ArrayList<String> packages = new ArrayList<>();
        packages.addAll(Arrays.asList(KNOWN_ROOT_APPS_PACKAGES));
        packages.addAll(Arrays.asList(KNOWN_DANGEROUS_APPS_PACKAGES));
        packages.addAll(Arrays.asList(KNOWN_ROOT_CLOAKING_PACKAGES));

        PackageManager pm = context.getPackageManager();
        List<String> packagesFound = new ArrayList<>();

        for (String packageName : packages) {
            try {
                // Root app detected
                pm.getPackageInfo(packageName, 0);
                packagesFound.add(packageName);
            } catch (PackageManager.NameNotFoundException e) {
                // Exception thrown, package is not installed into the system
            }
        }
        return packagesFound;
    }
private List < String > existingRootPackages ( ) { ArrayList < String > packages = new ArrayList < > ( ) ; packages . addAll ( Arrays . asList ( KNOWN_ROOT_APPS_PACKAGES ) ) ; packages . addAll ( Arrays . asList ( KNOWN_DANGEROUS_APPS_PACKAGES ) ) ; packages . addAll ( Arrays . asList ( KNOWN_ROOT_CLOAKING_PACKAGES ) ) ; PackageManager pm = context . getPackageManager ( ) ; List < String > packagesFound = new ArrayList < > ( ) ; for ( String packageName : packages ) { try { pm . getPackageInfo ( packageName , 0 ) ; packagesFound . add ( packageName ) ; } catch ( PackageManager . NameNotFoundException e ) { } } return packagesFound ; }
Checks for packages that are known to indicate root.
@return - list of such packages found