Settings: Add platform and RAM to Model & Hardware

This seems kinda empty... Fill it with fun stuff

Change-Id: Ia43cb31b7567bed07f2b8a1d8637de4e66320c90
[jaysonedson@gmail.com: Move to new HardwareInfo]
Signed-off-by: Jason Edson <jaysonedson@gmail.com>
diff --git a/res/values/leaf_strings.xml b/res/values/leaf_strings.xml
index d64b40d..0cd6a6e 100644
--- a/res/values/leaf_strings.xml
+++ b/res/values/leaf_strings.xml
@@ -61,4 +61,8 @@
     <!-- Annoying Notifications -->
     <string name="notification_sound_vib_screen_on_title">Annoying Notifications</string>
     <string name="notification_sound_vib_screen_on_summary">Play sound and vibration for notifications when screen is on</string>
+
+    <!-- Hardware info -->
+    <string name="platform_revision">Platform</string>
+    <string name="total_ram">Total RAM</string>
 </resources>
diff --git a/res/xml/hardware_info.xml b/res/xml/hardware_info.xml
index e086a48..055a62c 100644
--- a/res/xml/hardware_info.xml
+++ b/res/xml/hardware_info.xml
@@ -30,6 +30,24 @@
         settings:controller="com.android.settings.deviceinfo.hardwareinfo.DeviceModelPreferenceController"
         settings:enableCopying="true"/>
 
+    <!-- Platform -->
+    <Preference
+        android:key="hardware_info_platform"
+        android:title="@string/platform_revision"
+        android:summary="@string/summary_placeholder"
+        android:selectable="false"
+        settings:controller="com.android.settings.deviceinfo.hardwareinfo.PlatformRevisionPreferenceController"
+        settings:enableCopying="true"/>
+
+    <!-- Total RAM -->
+    <Preference
+        android:key="hardware_info_ram"
+        android:title="@string/total_ram"
+        android:summary="@string/summary_placeholder"
+        android:selectable="false"
+        settings:controller="com.android.settings.deviceinfo.hardwareinfo.TotalRAMPreferenceController"
+        settings:enableCopying="true"/>
+
     <!-- SerialNumber -->
     <Preference
         android:key="hardware_info_device_serial"
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/PlatformRevisionPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/PlatformRevisionPreferenceController.java
new file mode 100644
index 0000000..beac9f8
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/PlatformRevisionPreferenceController.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo.hardwareinfo;
+
+import android.content.Context;
+import android.os.SystemProperties;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.slices.Sliceable;
+
+public class PlatformRevisionPreferenceController extends BasePreferenceController {
+
+    public PlatformRevisionPreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return mContext.getResources().getBoolean(R.bool.config_show_device_model)
+                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public boolean useDynamicSliceSummary() {
+        return true;
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        return SystemProperties.get("ro.board.platform");
+    }
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java
new file mode 100644
index 0000000..3ed36bb
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/TotalRAMPreferenceController.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo.hardwareinfo;
+
+import android.app.ActivityManager;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.slices.Sliceable;
+
+import java.text.DecimalFormat;
+
+public class TotalRAMPreferenceController extends BasePreferenceController {
+
+    public TotalRAMPreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return mContext.getResources().getBoolean(R.bool.config_show_device_model)
+                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public boolean useDynamicSliceSummary() {
+        return true;
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        ActivityManager actManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+        ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
+        actManager.getMemoryInfo(memInfo);
+        DecimalFormat ramDecimalForm = new DecimalFormat("#.#");
+        long totRam = memInfo.totalMem;
+        double kb = (double)totRam / 1024.0;
+        double mb = (double)totRam / 1048576.0;
+        double gb = (double)totRam / 1073741824.0;
+        String ramString = "";
+        if (gb > 1) {
+            ramString = ramDecimalForm.format(gb).concat(" GB");
+        } else if (mb > 1) {
+            ramString = ramDecimalForm.format(mb).concat(" MB");
+        } else {
+            ramString = ramDecimalForm.format(kb).concat(" KB");
+        }
+        return ramString;
+    }
+}