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