Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 737a0cc3 authored by David Ng's avatar David Ng Committed by Gerrit - the friendly Code Review server
Browse files

Add processor info in device info screen

Display the CPU processor info based on the "Hardware" line
of /proc/cpuinfo in the Device Info screen.

Change-Id: I77a8dfc6c35bf6395c0a1ac1426fb24884af554d
parent 7286f3fc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2176,6 +2176,8 @@
    <string name="firmware_version">Android version</string>
    <!-- About phone screen, status item label  [CHAR LIMIT=40] -->
    <string name="model_number">Model number</string>
    <!-- About phone screen, status item label  [CHAR LIMIT=40] -->
    <string name="processor_info">Processor info</string>
    <!-- About phone screen, fcc equipment id label  [CHAR LIMIT=40] -->
    <string name="fcc_equipment_id">Equipment ID</string>
    <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
+7 −1
Original line number Diff line number Diff line
@@ -103,6 +103,12 @@
                android:title="@string/model_number"
                android:summary="@string/device_info_default"/>

        <!-- Device hardware processor infol -->
        <Preference android:key="device_processor"
                style="?android:preferenceInformationStyle"
                android:title="@string/processor_info"
                android:summary="@string/device_info_default"/>

        <!-- Device firmware version -->
        <Preference android:key="firmware_version" 
                style="?android:preferenceInformationStyle"
+36 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
    private static final String LOG_TAG = "DeviceInfoSettings";
    private static final String FILENAME_PROC_VERSION = "/proc/version";
    private static final String FILENAME_MSV = "/sys/board_properties/soc/msv";
    private static final String FILENAME_PROC_CPUINFO = "/proc/cpuinfo";

    private static final String KEY_CONTAINER = "container";
    private static final String KEY_REGULATORY_INFO = "regulatory_info";
@@ -71,6 +72,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
    private static final String KEY_KERNEL_VERSION = "kernel_version";
    private static final String KEY_BUILD_NUMBER = "build_number";
    private static final String KEY_DEVICE_MODEL = "device_model";
    private static final String KEY_DEVICE_PROCESSOR = "device_processor";
    private static final String KEY_SELINUX_STATUS = "selinux_status";
    private static final String KEY_BASEBAND_VERSION = "baseband_version";
    private static final String KEY_FIRMWARE_VERSION = "firmware_version";
@@ -96,6 +98,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
        findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
        setValueSummary(KEY_BASEBAND_VERSION, "gsm.version.baseband");
        setStringSummary(KEY_DEVICE_MODEL, Build.MODEL + getMsvSuffix());
        setStringSummary(KEY_DEVICE_PROCESSOR, getDeviceProcessorInfo());
        setValueSummary(KEY_EQUIPMENT_ID, PROPERTY_EQUIPMENT_ID);
        setStringSummary(KEY_DEVICE_MODEL, Build.MODEL);
        setStringSummary(KEY_BUILD_NUMBER, Build.DISPLAY);
@@ -484,5 +487,38 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
            }
        };

    /**
     * Returns the Hardware value in /proc/cpuinfo, else returns "Unknown".
     * @return a string that describes the processor
     */
    private static String getDeviceProcessorInfo() {
        // Hardware : XYZ
        final String PROC_HARDWARE_REGEX = "Hardware\\s*:\\s*(.*)$"; /* hardware string */

        try {
            BufferedReader reader = new BufferedReader(new FileReader(FILENAME_PROC_CPUINFO));
            String cpuinfo;

            try {
                while (null != (cpuinfo = reader.readLine())) {
                    if (cpuinfo.startsWith("Hardware")) {
                        Matcher m = Pattern.compile(PROC_HARDWARE_REGEX).matcher(cpuinfo);
                        if (m.matches()) {
                            return m.group(1);
                        }
                    }
                }
                return "Unknown";
            } finally {
                reader.close();
            }
        } catch (IOException e) {
            Log.e(LOG_TAG,
                "IO Exception when getting cpuinfo for Device Info screen",
                e);

            return "Unknown";
        }
    }
}