2017-12-16 06:15:17 -05:00
|
|
|
package us.spotco.malwarescanner;
|
|
|
|
|
2017-12-17 06:36:16 -05:00
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.content.Context;
|
|
|
|
|
2017-12-16 06:15:17 -05:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2017-12-16 15:02:10 -05:00
|
|
|
class Utils {
|
2017-12-16 06:15:17 -05:00
|
|
|
|
2017-12-16 15:02:10 -05:00
|
|
|
private final static int MAX_FILE_SIZE = (1000 * 1000) * 50; //50MB
|
2017-12-16 06:15:17 -05:00
|
|
|
|
|
|
|
public static Set<File> getFilesRecursive(File root) {
|
|
|
|
Set<File> filesAll = new HashSet<>();
|
|
|
|
|
|
|
|
File[] files = root.listFiles();
|
|
|
|
if (files != null && files.length > 0) {
|
|
|
|
for (File f : files) {
|
|
|
|
if (f.isDirectory()) {
|
|
|
|
Set<File> 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;
|
|
|
|
}
|
2017-12-17 06:36:16 -05:00
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
2017-12-16 06:15:17 -05:00
|
|
|
}
|