Search in sources :

Example 6 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 7 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 8 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 9 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 10 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)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