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

AOSP Building Blocks (DevFest Berlin 2014)

danybony
November 22, 2014

AOSP Building Blocks (DevFest Berlin 2014)

Most of the Android developers are able to build awesome apps, but do we really know how the Android OS works? In some cases, as when developing a new product, adding customised apps is not enough, and OS modifications are required.
To be able to modify Android at its core, this talk will guide you through the complete process, from setting the correct environment, configuring the different Google’s repositories and downloading the source code, to understand the structure of the source code and how to modify it.

danybony

November 22, 2014
Tweet

More Decks by danybony

Other Decks in Technology

Transcript

  1. AOSP building blocks

    View full-size slide

  2. Daniele Bonaldo
    @danybony_
    +DanieleBonaldo
    danybony
    Android Software Craftsman

    View full-size slide

  3. Repo and manifest
    Usually a single project
    =
    single repository

    View full-size slide

  4. Repo and manifest
    AOSP = more than 450 repositories

    View full-size slide

  5. Repo and manifest
    Enter repo

    View full-size slide

  6. Repo and manifest
    repo init
    -u http://your.company.repo/manifest
    -b working_branch
    -m manifest_name.xml

    View full-size slide

  7. Repo and manifest


    fetch="https://android.googlesource.com/" />
    fetch="ssh://[email protected]/third_party/" />
    remote="aosp"
    sync-j="4" />







    [...]

    View full-size slide

  8. Repo and manifest
    path="packages/apps/Settings"
    remote="company"
    name="firmware-settings"
    revision="other_branch"
    />

    View full-size slide

  9. Repo and manifest
    path="packages/apps/Settings"
    remote="company"
    name="firmware-settings"
    revision="other_branch"
    />
    fetch="ssh://[email protected]/third_party/" />

    View full-size slide

  10. Repo and manifest
    path="packages/apps/Settings"
    remote="company"
    name="firmware-settings"
    revision="other_branch"
    />

    View full-size slide

  11. Repo and manifest
    path="packages/apps/Settings"
    remote="company"
    name="firmware-settings"
    revision="other_branch"
    />

    View full-size slide

  12. Repo and manifest
    repo sync
    -j (--jobs)

    View full-size slide

  13. AOSP Source Code
    http://elinux.org/Master-android

    View full-size slide

  14. AOSP Source Code
    Some examples:
    ● development
    ● frameworks
    ● packages
    ● vendor

    View full-size slide

  15. Edit the source
    Jack M. on Flickr

    View full-size slide

  16. IDE
    ./development/tools/idegen/idegen.sh
    Project definition files generated in
    the root of the working dir

    View full-size slide

  17. Search the source

    View full-size slide

  18. @hide
    Context.sendBroadcastAsUser(Intent, UserHandle);
    Context.startActivityAsUser(Intent, UserHandle);
    Context.startServiceAsUser(Intent, UserHandle);
    @hide
    public UserHandle(int userId)

    View full-size slide

  19. @hide
    public UserHandle(int userId)
    @hide

    View full-size slide

  20. @hide
    public static UserHandle getUserHandleForUser(int userId) {
    try {
    Class userHandleClass = UserHandle.class;
    Constructor constructor = userHandleClass.getDeclaredConstructor(int.class);
    constructor.setAccessible(true);
    return constructor.newInstance(userId);
    } catch (InvocationTargetException e) {
    logUnableToFetchUserHandleForUser(userId, e);
    } catch (NoSuchMethodException e) {
    logUnableToFetchUserHandleForUser(userId, e);
    } catch (InstantiationException e) {
    logUnableToFetchUserHandleForUser(userId, e);
    } catch (IllegalAccessException e) {
    logUnableToFetchUserHandleForUser(userId, e);
    }
    return null;
    }
    REFLECTION

    View full-size slide

  21. Build environment
    https://source.android.com/
    source/initializing.html

    View full-size slide

  22. Mac OS X build environment
    Case-sensitive disk
    image
    Chris McVeigh on Flickr

    View full-size slide

  23. source build/envsetup.sh
    Setting up the build environment
    Check for missing dependencies

    View full-size slide

  24. lunch
    Choose the target product and build variant
    ● eng
    ● userdebug
    ● release

    View full-size slide

  25. make
    export USE_CCACHE=1
    make -jX
    X = # of working threads

    View full-size slide

  26. Speeding up the dev cycle
    make alias for single projects
    m = make from the top of the tree
    mm = make from the current directory
    mmm = make from the given directory
    mmma = make from the given directory WITH dependencies

    View full-size slide

  27. Speeding up the dev cycle
    adb shell stop
    adb sync
    adb shell start

    View full-size slide

  28. Build for devices
    Additional proprietary libraries required
    Placed under vendor/

    View full-size slide

  29. Install
    In out/target/product/DEVICE_NAME/
    ● recovery.img
    ● boot.img
    ● system.img
    ● userdata.img

    View full-size slide

  30. Install
    adb reboot bootloader
    fastboot flashall -w

    View full-size slide

  31. Questions?
    Daniele Bonaldo on G+

    View full-size slide