Android Open Source - Emmagee Process Info






From Project

Back to project page Emmagee.

License

The source code is released under:

Apache License

If you think the Android project Emmagee listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2012-2013 NetEase, Inc. and other contributors
 */*w w w  . j a v  a2 s .c  o  m*/
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package com.netease.qa.emmagee.utils;

import java.util.ArrayList;
import java.util.List;

import com.netease.qa.emmagee.activity.MainPageActivity;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;

public class ProcessInfo {

  private final String LOG_TAG = "Emmagee-"
      + ProcessInfo.class.getSimpleName();

  private final String PACKAGE_NAME = "com.netease.qa.emmagee";

  /**
   * get information of all running processes,including package name ,process
   * name ,icon ,pid and uid
   * 
   * @param context
   *            context of activity
   * @return running processes list
   */
  public List<Programe> getRunningProcess(Context context) {
    Log.i(LOG_TAG, "get running processes");

    ActivityManager am = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> run = am.getRunningAppProcesses();
    PackageManager pm = context.getPackageManager();
    List<Programe> progressList = new ArrayList<Programe>();
    boolean launchTag;

    for (ApplicationInfo appinfo : getPackagesInfo(context)) {
      launchTag = false;
      Programe programe = new Programe();
      if (((appinfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0)
          || ((appinfo.processName != null) && (appinfo.processName
              .equals(PACKAGE_NAME)))) {
        continue;
      }
      for (RunningAppProcessInfo runningProcess : run) {
        if ((runningProcess.processName != null)
            && runningProcess.processName
                .equals(appinfo.processName)) {
          launchTag = true;
          programe.setPid(runningProcess.pid);
          programe.setUid(runningProcess.uid);
          break;
        }
      }
      programe.setPackageName(appinfo.processName);
      programe.setProcessName(appinfo.loadLabel(pm).toString());
      if (launchTag == true) {
        programe.setIcon(appinfo.loadIcon(pm));
      }
      progressList.add(programe);
    }
    return progressList;
  }

  /**
   * get information of all applications
   * 
   * @param context
   *            context of activity
   * @return packages information of all applications
   */
  private List<ApplicationInfo> getPackagesInfo(Context context) {
    PackageManager pm = context.getApplicationContext().getPackageManager();
    List<ApplicationInfo> appList = pm
        .getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
    return appList;
  }
}




Java Source Code List

com.netease.qa.emmagee.activity.MainPageActivity.java
com.netease.qa.emmagee.activity.SettingsActivity.java
com.netease.qa.emmagee.service.EmmageeService.java
com.netease.qa.emmagee.utils.CpuInfo.java
com.netease.qa.emmagee.utils.MemoryInfo.java
com.netease.qa.emmagee.utils.MyApplication.java
com.netease.qa.emmagee.utils.ProcessInfo.java
com.netease.qa.emmagee.utils.Programe.java
com.netease.qa.emmagee.utils.TrafficInfo.java