Search in sources :

Example 1 with CancellablePreference

use of com.android.settings.CancellablePreference 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)

Example 2 with CancellablePreference

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

the class ProcessStatsDetail method fillServicesSection.

private void fillServicesSection(ProcStatsEntry entry, PreferenceCategory processPref) {
    final HashMap<String, PkgService> pkgServices = new HashMap<>();
    final ArrayList<PkgService> pkgList = new ArrayList<>();
    for (int ip = 0; ip < entry.mServices.size(); ip++) {
        String pkg = entry.mServices.keyAt(ip);
        PkgService psvc = null;
        ArrayList<ProcStatsEntry.Service> services = entry.mServices.valueAt(ip);
        for (int is = services.size() - 1; is >= 0; is--) {
            ProcStatsEntry.Service pent = services.get(is);
            if (pent.mDuration >= mOnePercentTime) {
                if (psvc == null) {
                    psvc = pkgServices.get(pkg);
                    if (psvc == null) {
                        psvc = new PkgService();
                        pkgServices.put(pkg, psvc);
                        pkgList.add(psvc);
                    }
                }
                psvc.mServices.add(pent);
                psvc.mDuration += pent.mDuration;
            }
        }
    }
    Collections.sort(pkgList, sServicePkgCompare);
    for (int ip = 0; ip < pkgList.size(); ip++) {
        ArrayList<ProcStatsEntry.Service> services = pkgList.get(ip).mServices;
        Collections.sort(services, sServiceCompare);
        for (int is = 0; is < services.size(); is++) {
            final ProcStatsEntry.Service service = services.get(is);
            CharSequence label = getLabel(service);
            CancellablePreference servicePref = new CancellablePreference(getPrefContext());
            servicePref.setSelectable(false);
            servicePref.setTitle(label);
            servicePref.setSummary(ProcStatsPackageEntry.getFrequency(service.mDuration / (float) mTotalTime, getActivity()));
            processPref.addPreference(servicePref);
            mServiceMap.put(new ComponentName(service.mPackage, service.mName), servicePref);
        }
    }
}
Also used : CancellablePreference(com.android.settings.CancellablePreference) HashMap(java.util.HashMap) Service(com.android.settings.applications.ProcStatsEntry.Service) ArrayList(java.util.ArrayList) Service(com.android.settings.applications.ProcStatsEntry.Service) ComponentName(android.content.ComponentName)

Aggregations

ComponentName (android.content.ComponentName)2 CancellablePreference (com.android.settings.CancellablePreference)2 ActivityManager (android.app.ActivityManager)1 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)1 OnCancelListener (com.android.settings.CancellablePreference.OnCancelListener)1 Service (com.android.settings.applications.ProcStatsEntry.Service)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1