Java Code Examples for android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_SERVICE

The following examples show how to use android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_SERVICE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Application.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
/**
 * Get highest priority process for the package.
 *
 * @param context
 * @param packageName
 * @return
 */
public static String getAppPriority(Context context, String packageName) {
    List<RunningAppProcessInfo> processInfos = Process.getRunningProcessInfo(context);
    List<RunningServiceInfo> serviceInfos = Service.getRunningServiceInfo(context);
    int highestPriority = Integer.MAX_VALUE;

    // Check if there are running services for the package
    for (RunningServiceInfo si : serviceInfos) {
        if (si.service.getPackageName().equals(packageName)) {
            highestPriority = RunningAppProcessInfo.IMPORTANCE_SERVICE;
        }

    }
    // Check if there are running processes for the package
    for (RunningAppProcessInfo pi : processInfos) {
        if (Arrays.asList(pi.pkgList).contains(packageName)) {
            if (pi.importance < highestPriority) {
                highestPriority = pi.importance;
            }
        }
    }

    return StringHelper.translatedPriority(
            context,
            StringHelper.importanceString(highestPriority)
    );
}
 
Example 2
Source File: ProcessFragment.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
private void bind(final int position) {
	final ProcessInfo pi = lpinfo.get(position);

	cbx.setTag(pi);
	more.setTag(pi);

	name.setText(pi.label);
	attr.setText(pi.packageName);
	items.setText(Util.nf.format(pi.size) + " B");

	int importance = pi.status;
	if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
		type.setText("Foreground");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE) {
		type.setText("Foreground Service");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
		type.setText("Background");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
		type.setText("Visible");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) {
		type.setText("Perceptible");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) {
		type.setText("Service");
	} else if (importance == 150) {//}RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING) {
		type.setText("Sleep");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_GONE) {
		type.setText("Gone");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) {
		type.setText("Can't save state");
	} else if (importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) {
		type.setText("Empty");
	}

	try {
		image.setImageDrawable(pk.getApplicationIcon(pi.packageName));
	} catch (NameNotFoundException e) {
		image.setImageResource(R.drawable.ic_doc_apk);
	}

	final boolean checked = selectedInList1.contains(pi.packageName);
	if (checked) {
		ll.setBackgroundColor(Constants.IN_DATA_SOURCE_2);
		cbx.setSelected(true);
		cbx.setImageResource(R.drawable.ic_accept);
	} else if (selectedInList1.size() > 0) {
		ll.setBackgroundColor(Constants.BASE_BACKGROUND);
		cbx.setSelected(false);
		cbx.setImageResource(R.drawable.ready);
	} else {
		ll.setBackgroundResource(R.drawable.ripple);
		cbx.setSelected(false);
		cbx.setImageResource(R.drawable.dot);
	}
}
 
Example 3
Source File: MyActivityManagerService.java    From DroidPlugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void runProcessGC() {
    if (mHostContext == null) {
        return;
    }
    ActivityManager am = (ActivityManager) mHostContext.getSystemService(Context.ACTIVITY_SERVICE);
    if (am == null) {
        return;
    }

    List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
    List<RunningAppProcessInfo> myInfos = new ArrayList<RunningAppProcessInfo>();
    if (infos == null || infos.size() < 0) {
        return;
    }

    List<String> pns = mStaticProcessList.getOtherProcessNames();
    pns.add(mHostContext.getPackageName());
    for (RunningAppProcessInfo info : infos) {
        if (info.uid == android.os.Process.myUid()
                && info.pid != android.os.Process.myPid()
                && !pns.contains(info.processName)
                && mRunningProcessList.isPlugin(info.pid)
                && !mRunningProcessList.isPersistentApplication(info.pid)
                /*&& !mRunningProcessList.isPersistentApplication(info.pid)*/) {
            myInfos.add(info);
        }
    }
    Collections.sort(myInfos, sProcessComparator);
    for (RunningAppProcessInfo myInfo : myInfos) {
        if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_GONE) {
            doGc(myInfo);
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) {
            doGc(myInfo);
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
            doGc(myInfo);
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) {
            doGc(myInfo);
        } /*else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) {
            //杀死进程,不能保存状态。但是关我什么事?
        }*/ else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) {
            //杀死进程
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
            //看得见
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            //前台进程。
        }
    }

}