package us.spotco.malwarescanner; import android.app.ActivityManager; import android.content.Context; import java.io.File; import java.util.HashSet; import java.util.Set; class Utils { private final static int MAX_FILE_SIZE = (1000 * 1000) * 50; //50MB public static Set getFilesRecursive(File root) { Set filesAll = new HashSet<>(); File[] files = root.listFiles(); if (files != null && files.length > 0) { for (File f : files) { if (f.isDirectory()) { Set filesTmp = getFilesRecursive(f); if (filesTmp != null) { filesAll.addAll(filesTmp); } } else { if (f.length() <= MAX_FILE_SIZE) {//Exclude files larger than 50MB for performance filesAll.add(f); } } } } return filesAll; } //Credit: https://stackoverflow.com/a/5921190 public static boolean isServiceRunning(Class serviceClass, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; } }