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);
}
}
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);
}
}
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();
}
}
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);
}
}
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");
}
Aggregations