Java 类android.app.ActivityManager.ProcessErrorStateInfo 实例源码

项目:ANRMessageCatch    文件:AnrCatchManager.java   
/**
 * 解析ProcessErrorInfo
 * @param paramMap
 */
private String fetchAnrMessage() {
    ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    int count = 0; //10秒中,没有取到CPU使用信息,直接退出;
    while(true) {
        List<ProcessErrorStateInfo> lists = manager.getProcessesInErrorState();
        if (lists != null) {
            for (ProcessErrorStateInfo info : lists) {
                if (info.condition == ProcessErrorStateInfo.NOT_RESPONDING) {
                    messageStore.put("AnrMessage", info.longMsg); //提取Anr进程CPU占用信息
                    return info.shortMsg;
                }
            }
        }
        if (count++ >= 20) {
            break;
        }
        Log.d(TAG, "waiting for process error Info!");
        delayReadMessage(500);
    }
    return null;
}
项目:funf-v4    文件:ProcessStatisticsProbe.java   
@Override
  protected void onStart() {
    ActivityManager am = (ActivityManager)getContext().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
ArrayList<RunningAppProcessInfo> runningProcesses = new ArrayList<RunningAppProcessInfo>(am.getRunningAppProcesses());
final int numProcesses = runningProcesses.size();
int[] runningProcessIds = new int[numProcesses];
for (int i=0; i<numProcesses; i++ ) {
    runningProcessIds[i] = runningProcesses.get(i).pid;
}
List<MemoryInfo> memoryInfos = Arrays.asList(am.getProcessMemoryInfo(runningProcessIds));
List<ProcessErrorStateInfo> errorInfos = am.getProcessesInErrorState();

Gson gson = getGson();
JsonObject data = new JsonObject();
data.add("RUNNING_PROCESS_INFO", gson.toJsonTree(runningProcesses));
data.add("RUNNING_PROCESS_MEMORY_INFO", gson.toJsonTree(memoryInfos));
data.add("ERRORED_PROCESS_INFO", gson.toJsonTree(errorInfos));
data.add("CPU_LOAD", gson.toJsonTree(getCpuLoad()));
data.add("MEM_INFO", gson.toJsonTree(getMemInfo()));
data.add("NET_DEV", gson.toJsonTree(getNetDev()));
sendData(data);
stop();
  }