use of android.app.ActivityManager in project atlas by alibaba.
the class WrapperUtil method killChildProcesses.
public static void killChildProcesses(Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> a = am.getRunningAppProcesses();
for (int i = 0; i < a.size(); i++) {
ActivityManager.RunningAppProcessInfo b = a.get(i);
if (b.processName.contains(context.getPackageName() + ":")) {
android.os.Process.killProcess(b.pid);
continue;
}
}
} catch (Exception e) {
}
}
use of android.app.ActivityManager in project android_frameworks_base by ParanoidAndroid.
the class UsbStorageActivity method checkStorageUsersAsync.
private void checkStorageUsersAsync() {
IMountService ims = getMountService();
if (ims == null) {
// Display error dialog
scheduleShowDialog(DLG_ERROR_SHARING);
}
String extStoragePath = Environment.getExternalStorageDirectory().toString();
boolean showDialog = false;
try {
int[] stUsers = ims.getStorageUsers(extStoragePath);
if (stUsers != null && stUsers.length > 0) {
showDialog = true;
} else {
// List of applications on sdcard.
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ApplicationInfo> infoList = am.getRunningExternalApplications();
if (infoList != null && infoList.size() > 0) {
showDialog = true;
}
}
} catch (RemoteException e) {
// Display error dialog
scheduleShowDialog(DLG_ERROR_SHARING);
}
if (showDialog) {
// Display dialog to user
scheduleShowDialog(DLG_CONFIRM_KILL_STORAGE_USERS);
} else {
if (localLOGV)
Log.i(TAG, "Enabling UMS");
switchUsbMassStorage(true);
}
}
use of android.app.ActivityManager in project android_frameworks_base by ParanoidAndroid.
the class RecentApplicationsDialog method switchTo.
private void switchTo(RecentTag tag) {
if (tag.info.id >= 0) {
// This is an active task; it should just go to the foreground.
final ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
am.moveTaskToFront(tag.info.id, ActivityManager.MOVE_TASK_WITH_HOME);
} else if (tag.intent != null) {
tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
try {
getContext().startActivity(tag.intent);
} catch (ActivityNotFoundException e) {
Log.w("Recent", "Unable to launch recent task", e);
}
}
}
use of android.app.ActivityManager in project android_frameworks_base by ParanoidAndroid.
the class AppsLaunchFailureReceiver method onReceive.
// This function implements the following logic.
// If after a theme was applied the number of application launch failures
// at any moment was equal to FAILURES_THRESHOLD
// in less than EXPIRATION_TIME_IN_MILLISECONDS
// the default theme is applied unconditionally.
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_APP_LAUNCH_FAILURE)) {
long currentTime = SystemClock.uptimeMillis();
if (currentTime - mStartTime > EXPIRATION_TIME_IN_MILLISECONDS) {
// reset both the count and the timer
mStartTime = currentTime;
mFailuresCount = 0;
}
if (mFailuresCount <= FAILURES_THRESHOLD) {
mFailuresCount++;
if (mFailuresCount == FAILURES_THRESHOLD) {
CustomTheme defaultTheme = CustomTheme.getSystemTheme();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
Configuration currentConfig = am.getConfiguration();
currentConfig.customTheme = new CustomTheme(defaultTheme.getThemeId(), defaultTheme.getThemePackageName());
am.updateConfiguration(currentConfig);
}
}
} else if (action.equals(Intent.ACTION_APP_LAUNCH_FAILURE_RESET)) {
mFailuresCount = 0;
mStartTime = SystemClock.uptimeMillis();
} else if (action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
mFailuresCount = 0;
mStartTime = SystemClock.uptimeMillis();
}
}
use of android.app.ActivityManager in project android_frameworks_base by ParanoidAndroid.
the class MemoryUsageTest method reportError.
private void reportError(String appName, String processName, Bundle results) {
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);
results.putString(mNameToResultKey.get(appName), crash.shortMsg);
return;
}
}
results.putString(mNameToResultKey.get(appName), "Crashed for unknown reason");
Log.w(TAG, appName + " not found in process list, most likely it is crashed");
}
Aggregations