SlideShare ist ein Scribd-Unternehmen logo
1 von 56
CONFIDENTIAL. ALL RIGHTS RESERVED.
Optio is a subsidiary of Allied Minds, an innovative U.S. science and technology development and commercialization company. Operating since 2006, Allied Minds forms, funds, manages and builds products and businesses based on
innovative technologies developed at leading U.S. universities and federal research institutions. Allied Minds serves as a diversified holding company that supports its businesses and product development with capital, central
Hamilton Turner
Oct 2015
1
Fast-paced Introduction to
Android Internals
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
$ whoami
2
@hamiltont
@hamiltont
• Director of Malware Research, OptioLabs
– Machine Learning, Data Science, Penetration
Testing, and Malware Prevention
• Doctorate in Computer Engineering
– Mobile & Cloud Computing, Distributed
Software Engineering, Security & Privacy
• Heavy contributor to open source software
• Android framework hacker for ~4 years
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
$ who…are we
3
and now a brief message from our sponsors
OptioLabs
– Mobile security company founded in 2011
– Caters to Government, Enterprise, and Mobile Carriers/Manufacturers
– Founders Dr. Charles Clancey, Dr. Jules White, Dr. Brian Dougherty
– Offices in Baltimore & Nashville
– Our OptioCore product increases Android security and enables legal
compliance with numerous regulations
– Recent news:
• AMD and OptioLabs partner to increase enterprise security
• Rugged Meets Secure: OptioCore Powers Sonim XP7
www.optiolabs.com
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
$ who…are we
4
We are hiring!
Mobile Developer (Application & Framework)
Server Developer (Backend & Frontend)
DevOps
Send resumes to our VP of Engineering
www.optiolabs.com
Andy Meister
andy.meister@optiolabs.com
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Slide Set EULA
• Android is…..
– A capital-B Big project
– A complex project
– Changing rapidly
– Different on each physical product
• This presentation is…..
– not comprehensive
– probably not fully correct
– already outdated
• Go explore yourself!
• Please let me know when you find something wrong with this
slide deck
5
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
What does it mean to be ‘Android’?
• Android is a (loosely) protected term!
– AOSP is all the open source code
– Stock ROM is what manufacturer ships
– Vanilla is very close to AOSP
– Android is ROM that passed Android Compatibility
• Android Compatibility
– Different for each version of Android
– 3 main parts
• Compatibility Test Suite (automated tests)
• Compatibility Verifier (human tests)
• Compatibility Definition Doc (manual)
• Android + Google Mobile Services (GMS)
– Google Play! Maps! YouTube! Gmail!
– All these are not open source and require a license agreement with Google if you want to sell a device
that comes with these
https://source.android.com/compatibility/index.html
6
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Is Android really Open Source?
~90% of development is behind closed doors
– Only Google&partners see source code
– Only Google&partners accept (or ignore/deny) patches
• Google is both the KeyMaster and the Architect
– Very few public discussions occur on AOSP design principles
– No public roadmap of features
– However….
• Google accepts huge responsibility for standardization & long term stability of platform
• Major contributions to upstream Linux kernel
• Huge money influx for PR releases, OEM standardization efforts, etc
“Open source is different than a community-driven project. Android is light on the community-driven
side and heavy on the open source. Everything we do ends up in the open source repository.”
- Andy Rubin, Cofounder of Android Inc, SVP@Google until 2013
See https://source.android.com/source/code-lines.html#about-private-code-lines
7
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Super basic legality of Android
• Pre-note: I am not a lawyer. This slide is extremely simplified for explanation purposes and there is therefore incorrect
by design
• Google is very careful to minimize “threats” to parties interested in modifying AOSP
– Actively avoids using components that require ‘derived works’ to be open sourced
• E.g. heavy modders are very familiar with the busybox install process ;-)
• Why Android doesn’t come with the well-tested, POSIX correct glibc?
– Actively avoids using components that *might, possibly* require licensing fees or agreements
• Apache Harmony vs Oracle (sun) Java – see https://en.wikipedia.org/wiki/Oracle_America,_Inc._v._Google,_Inc.
• When modifying Android, you should take a strong interest in the software licenses!
– Smartphone IP is extremely valuable and heavily protected – see https://en.wikipedia.org/wiki/Smartphone_patent_wars
8
Component License
Android applications Up to developer
GSM App suite
AOSP External libraries Apache 2 BSD, misc
Android Kernel GPLv2
Bootloader ???
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android
• Often explained using the stack
on the right
9
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android
• Or these…
10
http://blogs.freescale.com/mcus/2010/05/android-makes-the-move-to-power-architecture-technology/
http://www.techdesignforums.com/edasource/images/68/esd1004_mentor1_large.jpg
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android, Simplified
11
http://blogs.freescale.com/mcus/2010/05/android-makes-the-move-to-power-architecture-technology/
http://www.techdesignforums.com/edasource/images/68/esd1004_mentor1_large.jpg
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android
• The running software stack is critically important to understand
– However, the build system is quite obtuse
– And documentation is sparse & scattered
– One of your big challenges will be mapping running code to
• Source code
• Android filesystem
• Always be on the lookout for the ‘bigger picture’
– All 5 of these are representations of ‘Android’
– Of the docs you can find, 90% will be on the software stack
– 10% will be on the source code
– The rest is up to you
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Filesystem of Android device
• Roughly derived from standard linux filesystem
– See https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
– Uses ramdisk, /sbin, /sys, /dev (sometimes)
• Android adds multiple root folders
– /data, /system, /cache
– These are basically an Android filesystem Hierarchy
• Build system enforces this consistent hierarchy
– Many of the FHS folders are symlinks
• E.g. /etc  /system/etc
– Just enough of a linux filesystem to run a kernel and some helpful functions
• Heavy use of partitions
– Reliable update mechanisms are easier with multiple bootable partitions
– Updates can be made smaller
13
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Filesystem Partitions
• System
– Android OS
– Preinstalled APKs
– Shared libraries
– Executables
• Userdata
– User data, user apps
– App-specific data folders
– Backups
– Dalvik caches
– Crash information
– Encrypted and/or persistent system data
• Cache
– Simple writable, always trashable partition
• Recovery, Boot
– Not first-class citizens while AOSP is running!
14
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Filesystem Partitions
• Adding main symlinks
– /etc, /tombstones,
/vendor
• Note: Some phones have
distinct vendor.img
partition
15
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Filesystem Partitions
• Interactions with Kernel
• /dev is tmpfs
– Android uses udev (ueventd) to
fill /dev
• /acct is used by cgroups
– CPU, Memory, DiskIO accounting
and limiting
• /proc and /sys are standard
linux mechanisms for userspace
and kernel interaction
16
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Useful tooling: Android shell
• Android uses MirBSD Korn shell
(since 4.0 ICS)
• Utilities
– Gnu core utilities? GPL!
– Busybox? GPL!
• Android toolbox? BSD
– See `ls –l /system/bin`
– Emulates ~75 standard tools (ls, rm,
rmdir, top, sleep)
– See AOSP_ROOT/system/core/toolbox
for source
17
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Physical Android Architecture
• Most Android phones have two processors
– Mobile app processor
– Mobile baseband processor
– Communication using interrupts
– Which one ‘leads’?
– Frequently on same Soc
• Sensors/USB/Screen/modem
– Sometimes on SoC, sometimes connected externally
18
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Physical Android Hardware: Sensors
• General problem: sensors normally require proprietary code
– To be business-friendly, AOSP tries very hard to avoid GPL-ing someone’s
sensor code
– This unfortunately means that hardware access is *not* done using one
standard mechanism
• Access mechanisms:
– /dev nodes (display, lights)
– Shared library objects (touch, audio)
– Sockets
– Android HAL
• Android specifies header files, manufacturer provides *.so files
– D-Bus (until recently)
19
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Acquiring Android Source Code
• Google has comprehensive docs
– https://source.android.com/source/downloading.html
• AOSP uses git for version control
– Git repositories become huge given too much time
– AOSP has a lot of pieces (~450 different git repos)
– Working with ~450 git repositories is a nightmare….
• Repo
– Google tool to automate working across many git repos
– Enable branch/fetch/status/etc in multiple git repositories with one command
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
See https://source.android.com/source/build-numbers.html#source-code-tags-and-builds
20
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Acquiring Android Source Code
• In repo terms, each git repo is called a project
• A project has
– A remote (e.g. url)
– A path
– A name
• Repo will clone your projects into ‘detached
HEAD’
– aka anonymous branch
– You should use `repo start <project name>` to
do a git branch
• Repo has a concept of project groups
– Note the ‘notdefault’ group
See https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt
21
<manifest>
<remote name="aosp“
fetch="https://android.
googlesource.com" />
<project path="packages/apps/Mms“
name="platform/packages/apps/Mms" />
…
…
<project path="prebuilts/eclipse-build-deps"
name="platform/prebuilts/eclipse-build-deps"
groups="notdefault,eclipse" />
</manifest>
$ cat .repo/manifest.xml
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Uploading Android Source Code
• Doing code reviews across ~450 git repos is a
pain!
• Enter ‘gerrit’
– Google developed a code review website that is
specific to AOSP modifications
– Extremely structured process
– Can be self-hosted
– Integrated with ‘repo upload’
• Note: Your dev team does not have to use gerrit
– You can use git directly to push code
– Not quite as painless as ‘repo upload’, but you don’t
have to setup/maintain/use gerrit
22
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
23
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
24
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
You want to work with AOSP in any capacity
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
25
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
You want to port AOSP to a really-small IoT kind of device
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
26
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
You want to modify what it means to be ‘Dalvik’
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
27
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
You want to add a new system service to Android
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
28
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
You want to build a custom ROM to is AOSP with different images
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
29
abi C++ support for ABI
art Android ART runtime, compiler, dex2oat, etc
bionic Android C standard library
bootable Android Recovery image (no bootloader)
build Makefile-based AOSP build system
dalvik Dalvik VM source code, dex format spec, libdex
developers Source code examples
development Resources for setting up dev environments. Config files, small scripts, USB drivers
device Device-specific files and binaries
docs Doxyfile for source.android.com
external External projects used by AOSP
frameworks Android core components
hardware Android Hardware Abstraction Layer and hardware support
kernel Precompiled kernel images with Android modifications
libcore All java.* packages from Object.java down, as supplied by Apache Harmony
libnativehelper Android wrapper to make JNI easier to work with
ndk Native Development Kit source code & tools (for using C/C++ from APKs)
out Build output directory. make clean ~= rm -rf out
packages Stock Android apps, Input methods, content providers, etc
pdk Platform Development Kit for OEMs to test upcoming AOSP versions
prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc
sdk Software Development Kit – eclipse, ADT, SdkManager, etc
system Native components of Android that run on top of Linux
tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons
vendor OEM chipset binaries and device definitions
You want to use a different Bluetooth stack
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Navigating Android Source Code
• godir is your friend!
– It’s find and cd rolled into one command
30
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Building Android Source Code
• Use make!
• I don’t know why that needed an entire slide…
31
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Building Android Source Code
1. Setup computer
See https://source.android.com/source/building.html
2. Setup your shell
$ source build/envsetup.sh
3. Choose compile target
$ lunch aosp_arm-eng
4. Compile – full compile takes hours
$ make
5. Run emulator (or skip this and run on device instead)
$ emulator
6. Flash device
$ adb reboot-bootloader
$ fastboot –w flashall
32
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Building Android Source Code
1. Setup computer
See https://source.android.com/source/building.html
2. Setup your shell
$ source build/envsetup.sh
3. Choose compile target
$ lunch aosp_arm-eng
4. Compile – full compile takes hours
$ make
5. Run emulator (or skip this and run on device instead)
$ emulator
6. Flash device
$ adb reboot-bootloader
$ fastboot –w flashall
33
What is this?
How does this work?
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Build System – High Level
• AOSP has ~40k lines of makefiles under /build and /device
– Important to grok the main points before diving in there!
• Comparisons to standard projects using make
– Uses ‘Android.mk’, not ‘Makefile’
– Heavy usage of ANDROID_* environment variables
– All output (even intermediate) goes into ‘out’ folder
• rm –rf out/
– Smallest buildable unit is a ‘module’
• Similar to standard make targets, but there are 1000s of these
• While many ‘modules’ are named statically, even more are created dynamically!
– For example, every module “foo” automatically gets an accompanying module “foo-clean”
– Non-recursive build system
• See http://aegis.sourceforge.net/auug97.pdf
• See build/core/build-system.html
– You never call gcc yourself! Multiple ‘build templates’ exist
• Android application, shared library, static library, standalone executable, java library, prebuilt
• Build templates enforce the Android filesystem layout
• Accept “parameters” in the form of make variables (will default parameters if these variables are not set)
34
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Build System – High Level
To build a module:
• Setup expected variables:
LOCAL_PATH := $(call my-dir)
LOCAL_MODULE_NAME := some_example
• Then include the proper build template:
include $(BUILD_JAVA_LIBRARY)
The build template will read the variables you set, compile as expected
(in this case, as expected for a java library), and place the intermediates
and final output in the correct locations inside the out/ folder
35
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Build System – High Level
• Build system includes lots of ‘dark magic’
• Not recommended to just start writing an
Android.mk
– Find one that does what you want and modify it
– Or you’ll have forgotten a variable
• Look into build/core/ to find makefiles for each build
template
– All options listed at build/core/config.mk line ~75
– Missing variables are often set to default values
36
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
What is lunch?
• AOSP has many compile options
– Set options with env variables or
buildspec.mk
– envsetup.sh defines functions to help
set options using env variables
– One helper is ‘lunch’
– “I’m having JellyBeans for lunch”
• Just calling lunch presents a menu of
the form:
$TARGET_PRODUCT-$TARGET_BUILD_VARIANT
37
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Build Targets
• Target product ~= device + configuration
– E.g. nexus 6 (aka shamu)
– E.g. en keyboard/apps/tts
– Device name is arbitrary
• Example products
– aosp_arm: AOSP default locale on Emulator
– full_fugu: All locales on Nexus Player
– aosp_shamu: AOSP default on Nexus 6
– See https://source.android.com/source/build-
numbers.html
• To build your own, take a look at the different
AndroidProducts.mk and vendorsetup.sh scripts
– See https://source.android.com/source/add-
device.html
38
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Build Variants & Type
• Target_build_variant determines the default apps and settings
– user: Include stuff plan user would want
– userdebug: Include user stuff, and a few items/settings to make
debugging easier
– eng: Include userdebug stuff, user stuff, and item/settings an
engineer might use
• Target_build_type
– You can set this to release or debug to change the settings of
ConfigBuildFlags.DEBUG
– This is used to enable/disable some extra logging in core system
services
39
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Building Android Source Code
1. Setup computer
See https://source.android.com/source/building.html
2. Setup your shell
$ source build/envsetup.sh
3. Choose compile target
$ lunch aosp_arm-eng
4. Compile – full compile takes hours
$ make
5. Run emulator (or skip this and run on device instead)
$ emulator
6. Flash device
$ adb reboot-bootloader
$ fastboot –w flashall
40
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Modifying a Single Module
1. Modify code
$ gedit frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
2. Compile that module
Note: findmakefile function is helpful to discover the LOCAL_MODULE_NAME
$ make framework
3. Rebuild the system.img file using special snod module
$ make snod
4. Reflash
$ adb reboot-bootloader
$ fastboot –w flashall
41
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Bootup (Roughly) Explained
42
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android init.rc
• Android uses it’s own language for the init files
– Easy to understand
– I recommend you read init.rc
• Main primitives
– service: names a command string execution. Distinct from
other uses of word ‘service’
• Start with ‘start <servicename>’
• Can be grouped into ‘classes’
• Start class with ‘class_start <classname>’
– action: on some trigger, do this
• Predefined actions
– early-init, init, early-fs, fs, early-boot, boot
• User-defined action: property setting changed
– trigger: something happened
• ‘on <trigger>’ defines an action to react
• ‘trigger <triggername>’ fires the trigger
• Location of init.rc files
– In running system (e.g. in ramdisk) : /init.*rc
– In build system: system/core/rootdir/*.rc and /device
43
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Properties
• OS-wide key-value properties
– Not the same as Java properties
– Not environment variables
– Follow a hierarchy of naming
• Use getprop and setprop tools
– Note: There is actually a socket file, but its
tricky to access
• Setprop can be used to trigger actions in
init.rc!
– Start/stop native code
– Set logging levels
– Change properties that persist across boot
44
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android Properties
• Where do properties originally get set?!
– Filesystem (/default.prop, /system/build.prop)
– Init.rc files
– Java code – SystemProperties.set
– C++ code – property_set
• Some properties are controlled by UID/GID permissions
– E.g. ril.* properties can only be set by RADIO user
• Special cases
– ro.* is read-only. These can only be set once (normally at boot)!
– persist.* properties are written to the filesystem and persist across reboots
– ctl.* properties are not actually stored into the properties map. They enable you to start or stop an init.rc
‘service’ using the properties system
• E.g. ‘ctl.start foobar’ would start service ‘foobar’
45
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
What’s a zygote?
• At a native level, binary is called
app_process
• Encapsulates starting the Dalvik VM
• Eases the use of JNI
• Loads all Java libraries into itself
• Is capable of being forked
• Drastically speeds up creation of new,
ready-to-go processes pre-loaded with
the Dalvik VM and java libraries
46
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android System Server
• Note that only one bit of Android talks
to the Hardware & Kernel
• This is system server
– Multiplexes access to single-user systems
like the display
– Does most of the complex book-keeping
– Accepts remote messages from apps and
acts on their behalf (e.g. send SMS)
• Most ‘Android System Services’ run as a
thread inside the system_server
process
– Although a number run as standalone
apps with the persistent=true flag
47
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Main Android Services
• Some biggies:
– WifiService
– ActivityManagerService
– PowerService
– PackageManagerService
– LocationManagerService
• There are about ~90 more
– Individually they are not too bad
– Look in source code under frameworks/base/services
– Don’t start with ActivityManager ;-)
• Developers access these using Context.getSystemService
• How does this all happen?
48
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android IPC Architecture
“In the Android platform, the binder is used for
nearly everything thathappens across processes
in the core platform.” - Dianne Hackborn,
Android Framework Engineer @ Google -
https://lkml.org/lkml/2009/6/25/3
I highly recommend:
https://newcircle.com/s/post/1340/deep_dive_into_android_ipc_binder_framework_at_andevcon_iv
49
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android IPC Basics
• Android app calls into
android.jar
• In many places, android.jar
wants to call some core
framework service
– Proxy software design pattern!
• To send data through the
Binder driver, you have to write
data into a string
– Marshalling/unmarshalling
50
https://i.stack.imgur.com
/EkzyV.png
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android IPC Basics
• Android app calls into
android.jar
• In many places, android.jar
wants to call some core
framework service
– Proxy software design pattern!
• To send data through the
Binder driver, you have to write
data into a string
– Marshalling/unmarshalling
51
https://i.stack.imgur.com/EkzyV.png
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android IPC Basics
• AIDL files are used to
generate the Java source
code for Proxy
– Exactly the same as you can
do in an Android application!
• Very useful to read
generated Proxy & Stub files
52
https://i.stack.imgur.com/EkzyV.png
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Android: Files to Read
• Some source code files are important enough
to actually read…
• Zygote, ZygoteInit
• SystemServer
• Init.rc
57
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
How is Android not Linux?
• ueventd vs udev
– Check for devices showing up and populate /dev
• Kernel changes!
– Android Out of Memory (OOM) killer
– Wakelocks
– Binder RPC / IPC
– Android’s Anonymous Shared Memory (ashmem)
– Android Alarm (on top oc Linux’s Real time clock RTC)
– Android’s ring logger mechamisms
– Custom init.rc language
– Active work to upstream most of these changes
• https://events.linuxfoundation.org/images/stories/slides/abs2013_stultz.pdf
• Android Upstreaming group - https://wiki.linaro.org/WorkingGroups/Kernel/AndroidUpstreaming
• C standard library
– Bionic vs glibc. Seems this is mainly for licensing reasons
• User management (e.g. uid/gid mapping)
– Linux uses UID/GID. Android uses these for apps, and manages users in the AOSP code
• Hardware approach
– Linux mainly uses /dev for hardware exposure
– Android uses mostly shared object files
60
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
Resources
• Embedded Android
– Really excellent for everything below the AOSP java code
• New Android Book –
– Good for Android AOSP code
– E.g. ‘How does the PowerManager code work’
• Exploring SDK Add-ons
– Very interesting talk covering some of the interaction between Google and OEMs
– https://www.youtube.com/watch?v=1TY5rqyAyp4
• Deep Dive into Android IPC/Binder Framework at AnDevCon IV
– Binder is critical to Android, more understanding == better!
– https://newcircle.com/s/post/1349/andevcon_iv_video_presentations_android_devel
opers
– https://newcircle.com/s/post/1340/deep_dive_into_android_ipc_binder_framework_a
t_andevcon_iv
• Binder IPC talk
– http://www.dre.vanderbilt.edu/~schmidt/cs282/PDFs/android-binder-ipc.pdf
61
CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015
$ who…are we
62
We are hiring!
Mobile Developer (Application & Framework)
Server Developer (Backend & Frontend)
DevOps
Send resumes to our VP of Engineering
www.optiolabs.com
Andy Meister
andy.meister@optiolabs.com

Weitere ähnliche Inhalte

Was ist angesagt?

Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Google chrome os (perfect version)
Google chrome os (perfect version)Google chrome os (perfect version)
Google chrome os (perfect version)En Tj Pj
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of AndroidTetsuyuki Kobayashi
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementationChethan Pchethan
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)Nanik Tolaram
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiChris Simmonds
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debuggingUtkarsh Mankad
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0GlobalLogic Ukraine
 

Was ist angesagt? (20)

Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Google chrome os (perfect version)
Google chrome os (perfect version)Google chrome os (perfect version)
Google chrome os (perfect version)
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of Android
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Android Binder: Deep Dive
Android Binder: Deep DiveAndroid Binder: Deep Dive
Android Binder: Deep Dive
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementation
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Linux Audio Drivers. ALSA
Linux Audio Drivers. ALSALinux Audio Drivers. ALSA
Linux Audio Drivers. ALSA
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0
 

Andere mochten auch

An Introduction to Android Internals
An Introduction to Android InternalsAn Introduction to Android Internals
An Introduction to Android InternalsAnjana Somathilake
 
Android modding-source
Android modding-sourceAndroid modding-source
Android modding-sourcePhyo Lay
 
IntelliJ IDEA Architecture and Performance
IntelliJ IDEA Architecture and PerformanceIntelliJ IDEA Architecture and Performance
IntelliJ IDEA Architecture and Performanceintelliyole
 
Timings of Init : Android Ramdisks for the Practical Hacker
Timings of Init : Android Ramdisks for the Practical HackerTimings of Init : Android Ramdisks for the Practical Hacker
Timings of Init : Android Ramdisks for the Practical HackerStacy Devino
 
iOS Security: The Never-Ending Story of Malicious Profiles
iOS Security: The Never-Ending Story of Malicious ProfilesiOS Security: The Never-Ending Story of Malicious Profiles
iOS Security: The Never-Ending Story of Malicious ProfilesYair Amit
 
Hacking and Securing iOS Apps : Part 1
Hacking and Securing iOS Apps : Part 1Hacking and Securing iOS Apps : Part 1
Hacking and Securing iOS Apps : Part 1Subhransu Behera
 
Android Forensics: Exploring Android Internals and Android Apps
Android Forensics: Exploring Android Internals and Android AppsAndroid Forensics: Exploring Android Internals and Android Apps
Android Forensics: Exploring Android Internals and Android AppsMoe Tanabian
 
Q4.11: Introduction to eMMC
Q4.11: Introduction to eMMCQ4.11: Introduction to eMMC
Q4.11: Introduction to eMMCLinaro
 
Learning android with AOSP
Learning android with AOSPLearning android with AOSP
Learning android with AOSPJorge Barroso
 

Andere mochten auch (15)

An Introduction to Android Internals
An Introduction to Android InternalsAn Introduction to Android Internals
An Introduction to Android Internals
 
Android quick talk
Android quick talkAndroid quick talk
Android quick talk
 
Android modding-source
Android modding-sourceAndroid modding-source
Android modding-source
 
IntelliJ IDEA Architecture and Performance
IntelliJ IDEA Architecture and PerformanceIntelliJ IDEA Architecture and Performance
IntelliJ IDEA Architecture and Performance
 
Aosp+
Aosp+Aosp+
Aosp+
 
iOS Views
iOS ViewsiOS Views
iOS Views
 
Timings of Init : Android Ramdisks for the Practical Hacker
Timings of Init : Android Ramdisks for the Practical HackerTimings of Init : Android Ramdisks for the Practical Hacker
Timings of Init : Android Ramdisks for the Practical Hacker
 
iOS Security: The Never-Ending Story of Malicious Profiles
iOS Security: The Never-Ending Story of Malicious ProfilesiOS Security: The Never-Ending Story of Malicious Profiles
iOS Security: The Never-Ending Story of Malicious Profiles
 
Hacking and Securing iOS Apps : Part 1
Hacking and Securing iOS Apps : Part 1Hacking and Securing iOS Apps : Part 1
Hacking and Securing iOS Apps : Part 1
 
eMMC 5.0 Total IP Solution
eMMC 5.0 Total IP SolutioneMMC 5.0 Total IP Solution
eMMC 5.0 Total IP Solution
 
Android Forensics: Exploring Android Internals and Android Apps
Android Forensics: Exploring Android Internals and Android AppsAndroid Forensics: Exploring Android Internals and Android Apps
Android Forensics: Exploring Android Internals and Android Apps
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Q4.11: Introduction to eMMC
Q4.11: Introduction to eMMCQ4.11: Introduction to eMMC
Q4.11: Introduction to eMMC
 
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
 
Learning android with AOSP
Learning android with AOSPLearning android with AOSP
Learning android with AOSP
 

Ähnlich wie Fast-paced Introduction to Android Internals

Enterprise iPad Development Without Notes
Enterprise iPad Development Without NotesEnterprise iPad Development Without Notes
Enterprise iPad Development Without Notesjaxarcsig
 
Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA NITIN GUPTA
 
Bringing Government and Enterprise Security Controls to the Android Endpoint
Bringing Government and Enterprise Security Controls to the Android EndpointBringing Government and Enterprise Security Controls to the Android Endpoint
Bringing Government and Enterprise Security Controls to the Android EndpointHamilton Turner
 
Android Seminar BY Suleman Khan.pdf
Android Seminar BY Suleman Khan.pdfAndroid Seminar BY Suleman Khan.pdf
Android Seminar BY Suleman Khan.pdfNomanKhan869872
 
CNIT 128 Ch 4: Android
CNIT 128 Ch 4: AndroidCNIT 128 Ch 4: Android
CNIT 128 Ch 4: AndroidSam Bowne
 
Droidcon 2013 france - The Growth of Android in Embedded Systems
Droidcon 2013 france - The Growth of Android in Embedded SystemsDroidcon 2013 france - The Growth of Android in Embedded Systems
Droidcon 2013 france - The Growth of Android in Embedded SystemsBenjamin Zores
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphoneChris Simmonds
 
Evaluating iOS Applications
Evaluating iOS ApplicationsEvaluating iOS Applications
Evaluating iOS Applicationsiphonepentest
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Androidoverview 100405150711-phpapp01
Androidoverview 100405150711-phpapp01Androidoverview 100405150711-phpapp01
Androidoverview 100405150711-phpapp01Santosh Sh
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Designing Secure Mobile Apps
Designing Secure Mobile AppsDesigning Secure Mobile Apps
Designing Secure Mobile AppsDenim Group
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopOpersys inc.
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowKarim Yaghmour
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopOpersys inc.
 

Ähnlich wie Fast-paced Introduction to Android Internals (20)

Enterprise iPad Development Without Notes
Enterprise iPad Development Without NotesEnterprise iPad Development Without Notes
Enterprise iPad Development Without Notes
 
Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA
 
Bringing Government and Enterprise Security Controls to the Android Endpoint
Bringing Government and Enterprise Security Controls to the Android EndpointBringing Government and Enterprise Security Controls to the Android Endpoint
Bringing Government and Enterprise Security Controls to the Android Endpoint
 
Android ppt
Android ppt Android ppt
Android ppt
 
Android Applications
Android ApplicationsAndroid Applications
Android Applications
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android
AndroidAndroid
Android
 
Android Seminar BY Suleman Khan.pdf
Android Seminar BY Suleman Khan.pdfAndroid Seminar BY Suleman Khan.pdf
Android Seminar BY Suleman Khan.pdf
 
CNIT 128 Ch 4: Android
CNIT 128 Ch 4: AndroidCNIT 128 Ch 4: Android
CNIT 128 Ch 4: Android
 
Droidcon 2013 france - The Growth of Android in Embedded Systems
Droidcon 2013 france - The Growth of Android in Embedded SystemsDroidcon 2013 france - The Growth of Android in Embedded Systems
Droidcon 2013 france - The Growth of Android in Embedded Systems
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphone
 
Evaluating iOS Applications
Evaluating iOS ApplicationsEvaluating iOS Applications
Evaluating iOS Applications
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Androidoverview 100405150711-phpapp01
Androidoverview 100405150711-phpapp01Androidoverview 100405150711-phpapp01
Androidoverview 100405150711-phpapp01
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Designing Secure Mobile Apps
Designing Secure Mobile AppsDesigning Secure Mobile Apps
Designing Secure Mobile Apps
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with Lollipop
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with Lollipop
 

Kürzlich hochgeladen

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 

Kürzlich hochgeladen (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Fast-paced Introduction to Android Internals

  • 1. CONFIDENTIAL. ALL RIGHTS RESERVED. Optio is a subsidiary of Allied Minds, an innovative U.S. science and technology development and commercialization company. Operating since 2006, Allied Minds forms, funds, manages and builds products and businesses based on innovative technologies developed at leading U.S. universities and federal research institutions. Allied Minds serves as a diversified holding company that supports its businesses and product development with capital, central Hamilton Turner Oct 2015 1 Fast-paced Introduction to Android Internals
  • 2. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 $ whoami 2 @hamiltont @hamiltont • Director of Malware Research, OptioLabs – Machine Learning, Data Science, Penetration Testing, and Malware Prevention • Doctorate in Computer Engineering – Mobile & Cloud Computing, Distributed Software Engineering, Security & Privacy • Heavy contributor to open source software • Android framework hacker for ~4 years
  • 3. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 $ who…are we 3 and now a brief message from our sponsors OptioLabs – Mobile security company founded in 2011 – Caters to Government, Enterprise, and Mobile Carriers/Manufacturers – Founders Dr. Charles Clancey, Dr. Jules White, Dr. Brian Dougherty – Offices in Baltimore & Nashville – Our OptioCore product increases Android security and enables legal compliance with numerous regulations – Recent news: • AMD and OptioLabs partner to increase enterprise security • Rugged Meets Secure: OptioCore Powers Sonim XP7 www.optiolabs.com
  • 4. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 $ who…are we 4 We are hiring! Mobile Developer (Application & Framework) Server Developer (Backend & Frontend) DevOps Send resumes to our VP of Engineering www.optiolabs.com Andy Meister andy.meister@optiolabs.com
  • 5. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Slide Set EULA • Android is….. – A capital-B Big project – A complex project – Changing rapidly – Different on each physical product • This presentation is….. – not comprehensive – probably not fully correct – already outdated • Go explore yourself! • Please let me know when you find something wrong with this slide deck 5
  • 6. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 What does it mean to be ‘Android’? • Android is a (loosely) protected term! – AOSP is all the open source code – Stock ROM is what manufacturer ships – Vanilla is very close to AOSP – Android is ROM that passed Android Compatibility • Android Compatibility – Different for each version of Android – 3 main parts • Compatibility Test Suite (automated tests) • Compatibility Verifier (human tests) • Compatibility Definition Doc (manual) • Android + Google Mobile Services (GMS) – Google Play! Maps! YouTube! Gmail! – All these are not open source and require a license agreement with Google if you want to sell a device that comes with these https://source.android.com/compatibility/index.html 6
  • 7. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Is Android really Open Source? ~90% of development is behind closed doors – Only Google&partners see source code – Only Google&partners accept (or ignore/deny) patches • Google is both the KeyMaster and the Architect – Very few public discussions occur on AOSP design principles – No public roadmap of features – However…. • Google accepts huge responsibility for standardization & long term stability of platform • Major contributions to upstream Linux kernel • Huge money influx for PR releases, OEM standardization efforts, etc “Open source is different than a community-driven project. Android is light on the community-driven side and heavy on the open source. Everything we do ends up in the open source repository.” - Andy Rubin, Cofounder of Android Inc, SVP@Google until 2013 See https://source.android.com/source/code-lines.html#about-private-code-lines 7
  • 8. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Super basic legality of Android • Pre-note: I am not a lawyer. This slide is extremely simplified for explanation purposes and there is therefore incorrect by design • Google is very careful to minimize “threats” to parties interested in modifying AOSP – Actively avoids using components that require ‘derived works’ to be open sourced • E.g. heavy modders are very familiar with the busybox install process ;-) • Why Android doesn’t come with the well-tested, POSIX correct glibc? – Actively avoids using components that *might, possibly* require licensing fees or agreements • Apache Harmony vs Oracle (sun) Java – see https://en.wikipedia.org/wiki/Oracle_America,_Inc._v._Google,_Inc. • When modifying Android, you should take a strong interest in the software licenses! – Smartphone IP is extremely valuable and heavily protected – see https://en.wikipedia.org/wiki/Smartphone_patent_wars 8 Component License Android applications Up to developer GSM App suite AOSP External libraries Apache 2 BSD, misc Android Kernel GPLv2 Bootloader ???
  • 9. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android • Often explained using the stack on the right 9
  • 10. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android • Or these… 10 http://blogs.freescale.com/mcus/2010/05/android-makes-the-move-to-power-architecture-technology/ http://www.techdesignforums.com/edasource/images/68/esd1004_mentor1_large.jpg
  • 11. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android, Simplified 11 http://blogs.freescale.com/mcus/2010/05/android-makes-the-move-to-power-architecture-technology/ http://www.techdesignforums.com/edasource/images/68/esd1004_mentor1_large.jpg
  • 12. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android • The running software stack is critically important to understand – However, the build system is quite obtuse – And documentation is sparse & scattered – One of your big challenges will be mapping running code to • Source code • Android filesystem • Always be on the lookout for the ‘bigger picture’ – All 5 of these are representations of ‘Android’ – Of the docs you can find, 90% will be on the software stack – 10% will be on the source code – The rest is up to you
  • 13. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Filesystem of Android device • Roughly derived from standard linux filesystem – See https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard – Uses ramdisk, /sbin, /sys, /dev (sometimes) • Android adds multiple root folders – /data, /system, /cache – These are basically an Android filesystem Hierarchy • Build system enforces this consistent hierarchy – Many of the FHS folders are symlinks • E.g. /etc  /system/etc – Just enough of a linux filesystem to run a kernel and some helpful functions • Heavy use of partitions – Reliable update mechanisms are easier with multiple bootable partitions – Updates can be made smaller 13
  • 14. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Filesystem Partitions • System – Android OS – Preinstalled APKs – Shared libraries – Executables • Userdata – User data, user apps – App-specific data folders – Backups – Dalvik caches – Crash information – Encrypted and/or persistent system data • Cache – Simple writable, always trashable partition • Recovery, Boot – Not first-class citizens while AOSP is running! 14
  • 15. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Filesystem Partitions • Adding main symlinks – /etc, /tombstones, /vendor • Note: Some phones have distinct vendor.img partition 15
  • 16. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Filesystem Partitions • Interactions with Kernel • /dev is tmpfs – Android uses udev (ueventd) to fill /dev • /acct is used by cgroups – CPU, Memory, DiskIO accounting and limiting • /proc and /sys are standard linux mechanisms for userspace and kernel interaction 16
  • 17. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Useful tooling: Android shell • Android uses MirBSD Korn shell (since 4.0 ICS) • Utilities – Gnu core utilities? GPL! – Busybox? GPL! • Android toolbox? BSD – See `ls –l /system/bin` – Emulates ~75 standard tools (ls, rm, rmdir, top, sleep) – See AOSP_ROOT/system/core/toolbox for source 17
  • 18. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Physical Android Architecture • Most Android phones have two processors – Mobile app processor – Mobile baseband processor – Communication using interrupts – Which one ‘leads’? – Frequently on same Soc • Sensors/USB/Screen/modem – Sometimes on SoC, sometimes connected externally 18
  • 19. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Physical Android Hardware: Sensors • General problem: sensors normally require proprietary code – To be business-friendly, AOSP tries very hard to avoid GPL-ing someone’s sensor code – This unfortunately means that hardware access is *not* done using one standard mechanism • Access mechanisms: – /dev nodes (display, lights) – Shared library objects (touch, audio) – Sockets – Android HAL • Android specifies header files, manufacturer provides *.so files – D-Bus (until recently) 19
  • 20. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Acquiring Android Source Code • Google has comprehensive docs – https://source.android.com/source/downloading.html • AOSP uses git for version control – Git repositories become huge given too much time – AOSP has a lot of pieces (~450 different git repos) – Working with ~450 git repositories is a nightmare…. • Repo – Google tool to automate working across many git repos – Enable branch/fetch/status/etc in multiple git repositories with one command $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1 See https://source.android.com/source/build-numbers.html#source-code-tags-and-builds 20
  • 21. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Acquiring Android Source Code • In repo terms, each git repo is called a project • A project has – A remote (e.g. url) – A path – A name • Repo will clone your projects into ‘detached HEAD’ – aka anonymous branch – You should use `repo start <project name>` to do a git branch • Repo has a concept of project groups – Note the ‘notdefault’ group See https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt 21 <manifest> <remote name="aosp“ fetch="https://android. googlesource.com" /> <project path="packages/apps/Mms“ name="platform/packages/apps/Mms" /> … … <project path="prebuilts/eclipse-build-deps" name="platform/prebuilts/eclipse-build-deps" groups="notdefault,eclipse" /> </manifest> $ cat .repo/manifest.xml
  • 22. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Uploading Android Source Code • Doing code reviews across ~450 git repos is a pain! • Enter ‘gerrit’ – Google developed a code review website that is specific to AOSP modifications – Extremely structured process – Can be self-hosted – Integrated with ‘repo upload’ • Note: Your dev team does not have to use gerrit – You can use git directly to push code – Not quite as painless as ‘repo upload’, but you don’t have to setup/maintain/use gerrit 22
  • 23. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 23 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions
  • 24. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 24 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions You want to work with AOSP in any capacity
  • 25. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 25 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions You want to port AOSP to a really-small IoT kind of device
  • 26. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 26 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions You want to modify what it means to be ‘Dalvik’
  • 27. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 27 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions You want to add a new system service to Android
  • 28. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 28 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions You want to build a custom ROM to is AOSP with different images
  • 29. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code 29 abi C++ support for ABI art Android ART runtime, compiler, dex2oat, etc bionic Android C standard library bootable Android Recovery image (no bootloader) build Makefile-based AOSP build system dalvik Dalvik VM source code, dex format spec, libdex developers Source code examples development Resources for setting up dev environments. Config files, small scripts, USB drivers device Device-specific files and binaries docs Doxyfile for source.android.com external External projects used by AOSP frameworks Android core components hardware Android Hardware Abstraction Layer and hardware support kernel Precompiled kernel images with Android modifications libcore All java.* packages from Object.java down, as supplied by Apache Harmony libnativehelper Android wrapper to make JNI easier to work with ndk Native Development Kit source code & tools (for using C/C++ from APKs) out Build output directory. make clean ~= rm -rf out packages Stock Android apps, Input methods, content providers, etc pdk Platform Development Kit for OEMs to test upcoming AOSP versions prebuilts Binary (vs source) tools. SDK, qemu for emulator, clang, etc sdk Software Development Kit – eclipse, ADT, SdkManager, etc system Native components of Android that run on top of Linux tools Compilation and IDE tools – gradle files, Eclipse add-ons, Studio add-ons vendor OEM chipset binaries and device definitions You want to use a different Bluetooth stack
  • 30. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Navigating Android Source Code • godir is your friend! – It’s find and cd rolled into one command 30
  • 31. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Building Android Source Code • Use make! • I don’t know why that needed an entire slide… 31
  • 32. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Building Android Source Code 1. Setup computer See https://source.android.com/source/building.html 2. Setup your shell $ source build/envsetup.sh 3. Choose compile target $ lunch aosp_arm-eng 4. Compile – full compile takes hours $ make 5. Run emulator (or skip this and run on device instead) $ emulator 6. Flash device $ adb reboot-bootloader $ fastboot –w flashall 32
  • 33. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Building Android Source Code 1. Setup computer See https://source.android.com/source/building.html 2. Setup your shell $ source build/envsetup.sh 3. Choose compile target $ lunch aosp_arm-eng 4. Compile – full compile takes hours $ make 5. Run emulator (or skip this and run on device instead) $ emulator 6. Flash device $ adb reboot-bootloader $ fastboot –w flashall 33 What is this? How does this work?
  • 34. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Build System – High Level • AOSP has ~40k lines of makefiles under /build and /device – Important to grok the main points before diving in there! • Comparisons to standard projects using make – Uses ‘Android.mk’, not ‘Makefile’ – Heavy usage of ANDROID_* environment variables – All output (even intermediate) goes into ‘out’ folder • rm –rf out/ – Smallest buildable unit is a ‘module’ • Similar to standard make targets, but there are 1000s of these • While many ‘modules’ are named statically, even more are created dynamically! – For example, every module “foo” automatically gets an accompanying module “foo-clean” – Non-recursive build system • See http://aegis.sourceforge.net/auug97.pdf • See build/core/build-system.html – You never call gcc yourself! Multiple ‘build templates’ exist • Android application, shared library, static library, standalone executable, java library, prebuilt • Build templates enforce the Android filesystem layout • Accept “parameters” in the form of make variables (will default parameters if these variables are not set) 34
  • 35. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Build System – High Level To build a module: • Setup expected variables: LOCAL_PATH := $(call my-dir) LOCAL_MODULE_NAME := some_example • Then include the proper build template: include $(BUILD_JAVA_LIBRARY) The build template will read the variables you set, compile as expected (in this case, as expected for a java library), and place the intermediates and final output in the correct locations inside the out/ folder 35
  • 36. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Build System – High Level • Build system includes lots of ‘dark magic’ • Not recommended to just start writing an Android.mk – Find one that does what you want and modify it – Or you’ll have forgotten a variable • Look into build/core/ to find makefiles for each build template – All options listed at build/core/config.mk line ~75 – Missing variables are often set to default values 36
  • 37. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 What is lunch? • AOSP has many compile options – Set options with env variables or buildspec.mk – envsetup.sh defines functions to help set options using env variables – One helper is ‘lunch’ – “I’m having JellyBeans for lunch” • Just calling lunch presents a menu of the form: $TARGET_PRODUCT-$TARGET_BUILD_VARIANT 37
  • 38. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Build Targets • Target product ~= device + configuration – E.g. nexus 6 (aka shamu) – E.g. en keyboard/apps/tts – Device name is arbitrary • Example products – aosp_arm: AOSP default locale on Emulator – full_fugu: All locales on Nexus Player – aosp_shamu: AOSP default on Nexus 6 – See https://source.android.com/source/build- numbers.html • To build your own, take a look at the different AndroidProducts.mk and vendorsetup.sh scripts – See https://source.android.com/source/add- device.html 38
  • 39. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Build Variants & Type • Target_build_variant determines the default apps and settings – user: Include stuff plan user would want – userdebug: Include user stuff, and a few items/settings to make debugging easier – eng: Include userdebug stuff, user stuff, and item/settings an engineer might use • Target_build_type – You can set this to release or debug to change the settings of ConfigBuildFlags.DEBUG – This is used to enable/disable some extra logging in core system services 39
  • 40. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Building Android Source Code 1. Setup computer See https://source.android.com/source/building.html 2. Setup your shell $ source build/envsetup.sh 3. Choose compile target $ lunch aosp_arm-eng 4. Compile – full compile takes hours $ make 5. Run emulator (or skip this and run on device instead) $ emulator 6. Flash device $ adb reboot-bootloader $ fastboot –w flashall 40
  • 41. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Modifying a Single Module 1. Modify code $ gedit frameworks/base/core/java/com/android/internal/os/ZygoteInit.java 2. Compile that module Note: findmakefile function is helpful to discover the LOCAL_MODULE_NAME $ make framework 3. Rebuild the system.img file using special snod module $ make snod 4. Reflash $ adb reboot-bootloader $ fastboot –w flashall 41
  • 42. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Bootup (Roughly) Explained 42
  • 43. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android init.rc • Android uses it’s own language for the init files – Easy to understand – I recommend you read init.rc • Main primitives – service: names a command string execution. Distinct from other uses of word ‘service’ • Start with ‘start <servicename>’ • Can be grouped into ‘classes’ • Start class with ‘class_start <classname>’ – action: on some trigger, do this • Predefined actions – early-init, init, early-fs, fs, early-boot, boot • User-defined action: property setting changed – trigger: something happened • ‘on <trigger>’ defines an action to react • ‘trigger <triggername>’ fires the trigger • Location of init.rc files – In running system (e.g. in ramdisk) : /init.*rc – In build system: system/core/rootdir/*.rc and /device 43
  • 44. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Properties • OS-wide key-value properties – Not the same as Java properties – Not environment variables – Follow a hierarchy of naming • Use getprop and setprop tools – Note: There is actually a socket file, but its tricky to access • Setprop can be used to trigger actions in init.rc! – Start/stop native code – Set logging levels – Change properties that persist across boot 44
  • 45. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android Properties • Where do properties originally get set?! – Filesystem (/default.prop, /system/build.prop) – Init.rc files – Java code – SystemProperties.set – C++ code – property_set • Some properties are controlled by UID/GID permissions – E.g. ril.* properties can only be set by RADIO user • Special cases – ro.* is read-only. These can only be set once (normally at boot)! – persist.* properties are written to the filesystem and persist across reboots – ctl.* properties are not actually stored into the properties map. They enable you to start or stop an init.rc ‘service’ using the properties system • E.g. ‘ctl.start foobar’ would start service ‘foobar’ 45
  • 46. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 What’s a zygote? • At a native level, binary is called app_process • Encapsulates starting the Dalvik VM • Eases the use of JNI • Loads all Java libraries into itself • Is capable of being forked • Drastically speeds up creation of new, ready-to-go processes pre-loaded with the Dalvik VM and java libraries 46
  • 47. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android System Server • Note that only one bit of Android talks to the Hardware & Kernel • This is system server – Multiplexes access to single-user systems like the display – Does most of the complex book-keeping – Accepts remote messages from apps and acts on their behalf (e.g. send SMS) • Most ‘Android System Services’ run as a thread inside the system_server process – Although a number run as standalone apps with the persistent=true flag 47
  • 48. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Main Android Services • Some biggies: – WifiService – ActivityManagerService – PowerService – PackageManagerService – LocationManagerService • There are about ~90 more – Individually they are not too bad – Look in source code under frameworks/base/services – Don’t start with ActivityManager ;-) • Developers access these using Context.getSystemService • How does this all happen? 48
  • 49. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android IPC Architecture “In the Android platform, the binder is used for nearly everything thathappens across processes in the core platform.” - Dianne Hackborn, Android Framework Engineer @ Google - https://lkml.org/lkml/2009/6/25/3 I highly recommend: https://newcircle.com/s/post/1340/deep_dive_into_android_ipc_binder_framework_at_andevcon_iv 49
  • 50. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android IPC Basics • Android app calls into android.jar • In many places, android.jar wants to call some core framework service – Proxy software design pattern! • To send data through the Binder driver, you have to write data into a string – Marshalling/unmarshalling 50 https://i.stack.imgur.com /EkzyV.png
  • 51. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android IPC Basics • Android app calls into android.jar • In many places, android.jar wants to call some core framework service – Proxy software design pattern! • To send data through the Binder driver, you have to write data into a string – Marshalling/unmarshalling 51 https://i.stack.imgur.com/EkzyV.png
  • 52. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android IPC Basics • AIDL files are used to generate the Java source code for Proxy – Exactly the same as you can do in an Android application! • Very useful to read generated Proxy & Stub files 52 https://i.stack.imgur.com/EkzyV.png
  • 53. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Android: Files to Read • Some source code files are important enough to actually read… • Zygote, ZygoteInit • SystemServer • Init.rc 57
  • 54. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 How is Android not Linux? • ueventd vs udev – Check for devices showing up and populate /dev • Kernel changes! – Android Out of Memory (OOM) killer – Wakelocks – Binder RPC / IPC – Android’s Anonymous Shared Memory (ashmem) – Android Alarm (on top oc Linux’s Real time clock RTC) – Android’s ring logger mechamisms – Custom init.rc language – Active work to upstream most of these changes • https://events.linuxfoundation.org/images/stories/slides/abs2013_stultz.pdf • Android Upstreaming group - https://wiki.linaro.org/WorkingGroups/Kernel/AndroidUpstreaming • C standard library – Bionic vs glibc. Seems this is mainly for licensing reasons • User management (e.g. uid/gid mapping) – Linux uses UID/GID. Android uses these for apps, and manages users in the AOSP code • Hardware approach – Linux mainly uses /dev for hardware exposure – Android uses mostly shared object files 60
  • 55. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 Resources • Embedded Android – Really excellent for everything below the AOSP java code • New Android Book – – Good for Android AOSP code – E.g. ‘How does the PowerManager code work’ • Exploring SDK Add-ons – Very interesting talk covering some of the interaction between Google and OEMs – https://www.youtube.com/watch?v=1TY5rqyAyp4 • Deep Dive into Android IPC/Binder Framework at AnDevCon IV – Binder is critical to Android, more understanding == better! – https://newcircle.com/s/post/1349/andevcon_iv_video_presentations_android_devel opers – https://newcircle.com/s/post/1340/deep_dive_into_android_ipc_binder_framework_a t_andevcon_iv • Binder IPC talk – http://www.dre.vanderbilt.edu/~schmidt/cs282/PDFs/android-binder-ipc.pdf 61
  • 56. CONFIDENTIAL. ALL RIGHTS RESERVED.Oct 2015 $ who…are we 62 We are hiring! Mobile Developer (Application & Framework) Server Developer (Backend & Frontend) DevOps Send resumes to our VP of Engineering www.optiolabs.com Andy Meister andy.meister@optiolabs.com