use of android.app.ActivityManager.RunningAppProcessInfo in project BetterBatteryStats by asksven.
the class WakeupSourcesLg method parseWakeupSources.
// private static String FILE_PATH = "/sdcard/wakeup_sources.txt";
public static ArrayList<StatElement> parseWakeupSources(Context context) {
Log.i(TAG, "Parsing " + FILE_PATH);
String delimiter = String.valueOf('\t');
delimiter = delimiter + "+";
ArrayList<StatElement> myRet = new ArrayList<StatElement>();
// format
// new [name active_count event_count wakeup_count expire_count active_since total_time max_time last_change prevent_suspend_time]
ArrayList<String[]> rows = parseDelimitedFile(FILE_PATH, delimiter);
long msSinceBoot = SystemClock.elapsedRealtime();
// list the running processes
ActivityManager actvityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
// start with 1
for (int i = 1; i < rows.size(); i++) {
try {
// different mapping from LG G3
// name active_count event_count wakeup_count expire_count pending_count active_since total_time max_time last_change prevent_suspend_time
// times in file are milliseconds
String[] data = (String[]) rows.get(i);
// name
String name = data[0].trim();
// active_count
int count = Integer.valueOf(data[1]);
// expire_count
int expire_count = Integer.valueOf(data[4]);
// wakeup_count
int wake_count = Integer.valueOf(data[3]);
// active_since
long active_since = Long.valueOf(data[6]);
// total_time
long total_time = Long.valueOf(data[7]);
// prevent_suspend_time
long sleep_time = Long.valueOf(data[10]);
// max_time
long max_time = Long.valueOf(data[8]);
// last_change
long last_change = Long.valueOf(data[9]);
// post-processing of eventX-YYYY processes
String details = "";
// we start with a " here as that is the way the data comes from /proc
if (name.startsWith("\"event")) {
String process = name.replaceAll("\"", "");
if (CommonLogSettings.DEBUG) {
Log.d(TAG, "Pattern 'event' found in " + process);
}
int proc = 0;
String[] parts = process.split("-");
if (parts.length == 2) {
try {
proc = Integer.valueOf(parts[1]);
if (CommonLogSettings.DEBUG) {
Log.d(TAG, "Resolving proc name for 'event' " + proc);
}
} catch (Exception e) {
Log.e(TAG, "Cound not split process name " + process);
}
}
if (proc != 0) {
// search for the process in the task list
for (int psCount = 0; psCount < procInfos.size(); psCount++) {
int id = procInfos.get(psCount).pid;
if (id == proc) {
String processName = procInfos.get(psCount).processName;
details = processName;
String appName = "";
String[] pkgList = procInfos.get(count).pkgList;
for (int j = 0; j < pkgList.length; j++) {
if (details.length() > 0) {
details += ", ";
}
details += pkgList[j];
}
if (CommonLogSettings.DEBUG) {
Log.d(TAG, "Pattern 'event' resolved to " + details);
}
}
}
}
}
if (CommonLogSettings.DEBUG) {
Log.d(TAG, "Native Kernel wakelock parsed" + " name=" + name + " details=" + details + " count=" + count + " expire_count=" + expire_count + " wake_count=" + wake_count + " active_since=" + active_since + " total_time=" + total_time + " sleep_time=" + sleep_time + " max_time=" + max_time + "last_change=" + last_change + "ms_since_boot=" + msSinceBoot);
}
NativeKernelWakelock wl = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// on L sleep time is always 0 so use total time instead
wl = new NativeKernelWakelock(name, details, count, expire_count, wake_count, active_since, total_time, total_time, max_time, last_change, msSinceBoot);
} else {
wl = new NativeKernelWakelock(name, details, count, expire_count, wake_count, active_since, total_time, sleep_time, max_time, last_change, msSinceBoot);
}
myRet.add(wl);
} catch (Exception e) {
// go on
}
}
return myRet;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project AnExplorer by 1hakr.
the class AppsProvider method queryChildDocuments.
@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
final MatrixCursor result = new DocumentCursor(resolveDocumentProjection(projection), docId);
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
try {
if (docId.startsWith(ROOT_ID_USER_APP)) {
List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : allAppList) {
includeAppFromPackage(result, docId, packageInfo, false, null);
}
} else if (docId.startsWith(ROOT_ID_SYSTEM_APP)) {
List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : allAppList) {
includeAppFromPackage(result, docId, packageInfo, true, null);
}
} else if (docId.startsWith(ROOT_ID_PROCESS)) {
if (Utils.hasNougat()) {
List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
for (RunningServiceInfo process : runningServices) {
includeAppFromService(result, docId, process, null);
}
} else if (Utils.hasLollipopMR1()) {
List<AndroidAppProcess> runningAppProcesses = AndroidProcesses.getRunningAppProcesses();
for (AndroidAppProcess process : runningAppProcesses) {
includeAppFromProcess(result, docId, process, null);
}
} else {
List<RunningAppProcessInfo> runningProcessesList = activityManager.getRunningAppProcesses();
for (RunningAppProcessInfo processInfo : runningProcessesList) {
includeAppFromProcess(result, docId, processInfo, null);
}
}
}
} finally {
Binder.restoreCallingIdentity(token);
}
return result;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project BlogSource by TeachCourse.
the class MyUtils method getProcessName.
public static String getProcessName(Context cxt, int pid) {
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
if (runningApps == null) {
return null;
}
for (RunningAppProcessInfo procInfo : runningApps) {
if (procInfo.pid == pid) {
return procInfo.processName;
}
}
return null;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project BaseProject by feer921.
the class PackageManagerUtil method getProcessNameByPid.
/**
* 获取进程的名称<br/>
* 通过进程id在运行的栈中查找获取进程名称(包名+进程名)
*
* @param context
* @param pid
* @return
*/
public static String getProcessNameByPid(Context context, final int pid) {
String processName = null;
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses != null) {
for (RunningAppProcessInfo appProcess : appProcesses) {
if (pid == appProcess.pid) {
processName = appProcess.processName;
break;
}
}
}
CommonLog.d(TAG, "getProcessNameByPid,pid=", pid, ",processName=", processName);
return processName;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project MLib by DaoBillTang.
the class SystemUtils method getProcessName.
/**
* 获取当前进程的名称
*
* @param context
* @return
*/
public static String getProcessName(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
if (runningApps != null && runningApps.size() != 0) {
int myPid = android.os.Process.myPid();
for (RunningAppProcessInfo proInfo : runningApps) {
if (proInfo != null && proInfo.pid == myPid) {
return proInfo.processName;
}
}
}
return null;
}
Aggregations