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;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by AOSPA.
the class FingerprintService method isForegroundActivity.
private boolean isForegroundActivity(int uid, int pid) {
try {
List<RunningAppProcessInfo> procs = ActivityManagerNative.getDefault().getRunningAppProcesses();
int N = procs.size();
for (int i = 0; i < N; i++) {
RunningAppProcessInfo proc = procs.get(i);
if (proc.pid == pid && proc.uid == uid && proc.importance == IMPORTANCE_FOREGROUND) {
return true;
}
}
} catch (RemoteException e) {
Slog.w(TAG, "am.getRunningAppProcesses() failed");
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ResurrectionRemix.
the class DevUtils method killForegroundApplication.
/**
* Kills the top most / most recent user application, but leaves out the launcher.
* This is function governed by {@link Settings.Secure.KILL_APP_LONGPRESS_BACK}.
*
* @param context the current context, used to retrieve the package manager.
* @return {@code true} when a user application was found and closed.
*/
public static boolean killForegroundApplication(Context context) {
boolean targetKilled = false;
try {
final Intent intent = new Intent(Intent.ACTION_MAIN);
String defaultHomePackage = "com.android.launcher";
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
defaultHomePackage = res.activityInfo.packageName;
}
IActivityManager am = ActivityManagerNative.getDefault();
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo appInfo : apps) {
int uid = appInfo.uid;
// root, phone, etc.)
if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID && appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (appInfo.pkgList != null && (appInfo.pkgList.length > 0)) {
for (String pkg : appInfo.pkgList) {
if (!pkg.equals("com.android.systemui") && !pkg.equals(defaultHomePackage)) {
am.forceStopPackage(pkg, UserHandle.USER_CURRENT);
targetKilled = true;
break;
}
}
} else {
Process.killProcess(appInfo.pid);
targetKilled = true;
break;
}
}
}
} catch (RemoteException remoteException) {
// Do nothing; just let it go.
}
return targetKilled;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ResurrectionRemix.
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 platform_frameworks_base by android.
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;
}
Aggregations