Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access ro.serialno from native in Android 8?

I need some help. I have an app that is mostly written in native C code. I use the __system_property_get(const char * name, char * value) method to read the serial nr. of the device at various points in my native code. With Android 8 I always get a "Access denied" message now.
libc: Access denied finding property "ro.serialno"
Is there a way for me to still be able to read the serial nr. in Android 8? I tried switching to targetSDKversion < 26 but it still gives me a "Access denied" message. I do get the correct values if I use Java with Build.SERIAL (regardless of SDK version) and Build.getSerial() in SDK version 26 if I grant the READ_PHONE_STATE permission. But I cannot read these values in Java and pass them to the native code without a huge rewrite of the native code.

Any help?

like image 455
carlaharris Avatar asked Oct 19 '17 08:10

carlaharris


2 Answers

I met this problem too. Finally I find the root cause of the problem. In Android O, SELinux sets a lot of limitations in system property. In this case, There is a neverallow to limit read serial number except some domain in whitelist.

For more specific information, you can read code in system/sepolicy/public/domain.te:

neverallow {
  domain
  -adbd
  -dumpstate
  -hal_drm
  -init
  -mediadrmserver
  -recovery
  -shell
  -system_server
} serialno_prop:file r_file_perms;
like image 152
simowce Avatar answered Sep 23 '22 05:09

simowce


If you have the hand on AOSP:

  1. Put android:sharedUserId="android.uid.system" to AdnroidMainfest
  2. Run app like system_app.
  3. Change in Android.mk. LOCAL_MODULE_PATH := $(TARGET_OUT)/app.

Or you can duplicate the property.

like image 39
Thinh Dinh Avatar answered Sep 24 '22 05:09

Thinh Dinh