Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect when Android x86 is emulating ARM?

I have a JNI library that runs well on most Android devices - ARMv5, ARMv7, and x86.

I'm using NEON instructions on ARMv7, but instead of cluttering the code with conditional/duplicated source, I want to detect a non-NEON ARMv7 in Java at library load time, and load the v5 library instead: slow CPU is slow.

I found a post suggesting that I look for the 'neon' feature in /proc/cpuinfo, so I'm parsing that, and loading libthing.so usually, or libthing-v5.so if the device claims to be an ARMv7 without NEON. This works nicely on ARM.

Unfortunately not only does x86 emulate an ARM /proc/cpuinfo(!), if it decides it doesn't understand NEON then it also digs out the libthing-v5.so from the armeabiv7a directory, and uses it because there isn't one in the x86 directory.

My current workaround is just to copy the x86 library to both libthing.so and libthing-v5.so so if x86 is pretending to be a NEON-free ARMv7 chip, it'll get the x86 library anyway.

Aside from cooking up a tiny standalone architecture-detecting library of my own based on Yeppp or Android's own cpufeatures, is there a way to determine the genuine local architecture from Java?


@ph0b: Herewith the output of the Razr i, showing that the emulator has decided that the application has been installed as an 'ABI2 58', and that it needs to fake out /proc/cpuinfo.

Given that both shared libraries are available from x86 as well as the armeabi* directories, I don't understand why the device has decided to be an ARM. I might ask my contact at Intel about this.

06-05 10:58:41.360 17807 18053 D dalvikvm: Trying to load lib /data/data/com.company.android/lib/libmp.so 0x42409cb0
06-05 10:58:41.360 17807 18053 D dalvikvm: Added shared lib /data/data/com.company.android/lib/libmp.so 0x42409cb0
06-05 10:58:41.370 17807 18053 D dalvikvm: No JNI_OnLoad found in /data/data/com.company.android/lib/libmp.so 0x42409cb0, skipping init
06-05 10:58:41.420 17807 18053 D         : Searching package installed with ABI2 with Uid: 10109 
06-05 10:58:41.420 17807 18053 D         : Apps with ABI2 58 accessing /proc/cpuinfo 
06-05 10:58:41.430 17807 18053 I System.out: #Here's most of /proc/cpuinfo
06-05 10:58:41.430 17807 18053 I System.out: #Thu Jun 05 10:58:41 GMT+01:00 2014
06-05 10:58:41.430 17807 18053 I System.out: Serial=0000000000000001
06-05 10:58:41.430 17807 18053 I System.out: Revision=0001
06-05 10:58:41.430 17807 18053 I System.out: CPU=revision\t\: 1
06-05 10:58:41.430 17807 18053 I System.out: BogoMIPS=1500
06-05 10:58:41.430 17807 18053 I System.out: Hardware=placeholder
06-05 10:58:41.430 17807 18053 I System.out: Features=vfp swp half thumb fastmult edsp vfpv3 
06-05 10:58:41.430 17807 18053 I System.out: Processor=ARMv7 processor rev 1 (v7l)
06-05 10:58:41.430 17807 18053 I NativeWahooLibrary: Detected ARMv7 processor rev 1 (v7l) (=ARMv7, true) with (neon@-1) vfp swp half thumb fastmult edsp vfpv3 
06-05 10:58:41.430 17807 18053 D dalvikvm: Trying to load non-neon lib /data/data/com.company.android/lib/libwahoo-v5.so 0x42409cb0
like image 522
android.weasel Avatar asked Jun 04 '14 15:06

android.weasel


1 Answers

I doubt the x86 emulates an ARM /proc/cpuinfo !?

Anyway, in order to detect the local architecture from Java, you can rely on Build.CPU_ABI and Build.CPU_ABI2: http://developer.android.com/reference/android/os/Build.html#CPU_ABI, and then continue parsing /proc/cpuinfo to look for neon only if CPU_ABI and CPU_ABI2 are arm*/armeabi-v7a

like image 61
ph0b Avatar answered Oct 01 '22 21:10

ph0b