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