Search in sources :

Example 31 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class BaseStatusBar method getLastApp.

private void getLastApp() {
    int lastAppId = 0;
    int looper = 1;
    String packageName;
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    final ActivityManager am = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE);
    String defaultHomePackage = "com.android.launcher";
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = mContext.getPackageManager().resolveActivity(intent, 0);
    if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
        defaultHomePackage = res.activityInfo.packageName;
    }
    List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);
    // Note, we'll only get as many as the system currently has - up to 5
    while ((lastAppId == 0) && (looper < tasks.size())) {
        packageName = tasks.get(looper).topActivity.getPackageName();
        if (!packageName.equals(defaultHomePackage) && !packageName.equals("com.android.systemui")) {
            lastAppId = tasks.get(looper).id;
        }
        looper++;
    }
    if (lastAppId != 0) {
        am.moveTaskToFront(lastAppId, am.MOVE_TASK_NO_USER_ACTION);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager)

Example 32 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class PackageInstallerService method updateSessionAppIcon.

@Override
public void updateSessionAppIcon(int sessionId, Bitmap appIcon) {
    synchronized (mSessions) {
        final PackageInstallerSession session = mSessions.get(sessionId);
        if (session == null || !isCallingUidOwner(session)) {
            throw new SecurityException("Caller has no access to session " + sessionId);
        }
        // Defensively resize giant app icons
        if (appIcon != null) {
            final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
            final int iconSize = am.getLauncherLargeIconSize();
            if ((appIcon.getWidth() > iconSize * 2) || (appIcon.getHeight() > iconSize * 2)) {
                appIcon = Bitmap.createScaledBitmap(appIcon, iconSize, iconSize, true);
            }
        }
        session.params.appIcon = appIcon;
        session.params.appIconLastModified = -1;
        mInternalCallback.onSessionBadgingChanged(session);
    }
}
Also used : IPackageInstallerSession(android.content.pm.IPackageInstallerSession) ActivityManager(android.app.ActivityManager)

Example 33 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class RecentController method openLastApptoBottom.

public void openLastApptoBottom() {
    int taskid = 0;
    boolean doWeHaveAtask = true;
    final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.RunningTaskInfo lastTask = getLastTask(am);
    if (lastTask != null) {
        //user already ran another app in this session, we can dock it to the other side
        taskid = lastTask.id;
    } else {
        //no last app for this session, let's search in the previous session recent apps
        List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasksForUser(ActivityManager.getMaxRecentTasksStatic(), ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS | ActivityManager.RECENT_INGORE_DOCKED_STACK_TOP_TASK | ActivityManager.RECENT_INGORE_PINNED_STACK_TASKS | ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_PROFILES, UserHandle.CURRENT.getIdentifier());
        if (recentTasks != null && recentTasks.size() > 1) {
            ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(1);
            taskid = recentInfo.persistentId;
        } else {
            //user cleared all apps, we don't have any taskid to choose
            doWeHaveAtask = false;
        }
    }
    if (doWeHaveAtask) {
        try {
            ActivityOptions options = ActivityOptions.makeBasic();
            ActivityManagerNative.getDefault().startActivityFromRecents(taskid, options.toBundle());
        } catch (RemoteException e) {
        }
    } else {
        Toast noLastapp = Toast.makeText(mContext, R.string.recents_multiwin_nolastapp, Toast.LENGTH_LONG);
        noLastapp.show();
    }
}
Also used : Toast(android.widget.Toast) ActivityManager(android.app.ActivityManager) RemoteException(android.os.RemoteException) Point(android.graphics.Point) ActivityOptions(android.app.ActivityOptions)

Example 34 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class AppLaunch method reportError.

private void reportError(String appName, String processName) {
    ActivityManager am = (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ProcessErrorStateInfo> crashes = am.getProcessesInErrorState();
    if (crashes != null) {
        for (ProcessErrorStateInfo crash : crashes) {
            if (!crash.processName.equals(processName))
                continue;
            Log.w(TAG, appName + " crashed: " + crash.shortMsg);
            mResult.putString(mNameToResultKey.get(appName), crash.shortMsg);
            return;
        }
    }
    mResult.putString(mNameToResultKey.get(appName), "Crashed for unknown reason");
    Log.w(TAG, appName + " not found in process list, most likely it is crashed");
}
Also used : ProcessErrorStateInfo(android.app.ActivityManager.ProcessErrorStateInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Example 35 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ActivityTestMain method findDocTask.

ActivityManager.AppTask findDocTask() {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> tasks = am.getAppTasks();
    if (tasks != null) {
        for (int i = 0; i < tasks.size(); i++) {
            ActivityManager.AppTask task = tasks.get(i);
            ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
            if (recent.baseIntent != null && recent.baseIntent.getComponent().getClassName().equals(DocActivity.class.getCanonicalName())) {
                return task;
            }
        }
    }
    return null;
}
Also used : ActivityManager(android.app.ActivityManager)

Aggregations

ActivityManager (android.app.ActivityManager)612 Intent (android.content.Intent)61 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)55 PackageManager (android.content.pm.PackageManager)50 Context (android.content.Context)47 ComponentName (android.content.ComponentName)44 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)36 ArrayList (java.util.ArrayList)31 View (android.view.View)29 IOException (java.io.IOException)29 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)27 SuppressLint (android.annotation.SuppressLint)26 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)25 IActivityManager (android.app.IActivityManager)19 Point (android.graphics.Point)19 RemoteException (android.os.RemoteException)19 MemoryInfo (android.app.ActivityManager.MemoryInfo)18 Bitmap (android.graphics.Bitmap)18 AdapterView (android.widget.AdapterView)18