Search in sources :

Example 56 with ActivityManager

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;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Example 57 with ActivityManager

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;
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ViewGroup(android.view.ViewGroup) GridView(org.holoeverywhere.widget.GridView) ActivityManager(android.app.ActivityManager) AlertController(org.holoeverywhere.widget.AlertController)

Example 58 with ActivityManager

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;
    }
}
Also used : ActivityManager(android.app.ActivityManager) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 59 with ActivityManager

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;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager)

Example 60 with ActivityManager

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;
}
Also used : ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo)

Aggregations

ActivityManager (android.app.ActivityManager)339 Intent (android.content.Intent)44 Context (android.content.Context)33 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)30 ComponentName (android.content.ComponentName)26 PackageManager (android.content.pm.PackageManager)23 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)18 IActivityManager (android.app.IActivityManager)16 ConfigurationInfo (android.content.pm.ConfigurationInfo)16 IOException (java.io.IOException)16 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)15 View (android.view.View)15 ImageView (android.widget.ImageView)15 ArrayList (java.util.ArrayList)15 Point (android.graphics.Point)14 TextView (android.widget.TextView)14 RunningTaskInfo (android.app.ActivityManager.RunningTaskInfo)13 ResolveInfo (android.content.pm.ResolveInfo)12 RemoteException (android.os.RemoteException)12 TargetApi (android.annotation.TargetApi)11