Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DroidCon NYC 2014 : Android NDK for portability...

Anu Ka
September 21, 2014

DroidCon NYC 2014 : Android NDK for portability, performance and security

At Motorola Solutions, we focus on creating enterprise grade mobile computers based off on stock Android.
This session focuses on how we have leveraged Android NDK to design and develop custom hardware and proprietary software to extend and scale what stock Android provides.

Anu Ka

September 21, 2014
Tweet

Other Decks in Technology

Transcript

  1.  NDK Overview  JNI Walkthrough  Use-cases : 

    Portability  Security  Adding custom hardware  ART  Resources
  2.  When is NDK useful ? Ex: Joey camera, DSP

    application requiring FFT  Abstract software heavy lifting or achieve low level hardware redirection  Extend the Android platform  Threading, memory mgmt, chipset support, legacy code, performance
  3.  Oracle Java spec – your best friend on this

    journey !  Layer between managed Java code and unmanaged native C/C++  Integrates the native code with the Dalvik VM  JNI Interface functions and pointers Source : Oracle JNI Spec
  4.  Reach into low level hardware directly – IOCTLS, I2C

    drivers  Support for ample 3rd party libs – crypto, math, statistic, analytic  Port software value adds across OSes sustainably  Easy build/deploy – Eclipse, Studio, Windows, Ubuntu etc.  Leverage multi-threading support in both Dalvik and Native  System permissions make this that much more powerful TIPS :  Leverage chipset flags  Reverse JNI comes in handy. [Look up IDs once and cache it].  GetArrayRegion() instead of GetArrayElements(); ReleaseArrayRegion() -> JNI_COMMIT, JNI_ABORT, JNI_DEFAULT  Exceptions : (tradeoff size), env->ExceptionCheck(). C++ exceptions are not supported  Use CheckJNI via adb shell
  5.  Native code is that much harder to disassemble 

    Resides in the sandbox of the host app and inherits permissions  Reverse JNI as an option – reach into Java crypto libs to be more generic  Access to system files and I/O simpler provided you have the right permissions Tips :  File scope symbol : qualify with “static”  Use dynamic seed generation for security [based on runtime details – pkgName, device details etc.]  Collection of .a files into a .so  Use “-fvisibility=hidden “ in the Android.mk file [JNIEXPORT required]  Use Obfuscation tools on .so and .a to secure further
  6.  Android recommended way to add your own hardware and

    extend the platform  Expose to your end-users via a proper SDK – with both .jar as well as .so files  SDKs – sustainable and manageable via proper version control  Platform Testing  /mydroid/device/sample /apps /etc /framework /overlays /sdk-addon /skins /Android.mk TIPS :  Leverage the /sdk-addon/stubs_defs.txt for additional data abstraction
  7.  Android Run Time  Offers Ahead of Time Compilation

    [in place of the current JIT compilation]  Great boost in performance for Java based apps  Initial tests reveal apps heavily reliant on NDK haven’t seen much of a performance boost  NDK still very much relevant – portability, security, custom hardware, chipset specific optimizations
  8.  Getting started : http://developer.android.com/tools/sdk/ndk/index.html  JNI Spec : http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html

     Google groups  android-ndk  android-porting  android-platform  Stackoverflow  http://www.akkadia.org/drepper/dsohowto.pdf  https://gcc.gnu.org/onlinedocs/gcc/Option-Index.html