Skip to content

Commit

Permalink
fix(bios): added support to get sn in android < 7 (#222)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Grosz <lalogrosz@gmail.com>
  • Loading branch information
lalogrosz authored and Alexander Salas Bastidas committed Jul 3, 2019
1 parent bf71b09 commit 00ae538
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions inventory/src/main/java/org/flyve/inventory/categories/Bios.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,32 @@ public String getMotherBoardSerial() {
public String getSystemSerialNumber() {
String systemSerialNumber = "Unknown";
try {
if (!Build.SERIAL.equals(Build.UNKNOWN)) {
// Mother Board Serial Number
// Since in 2.3.3 a.k.a gingerbread
systemSerialNumber = Build.SERIAL;
} else {
//Try to get the serial by reading /proc/cpuinfo
String serial = "";
try {
serial = this.getSerialNumberFromCpuInfo();
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}
//Try to get the serial by reading /proc/cpuinfo
String serial = "";

//First, use the hidden API!
//Versions < Android 7 get bad serial with Build.SERIAL
serial = getSerialFromPrivateAPI();

if (!serial.equals("") && !serial.equals("0000000000000000")) {
systemSerialNumber = serial;
if (serial.equals("")) {
if (!Build.SERIAL.equals(Build.UNKNOWN)) {
// Mother Board Serial Number
// Since in 2.3.3 a.k.a gingerbread
systemSerialNumber = Build.SERIAL;
} else {
//Last try, use the hidden API!
serial = getSerialFromPrivateAPI();
if (!serial.equals("")) {

try {
serial = this.getSerialNumberFromCpuInfo();
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}

if (!serial.equals("") && !serial.equals("0000000000000000")) {
systemSerialNumber = serial;
}
}
} else {
systemSerialNumber = serial;
}
} catch (Exception ex) {
FlyveLog.e(FlyveLog.getMessage(context, CommonErrorType.BIOS_SYSTEM_SERIAL, ex.getMessage()));
Expand All @@ -231,15 +235,35 @@ public String getSystemSerialNumber() {
* @return String with a Serial Device
*/
private String getSerialFromPrivateAPI() {
String serial = "N/A";

String serialNumber;

try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
} catch (Exception ex) {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);

serialNumber = (String) get.invoke(c, "gsm.sn1");

if (serialNumber.equals("")) {
serialNumber = (String) get.invoke(c, "ril.serialnumber");

if (serialNumber.equals("")) {
serialNumber = (String) get.invoke(c, "ro.serialno");

if (serialNumber.equals("")) {
serialNumber = (String) get.invoke(c, "sys.serialnumber");
}
}
}



} catch (Exception ex) {
FlyveLog.e(FlyveLog.getMessage(context, CommonErrorType.BIOS_SERIAL_PRIVATE, ex.getMessage()));
}
return serial;
serialNumber = "";
}

return serialNumber;
}

/**
Expand Down

0 comments on commit 00ae538

Please sign in to comment.