Created
July 7, 2017 11:43
-
-
Save mrtry/30e8a8673023c65d13940ccf0a747eb2 to your computer and use it in GitHub Desktop.
Check app process priority.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Map<Integer, String> importance = new HashMap<Integer, String>(); | |
private static Map<Integer, String> reason = new HashMap<Integer, String>(); | |
static { | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND, "IMPORTANCE_FOREGROUND"); | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE, "IMPORTANCE_PERCEPTIBLE"); | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE, "IMPORTANCE_VISIBLE"); | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE, "IMPORTANCE_SERVICE"); | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE, "IMPORTANCE_FOREGROUND_SERVICE"); | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND, "IMPORTANCE_BACKGROUND"); | |
importance.put(ActivityManager.RunningAppProcessInfo.IMPORTANCE_EMPTY, "IMPORTANCE_EMPTY"); | |
reason.put(ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE, "REASON_PROVIDER_IN_USE"); | |
reason.put(ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE, "REASON_SERVICE_IN_USE"); | |
reason.put(ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN, "UNKNOWN"); | |
} | |
private void getProcessInfo() { | |
new Timer().schedule(new TimerTask() { | |
@Override | |
public void run() { | |
ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); | |
final List<ActivityManager.RunningAppProcessInfo> apps = manager.getRunningAppProcesses(); | |
for (ActivityManager.RunningAppProcessInfo rapi : apps) { | |
if (rapi.processName.contains(getPackageName())) { | |
Log.d("RunningAppProcessInfo", "processName: " + rapi.processName); | |
Log.d("RunningAppProcessInfo", "importance: " + importance.get(rapi.importance)); | |
Log.d("RunningAppProcessInfo", "importanceResonCode: " + rapi.importanceReasonCode); | |
break; | |
} | |
} | |
} | |
}, 0, 3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment