From 96d8d44bcd88b8d4fa3243dd59ad9208bb7b1dce Mon Sep 17 00:00:00 2001 From: andy <66240551+flandolf@users.noreply.github.com> Date: Thu, 6 Mar 2025 04:01:32 +1100 Subject: [PATCH] Settings: Improve RAM summary for devices >12GB of RAM * settings: Improve RAM summary formatting to show one decimal place * settings: Update RAM formatting to use gigabytes with no decimal places + base 10 units for closer accuracy to advertised RAM sizes --- .../TotalRAMPreferenceController.java | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java index f06fef5bd50..e1c55ff7e90 100644 --- a/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java +++ b/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java @@ -49,31 +49,16 @@ public class TotalRAMPreferenceController extends BasePreferenceController { @Override public CharSequence getSummary() { - ActivityManager actManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); - ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); - actManager.getMemoryInfo(memInfo); + ActivityManager actManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); + ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); + actManager.getMemoryInfo(memInfo); - long totRam = memInfo.totalMem; - double gb = (double) totRam / 1073741824.0; - - String aproxRam; - if (gb > 0 && gb <= 2) { - aproxRam = "2"; - } else if (gb <= 3) { - aproxRam = "3"; - } else if (gb <= 4) { - aproxRam = "4"; - } else if (gb <= 6) { - aproxRam = "6"; - } else if (gb <= 8) { - aproxRam = "8"; - } else if (gb <= 12) { - aproxRam = "12"; - } else { - aproxRam = "12+"; + long totRam = memInfo.totalMem; + double gb = (double) totRam / 1000000000.0; + + DecimalFormat df = new DecimalFormat("#"); + String formattedRam = df.format(gb); + + return formattedRam + " GB"; } - - String actualRam = aproxRam.concat(" GB"); - return actualRam; - } }