Permalink
Browse files

DeviceInfoUtils: Expand Processor string #3

Previously located in Settings: krexus/packages_apps_Settings@f95421f

This time, it becomes even more global (catch all):
 - Remove "Hardware" hardcoded necessity
 - Now check for both "Hardware" and "Processor" strings
 - If both are found, pick the bigger one (and pray it has the most relevant info)
  • Loading branch information...
KreAch3R authored and xlxfoxxlx committed Sep 19, 2016
1 parent 8ffc1fa commit d2678f766baccc584887742f393cc0d614699954
Showing with 20 additions and 6 deletions.
  1. +20 −6 packages/SettingsLib/src/com/android/settingslib/DeviceInfoUtils.java
@@ -238,27 +238,41 @@ public static String getFormattedPhoneNumbers(Context context,
}
/**
* Returns the Hardware value in /proc/cpuinfo, else returns "Unknown".
* Returns the Hardware or Processor value in /proc/cpuinfo,
* else returns "Unknown".
* @return a string that describes the processor
*/
public static String getDeviceProcessorInfo() {
// Hardware : XYZ
final String PROC_HARDWARE_REGEX = "Hardware\\s*:\\s*(.*?)(?:\\(.*)?$"; /* hardware string */
// Hardware or Processor : XYZ
final String PROC_REGEX = ".*\\s*:\\s*(.*?)(?:\\(.*)?$"; /* hardware or processor string */
try {
BufferedReader reader = new BufferedReader(new FileReader(FILENAME_PROC_CPUINFO));
String cpuinfo;
String hardware = "";
String processor = "";
try {
while (null != (cpuinfo = reader.readLine())) {
if (cpuinfo.startsWith("Hardware")) {
Matcher m = Pattern.compile(PROC_HARDWARE_REGEX).matcher(cpuinfo);
Matcher m = Pattern.compile(PROC_REGEX).matcher(cpuinfo);
if (m.matches()) {
return m.group(1);
hardware = m.group(1);
}
} else if (cpuinfo.contains("Processor")) {
Matcher m = Pattern.compile(PROC_REGEX).matcher(cpuinfo);
if (m.matches()) {
processor = m.group(1);
}
}
}
return "Unknown";
if (hardware.isEmpty() && processor.isEmpty()) {
return "Unknown";
} else if (hardware.length() > processor.length()) {
return hardware;
} else {
return processor;
}
} finally {
reader.close();
}

0 comments on commit d2678f7

Please sign in to comment.