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

ROM Cooking - Droidcon UK 20013

Slvn
October 27, 2013

ROM Cooking - Droidcon UK 20013

Slides of the Droidcon UK 2013 Workshop made by Sylvain Galand from Genymobile about ROM Cooking.

Slvn

October 27, 2013
Tweet

More Decks by Slvn

Other Decks in Programming

Transcript

  1. AGENDA 01 Android 02 Architecture 03 Hardware Support 04 AOSP

    05 Build Demo: Add a kernel module Android style
  2. ANDROID STORY Releases 1.5 3.x 1.6 2.x April 30, 2009

    September 15, 2009 October 2009 May 2010 December 2010 Febuary 2011 FAST & CURIOUS 4.x October 2011 July 2012 November 2012 July 2013 ... ...
  3. ANDROID STORY Figures 1 M Apps 75 % market share

    900 M Devices 50G dls ! Smartphones IDC 2013 1.5M/day
  4. ANDROID STORY Android Compliancy Compatibility Test Suite Compatibility Definition Document

    CDD Let Google test it when you already did everything Compatibility Test Suite manual testing CTS CTS man. Big G.
  5. but it’s open source NOT an OPEN SOURCE PROJECT Android

    is ANDROID STORY Android, an open source project ?
  6. Sensors Camera Bluetooth GSM, 3G, 4G, LTE GPS Touchscreen ANDROID

    DEVICE ANDROID ARCHITECTURE So much features
  7. IPC BINDER POWER MANAGEMENT WAKELOCK MORE TIMER, OOM, LOGGER ...

    ANDROID ARCHITECTURE Linux modifications
  8. GPL for the kernel ! Apache Framework & Apps ANDROID

    HARDWARE SUPPORT Open source licensing
  9. DRIVERS ARE CLOSED SOURCE DRIVERS ARE NOT AVAILABLE DRIVERS ARE

    F**ING ESSENTIALS ! ANDROID HARDWARE SUPPORT U.S. Route 66
  10. Google made a tool called “repo” ! ANDROID OPEN SOURCE

    PROJECT repo Everything is available through git repositories.
  11. Branch switching is risky in my opinion ANDROID OPEN SOURCE

    PROJECT Tree of life repo init -u https://android.googlesource.com/platform/manifest -b android-4.3.1_r1
  12. ANDROID OPEN SOURCE PROJECT Folders 1/4 Google Android libc implementation

    Bootloader & recovery Build system Compatibility Test Suite bionic/ bootable/ build/ cts/
  13. ANDROID OPEN SOURCE PROJECT Folders 2/4 Dev tools, debug applications...

    Configuration for each target device External libraries Android framework develope ment/ device/ external/ framework/
  14. ANDROID OPEN SOURCE PROJECT Folders 3/4 Java implementation (Apache Harmony)

    Native Development Kit Results of your build Android base applications (sms, camera…) libcore/ ndk/ out/ packages/
  15. ANDROID OPEN SOURCE PROJECT Folders 4/4 Binaries (toolchain, gdbserver…) Software

    developement kit Base : init, toolbox, logcat... Vendor directory (libs, apps) prebuilt/ sdk/ system/ vendor/
  16. « the definition of open: mkdir android cd android repo

    init repo sync make » ANDY RUBIN Android’s dad BUILD ANDROID What a classy first tweet !
  17. Ubuntu 10.04 for builds BUILD ANDROID sources.android.com a LOT of

    dependencies must be installed you can chroot it !
  18. BUILD ANDROID prepare the environment #source build/envsetup.sh including device/samsung/maguro/vendorsetup.sh including

    device/samsung/tuna/vendorsetup.sh including device/ti/panda/vendorsetup.sh including sdk/bash_completion/adb.bash Example : device/samsung/maguro/vendorsetup.sh add_lunch_combo full_maguro-userdebug
  19. BUILD ANDROID Lunch time #lunch You're building on Linux Lunch

    menu... pick a combo: 1. full-eng 2. full_x86-eng 3. vbox_x86-eng 4. full_maguro-userdebug 5. full_tuna-userdebug 6. full_panda-eng Which would you like? [full-eng]
  20. Congratulations ! COOKING YOUR OWN ROM You are now proud

    owners of the skill : BUILD ANDROID #WIN
  21. YOU BUILD 100% AOSP EXPERIENCE YOU CAN MODIFY EVERYTHING YOU

    CAN ADD ANYTHING BUILD ANDROID Start coding !
  22. MIX ANDROID KERNEL init dev # in init.rc on boot

    insmod /system/lib/modules/droidcon.ko chown system system /dev/droidcon chmod 0600 /dev/droidcon # in ./device/<vendor>/<product>/device.mk PRODUCT_COPY_FILES := \ device/<vendor>/<product>/droidcon.ko: system/lib/modules/droidcon.ko
  23. MIX ANDROID KERNEL /dev/droidcon test adb shell # ls -l

    /dev/droidcon crw------- system system 249, 0 droidcon # echo Hello > /dev/droidcon # cat /dev/droidcon hELLO #
  24. MIX ANDROID KERNEL hardware/droidcon/lib # in libdroidcon.h ssize_t droidcon_getdata(void *buf,

    size_t count); ssize_t droidcon_putdata(const void *buf, size_t count); void droidcon_clear(void); # This is the (often closed) part where we should do all the complicated code
  25. MIX ANDROID KERNEL frameworks/base/core/java/android/droidcon/ #LibDroidcon.java package android.droidcon; public class LibDroidcon

    { public native static void clear(); public native static String getData() throws DroidconException; public native static void putData(String in) throws DroidconException; static { System.loadLibrary("droidcon_jni"); } }
  26. MIX ANDROID KERNEL hardware/droidcon/jni/ #android_droidcon_LibDroidcon.c JNIEXPORT void JNICALL Java_android_droidcon_LibDroidcon_putData(JNIEnv *env,

    jclass cls, jstring string) { int ret; const char *buff = (*env)->GetStringUTFChars(env, string, NULL); int length = (*env)->GetStringLength(env, string); ret = droidcon_putdata(buff, length); if (ret < 0) { ThrowDroidconException(env, "fail to put data"); } (*env)->ReleaseStringUTFChars(env, string, buff); }
  27. MIX ANDROID KERNEL framework/base/droidcon/java/android/droidcon/ #IDroidconManager.aidl package android.droidcon; /** {@hide} */

    interface IDroidconManager { void clear(); String getData(); void putData(String data); }
  28. MIX ANDROID KERNEL frameworks/base/services/java/com/android/server/ #DroidconService.java class DroidconService extends IDroidconManager.Stub {

    public String getData() { enforceAccessPermission(); try { return LibDroidcon.getData(); } catch(DroidconException e) { Slog.d(TAG, "cannot getdata"); } return null; } ... private void enforceAccessPermission() { … } }
  29. MIX ANDROID KERNEL Hacking SystemServer.java #SystemServer.java ... public void run()

    { ... try { Slog.i(TAG, "Droidcon Service"); droidconService = new DroidconService(context); ServiceManager.addService(Context.DROIDCON_SERVICE, droidconService); } catch (Throwable e) { reportWtf("starting Droidcon Service", e); } ...
  30. MIX ANDROID KERNEL framework/base/droidcon/java/android/droidcon # DroidconManager.java public class DroidconManager {

    IDroidconManager mService; public DroidconManager(IDroidconManager service) { mService = service; } public String getData() { try { return mService.getData(); } catch (RemoteException e) { e.printStackTrace(); } return null; } }
  31. MIX ANDROID KERNEL Hacking ContextImpl.java # DroidconManager.java class ContextImpl extends

    Context { static { ... registerService(DROIDCON_SERVICE, new ServiceFetcher() { public Object createService(ContextImpl ctx){ IBinder b = ServiceManager .getService (DROIDCON_SERVICE); IDroidconManager service = IDroidconManager.Stub.asInterface(b); return new DroidconManager(service); }}); } ...
  32. and configure our IDE BUILD OUR SDK We can now

    MIX ANDROID KERNEL make update-api ; make sdk
  33. MIX ANDROID KERNEL Code an awesome app ! DroidconManager droidconManager;

    droidconManager = (DroidconManager) this.getSystemService(DROIDCON_SERVICE); droidconManager.putData(“Hello Droidcon London!”);
  34. Thank You for your time ! Now let’s finish this

    hackathon ! Build your own ROM Use the Sources Buy devices with AOSP support SYLVAIN GALAND @sylvaingaland http://slvn.fr/+ [email protected] Thanks Cédric Cabessa for the awesome open source droidcon device !