Search in sources :

Example 1 with OnCancelListener

use of com.android.settings.CancellablePreference.OnCancelListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProcessStatsDetail method updateRunningServices.

private void updateRunningServices() {
    ActivityManager activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
    // Set all services as not running, then turn back on the ones we find.
    int N = mServiceMap.size();
    for (int i = 0; i < N; i++) {
        mServiceMap.valueAt(i).setCancellable(false);
    }
    N = runningServices.size();
    for (int i = 0; i < N; i++) {
        RunningServiceInfo runningService = runningServices.get(i);
        if (!runningService.started && runningService.clientLabel == 0) {
            continue;
        }
        if ((runningService.flags & RunningServiceInfo.FLAG_PERSISTENT_PROCESS) != 0) {
            continue;
        }
        final ComponentName service = runningService.service;
        CancellablePreference pref = mServiceMap.get(service);
        if (pref != null) {
            pref.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(CancellablePreference preference) {
                    stopService(service.getPackageName(), service.getClassName());
                }
            });
            pref.setCancellable(true);
        }
    }
}
Also used : CancellablePreference(com.android.settings.CancellablePreference) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager) OnCancelListener(com.android.settings.CancellablePreference.OnCancelListener)

Aggregations

ActivityManager (android.app.ActivityManager)1 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)1 ComponentName (android.content.ComponentName)1 CancellablePreference (com.android.settings.CancellablePreference)1 OnCancelListener (com.android.settings.CancellablePreference.OnCancelListener)1