What is the proper way to get the serial number from native on Android O without calling the Java Build.getSerial()
.
On Android < 26 versions from native we could get the device serial number using the following code:
string serial = read_property("ro.boot.serialno");
...
string read_property(const string& property_name) {
char propertyValue[PROP_VALUE_MAX];
int propertyLen = __system_property_get(property_name.c_str(), propertyValue);
...
}
On Android O this throws an error:
Access denied finding property "ro.boot.serialno"
Although the READ_PHONE_STATE
permission is granted. Seems to be related to the deprecated Build.SERIAL
in Android 26.
I managed to get this property using adb
, so the value is not removed and is there:
adb shell getprop ro.boot.serialno