use of android.app.ActivityManager 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;
}
use of android.app.ActivityManager in project HoloEverywhere by Prototik.
the class ResolverActivity method onCreate.
protected void onCreate(Bundle savedInstanceState, Intent intent, CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList, boolean alwaysUseOption) {
super.onCreate(savedInstanceState);
try {
mLaunchedFromUid = getPackageManager().getApplicationInfo(getPackageName(), 0).uid;
} catch (NameNotFoundException e) {
e.printStackTrace();
mLaunchedFromUid = -1;
}
mPm = getPackageManager();
mAlwaysUseOption = alwaysUseOption;
mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns);
intent.setComponent(null);
AlertController.AlertParams ap = mAlertParams;
ap.mTitle = title;
final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
mIconDpi = getLauncherLargeIconDensity(am);
mIconSize = getLauncherLargeIconSize(am);
mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList, mLaunchedFromUid);
int count = mAdapter.getCount();
if (mLaunchedFromUid < 0 || isIsolated(mLaunchedFromUid)) {
finish();
return;
} else if (count > 1) {
ap.mView = getLayoutInflater().inflate(R.layout.resolver_grid, null);
mGrid = (GridView) ap.mView.findViewById(R.id.resolver_grid);
mGrid.setAdapter(mAdapter);
mGrid.setOnItemClickListener(this);
mGrid.setOnItemLongClickListener(new ItemLongClickListener());
if (alwaysUseOption) {
mGrid.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
resizeGrid();
} else if (count == 1) {
startActivity(mAdapter.intentForPosition(0));
finish();
return;
} else {
ap.mMessage = getResources().getText(R.string.noApplications);
}
setupAlert();
if (alwaysUseOption) {
final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
if (buttonLayout != null) {
buttonLayout.setVisibility(View.VISIBLE);
mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
} else {
mAlwaysUseOption = false;
}
}
}
use of android.app.ActivityManager in project StickerCamera by Skykai521.
the class PackageUtils method isTopActivity.
/**
* whether the app whost package's name is packageName is on the top of the stack
* <ul>
* <strong>Attentions:</strong>
* <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
* </ul>
*
* @param context
* @param packageName
* @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
* stack
*/
public static Boolean isTopActivity(Context context, String packageName) {
if (context == null || StringUtils.isEmpty(packageName)) {
return null;
}
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
if (ListUtils.isEmpty(tasksInfo)) {
return null;
}
try {
return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of android.app.ActivityManager in project StickerCamera by Skykai521.
the class AppUtils method isNamedProcess.
/**
* whether this process is named with processName
*
* @param context
* @param processName
* @return <ul>
* return whether this process is named with processName
* <li>if context is null, return false</li>
* <li>if {@link ActivityManager#getRunningAppProcesses()} is null, return false</li>
* <li>if one process of {@link ActivityManager#getRunningAppProcesses()} is equal to processName, return
* true, otherwise return false</li>
* </ul>
*/
public static boolean isNamedProcess(Context context, String processName) {
if (context == null) {
return false;
}
int pid = android.os.Process.myPid();
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
if (ListUtils.isEmpty(processInfoList)) {
return false;
}
for (RunningAppProcessInfo processInfo : processInfoList) {
if (processInfo != null && processInfo.pid == pid && ObjectUtils.isEquals(processName, processInfo.processName)) {
return true;
}
}
return false;
}
use of android.app.ActivityManager in project StickerCamera by Skykai521.
the class AppUtils method isApplicationInBackground.
/**
* whether application is in background
* <ul>
* <li>need use permission android.permission.GET_TASKS in Manifest.xml</li>
* </ul>
*
* @param context
* @return if application is in background return true, otherwise return false
*/
public static boolean isApplicationInBackground(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> taskList = am.getRunningTasks(1);
if (taskList != null && !taskList.isEmpty()) {
ComponentName topActivity = taskList.get(0).topActivity;
if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
Aggregations