Search in sources :

Example 86 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 87 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 88 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 89 with ActivityManager

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

the class AppStorageSettings method initiateClearUserData.

/*
     * Private method to initiate clearing user data when the user clicks the clear data
     * button for a system package
     */
private void initiateClearUserData() {
    mClearDataButton.setEnabled(false);
    // Invoke uninstall or clear user data based on sysPackage
    String packageName = mAppEntry.info.packageName;
    Log.i(TAG, "Clearing user data for package : " + packageName);
    if (mClearDataObserver == null) {
        mClearDataObserver = new ClearUserDataObserver();
    }
    ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    boolean res = am.clearApplicationUserData(packageName, mClearDataObserver);
    if (!res) {
        // Clearing data failed for some obscure reason. Just log error for now
        Log.i(TAG, "Couldnt clear application user data for package:" + packageName);
        showDialogInner(DLG_CANNOT_CLEAR_DATA, 0);
    } else {
        mClearDataButton.setText(R.string.recompute_size);
    }
}
Also used : ActivityManager(android.app.ActivityManager)

Example 90 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)

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