Search in sources :

Example 1 with RunningAppProcessInfo

use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ParanoidAndroid.

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 2 with RunningAppProcessInfo

use of android.app.ActivityManager.RunningAppProcessInfo in project superCleanMaster by joyoyao.

the class AppUtil method getRunningAppProcesses.

/**
     * 描述:获取运行的进程列表.
     *
     * @param context
     * @return
     */
public static List<AppProcessInfo> getRunningAppProcesses(Context context) {
    ActivityManager activityManager = null;
    List<AppProcessInfo> list = null;
    PackageManager packageManager = null;
    try {
        activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        packageManager = context.getApplicationContext().getPackageManager();
        list = new ArrayList<AppProcessInfo>();
        // 所有运行的进程
        List<RunningAppProcessInfo> appProcessList = activityManager.getRunningAppProcesses();
        ApplicationInfo appInfo = null;
        AppProcessInfo abAppProcessInfo = null;
        PackageInfo packageInfo = getPackageInfo(context);
        if (mProcessList != null) {
            mProcessList.clear();
        }
        mProcessList = getProcessRunningInfo();
        for (RunningAppProcessInfo appProcessInfo : appProcessList) {
            abAppProcessInfo = new AppProcessInfo(appProcessInfo.processName, appProcessInfo.pid, appProcessInfo.uid);
            appInfo = getApplicationInfo(context, appProcessInfo.processName);
            if (appInfo != null) {
                if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    abAppProcessInfo.isSystem = true;
                } else {
                    abAppProcessInfo.isSystem = false;
                }
                Drawable icon = appInfo.loadIcon(packageManager);
                String appName = appInfo.loadLabel(packageManager).toString();
                abAppProcessInfo.icon = icon;
                abAppProcessInfo.appName = appName;
            } else {
                // :服务的命名
                if (appProcessInfo.processName.indexOf(":") != -1) {
                    appInfo = getApplicationInfo(context, appProcessInfo.processName.split(":")[0]);
                    Drawable icon = appInfo.loadIcon(packageManager);
                    abAppProcessInfo.icon = icon;
                }
                abAppProcessInfo.isSystem = true;
                abAppProcessInfo.appName = appProcessInfo.processName;
            }
            /*
                 * AbPsRow psRow = getPsRow(appProcessInfo.processName);
				 * if(psRow!=null){ abAppProcessInfo.memory = psRow.mem; }
				 */
            ProcessInfo processInfo = getMemInfo(appProcessInfo.processName);
            abAppProcessInfo.memory = processInfo.memory;
            abAppProcessInfo.cpu = processInfo.cpu;
            abAppProcessInfo.status = processInfo.status;
            abAppProcessInfo.threadsCount = processInfo.threadsCount;
            list.add(abAppProcessInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) ProcessInfo(com.yzy.supercleanmaster.bean.ProcessInfo) AppProcessInfo(com.yzy.supercleanmaster.bean.AppProcessInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) AppProcessInfo(com.yzy.supercleanmaster.bean.AppProcessInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo)

Example 3 with RunningAppProcessInfo

use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ResurrectionRemix.

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 4 with RunningAppProcessInfo

use of android.app.ActivityManager.RunningAppProcessInfo in project LshUtils by SenhLinsh.

the class AppUtils method gc.

/**
     * 清理后台进程与服务
     *
     * @return 被清理的数量
     */
public static int gc(Context context) {
    long i = getDeviceUsableMemory(context);
    // 清理掉的进程数
    int count = 0;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    // 获取正在运行的service列表
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null) {
        for (RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;
            } catch (Exception e) {
                e.getStackTrace();
            }
        }
    }
    // 获取正在运行的进程列表
    List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null) {
        for (RunningAppProcessInfo process : processList) {
            // 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
            if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                // pkgList 得到该进程下运行的包名
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    if (DEBUG) {
                    }
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        // 防止意外发生
                        e.getStackTrace();
                    }
                }
            }
        }
    }
    if (DEBUG) {
    }
    return count;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 5 with RunningAppProcessInfo

use of android.app.ActivityManager.RunningAppProcessInfo in project DroidPlugin by DroidPluginTeam.

the class PluginProcessManager method getCurrentProcessName.

public static String getCurrentProcessName(Context context) {
    if (context == null)
        return sCurrentProcessName;
    synchronized (sGetCurrentProcessNameLock) {
        if (sCurrentProcessName == null) {
            ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            List<RunningAppProcessInfo> infos = activityManager.getRunningAppProcesses();
            if (infos == null)
                return null;
            for (RunningAppProcessInfo info : infos) {
                if (info.pid == android.os.Process.myPid()) {
                    sCurrentProcessName = info.processName;
                    return sCurrentProcessName;
                }
            }
        }
    }
    return sCurrentProcessName;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager)

Aggregations

RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)60 ActivityManager (android.app.ActivityManager)51 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