From 020999103b34860a89576cd5dba862009337e9a9 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 9 Oct 2013 12:06:59 -0700 Subject: [PATCH] Fix issue #11033002: Percentages in proc stats details are not rounded correctly Use round instead of ceil. Also, when showing services from multiple packages, sort the package categories by the duration of the longest running service in each, so that the more important ones come first. Change-Id: I42b47b0522cd786a1c4ee5b59a549ec7c0c6ffe1 --- .../applications/ProcessStatsDetail.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/applications/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java index a1885a74843..94dc5522930 100644 --- a/src/com/android/settings/applications/ProcessStatsDetail.java +++ b/src/com/android/settings/applications/ProcessStatsDetail.java @@ -74,7 +74,7 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen public static String makePercentString(Resources res, long amount, long total) { final double percent = (((double)amount) / total) * 100; - return res.getString(R.string.percentage, (int) Math.ceil(percent)); + return res.getString(R.string.percentage, (int) Math.round(percent)); } @Override @@ -220,17 +220,42 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen } }; + final static Comparator> sServicePkgCompare + = new Comparator>() { + @Override + public int compare(ArrayList lhs, + ArrayList rhs) { + long topLhs = lhs.size() > 0 ? lhs.get(0).mDuration : 0; + long topRhs = rhs.size() > 0 ? rhs.get(0).mDuration : 0; + if (topLhs < topRhs) { + return 1; + } else if (topLhs > topRhs) { + return -1; + } + return 0; + } + }; + private void fillServicesSection() { if (mEntry.mServices.size() > 0) { boolean addPackageSections = false; - if (mEntry.mServices.size() > 1 - || !mEntry.mServices.valueAt(0).get(0).mPackage.equals(mEntry.mPackage)) { - addPackageSections = true; - } + // Sort it all. + ArrayList> servicePkgs + = new ArrayList>(); for (int ip=0; ip services = (ArrayList)mEntry.mServices.valueAt(ip).clone(); Collections.sort(services, sServiceCompare); + servicePkgs.add(services); + } + if (mEntry.mServices.size() > 1 + || !mEntry.mServices.valueAt(0).get(0).mPackage.equals(mEntry.mPackage)) { + addPackageSections = true; + // Sort these so that the one(s) with the longest run durations are on top. + Collections.sort(servicePkgs, sServicePkgCompare); + } + for (int ip=0; ip services = servicePkgs.get(ip); if (addPackageSections) { addPackageHeaderItem(mServicesParent, services.get(0).mPackage); }