use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ParanoidAndroid.
the class AppCompatibility method processStillUp.
/**
* Determine if a given package is still running.
*
* @param packageName {@link String} package to look for
* @return True if package is running, false otherwise.
*/
private boolean processStillUp(String packageName) {
try {
PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, 0);
String processName = packageInfo.applicationInfo.processName;
List<RunningAppProcessInfo> runningApps = mActivityManager.getRunningAppProcesses();
for (RunningAppProcessInfo app : runningApps) {
if (app.processName.equalsIgnoreCase(processName)) {
Log.d(TAG, "Found process " + app.processName);
return true;
}
}
Log.d(TAG, "Failed to find process " + processName + " with package name " + packageName);
} catch (NameNotFoundException e) {
Log.w(TAG, "Failed to find package " + packageName);
return false;
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project DroidPlugin by DroidPluginTeam.
the class MyCrashHandler method getProcessName.
public String getProcessName() {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
for (RunningAppProcessInfo info : infos) {
if (info.pid == android.os.Process.myPid()) {
return info.processName;
}
}
return null;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project DroidPlugin by DroidPluginTeam.
the class MyActivityManagerService method runProcessGC.
//运行进程GC
private void runProcessGC() {
if (mHostContext == null) {
return;
}
ActivityManager am = (ActivityManager) mHostContext.getSystemService(Context.ACTIVITY_SERVICE);
if (am == null) {
return;
}
List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
List<RunningAppProcessInfo> myInfos = new ArrayList<RunningAppProcessInfo>();
if (infos == null || infos.size() < 0) {
return;
}
List<String> pns = mStaticProcessList.getOtherProcessNames();
pns.add(mHostContext.getPackageName());
for (RunningAppProcessInfo info : infos) {
if (info.uid == android.os.Process.myUid() && info.pid != android.os.Process.myPid() && !pns.contains(info.processName) && mRunningProcessList.isPlugin(info.pid) && !mRunningProcessList.isPersistentApplication(info.pid)) /*&& !mRunningProcessList.isPersistentApplication(info.pid)*/
{
myInfos.add(info);
}
}
Collections.sort(myInfos, sProcessComparator);
for (RunningAppProcessInfo myInfo : myInfos) {
if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_GONE) {
doGc(myInfo);
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) {
doGc(myInfo);
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
doGc(myInfo);
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) {
doGc(myInfo);
} else /*else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) {
//杀死进程,不能保存状态。但是关我什么事?
}*/
if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) {
//杀死进程
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
//看得见
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
//前台进程。
}
}
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by DirtyUnicorns.
the class MemoryUsageTest method getPss.
private int getPss(String processName) {
ActivityManager am = (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo proc : apps) {
if (!proc.processName.equals(processName)) {
continue;
}
int[] pids = { proc.pid };
MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
return meminfo.getTotalPss();
}
return -1;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project react-native-push-notification by zo0r.
the class RNPushNotificationListenerService method isApplicationInForeground.
private boolean isApplicationInForeground() {
ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
if (processInfos != null) {
for (RunningAppProcessInfo processInfo : processInfos) {
if (processInfo.processName.equals(getApplication().getPackageName())) {
if (processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String d : processInfo.pkgList) {
return true;
}
}
}
}
}
return false;
}
Aggregations