Search in sources :

Example 51 with ActivityManager

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

Example 52 with ActivityManager

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);
    }
}
Also used : IMountService(android.os.storage.IMountService) ApplicationInfo(android.content.pm.ApplicationInfo) ActivityManager(android.app.ActivityManager) RemoteException(android.os.RemoteException)

Example 53 with ActivityManager

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

Example 54 with ActivityManager

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

Example 55 with ActivityManager

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