Search in sources :

Example 36 with RunningAppProcessInfo

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;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager)

Example 37 with RunningAppProcessInfo

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;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) RemoteException(android.os.RemoteException) Fingerprint(android.hardware.fingerprint.Fingerprint)

Example 38 with RunningAppProcessInfo

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;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 39 with RunningAppProcessInfo

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;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Example 40 with RunningAppProcessInfo

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;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Aggregations

RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)61 ActivityManager (android.app.ActivityManager)52 ArrayList (java.util.ArrayList)9 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)8 IOException (java.io.IOException)8 IActivityManager (android.app.IActivityManager)6 Context (android.content.Context)6 Build (android.os.Build)6 RemoteException (android.os.RemoteException)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 Fingerprint (android.hardware.fingerprint.Fingerprint)5 MemoryInfo (android.os.Debug.MemoryInfo)5 SuppressLint (android.annotation.SuppressLint)4 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)4 TestCrashException (com.microsoft.appcenter.crashes.model.TestCrashException)4 Device (com.microsoft.appcenter.ingestion.models.Device)4