Core Android

39
Dominik Helleberg | inovex GmbH Core Android

description

In dieser Session werfen wir einen Blick auf die Android Platform jenseits der Dalvik VM. Wir entdecken den Android Source Code und erklären wo sich interessante Beispiele und Referenzen für App-Entwickler sowie nützliche Tools verbergen. Ein High-Level Überblick über die Platform-Architektur und das Platform-Build-System runden die Session ab.

Transcript of Core Android

Page 1: Core Android

Dominik Helleberg | inovex GmbH

Core Android

Page 2: Core Android

Dominik Helleberg

Mobile Development

Android

HTML5

http://dominik-helleberg.de/+

Page 3: Core Android

Core Android

Page 4: Core Android

Warum?

Neugier

Verständnis

- Bugs

- Beispiele

- Doku

Anwendungen / Projekte

http://www.ouya.tv/about/ https://mediacenter.motorola.com/Image-Gallery/MOTOACTV-Golf-Edition-8c1.aspx http://www.tolino.de https://www.honeywellaidc.com/en-US/resources/image-library/Pages/default.aspx?Category=7800&keywords=7800&title=7800&description=7800

Page 5: Core Android

Android is different…

Page 6: Core Android

Android is open?

https://twitter.com/Arubin/status/27808662429

Page 7: Core Android

Android Architektur Stock Apps

Framework / API

User Apps

Java System Services

Dalvik / Runtime / Zygote

Kernel

Libs HAL Init

Page 8: Core Android

Android Architektur / Source Stock Apps

Framework / API

User Apps

Java System Services

Dalvik / Runtime / Zygote

Kernel

Libs Init

https://android.googlesource.com/ HAL

Page 9: Core Android

Get the source! $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo

$ chmod a+x ~/bin/repo

$ repo init -u https://android.googlesource.com/platform/manifest

$ repo sync

Check: http://source.android.com

Sources: approx. 16 GB

Page 10: Core Android

Getting around AOSP abi

bionic

bootable

build

cts

dalvik

development

device

docs

external

frameworks

gdk

hardware

libcore

libnativehelper

ndk

packages

pdk

prebuilts

sdk

system

tools

Page 11: Core Android

Getting around AOSP abi

bionic

bootable

build

cts

dalvik

development

device

docs

external

frameworks

gdk

hardware

libcore

libnativehelper

ndk

packages

pdk

prebuilts

sdk

system

tools

android core Framework

icons

Stock Apps IMEs

Wallpapers..

The.... S D K

Page 12: Core Android

packages

Calendar

Contacts

Gallery2

Launcher2

Page 13: Core Android

Framework base/core/java/android/app/ActivityManager.java

base/core/java/android/widget/RelativeLayout.java

base/packages/SystemUI/res/*

base/core/res/res/*

base/core/java/android/os/PowerManager.java

Page 14: Core Android

sdk

bash_completion/adb.bash

screenshot/

Page 15: Core Android

Compile...

You need:

•  Ubuntu LTS (10.04) or Mac OS X

•  A bunch of tools

•  HDD space (~ 30 GB)

•  Time (Hours - depending on your HW)

Page 16: Core Android

Compile... $ source build/envsetup.sh

including device/generic/armv7-a-neon/vendorsetup.sh

including device/generic/armv7-a/vendorsetup.sh

....

Page 17: Core Android

Compile... $ lunch

You're building on Linux

Lunch menu... pick a combo:

1. full-eng

2. full_x86-eng

3. vbox_x86-eng

4. full_mips-eng

5. full_grouper-userdebug

...

Which would you like? [full-eng]

Page 18: Core Android

zzzzzZZZZZZzzzzzz

Page 19: Core Android

device mappings crespo Samsung Nexus S

manta Samsung Nexus 10

mako LG Nexus 4

grouper / tilapia Asus Nexus 7

toro / maguro Samsung Galaxy Nexus

wingray Motorola Xoom

Page 20: Core Android

…zzZZZzz… and run! $ emulator &

Page 21: Core Android

…zzZZZzz… and run!

Page 22: Core Android

Architecture by example - GPS Stock Apps

Framework / API

User Apps

Java System Services

Dalvik / Runtime / Zygote

Kernel

Libs HAL Init

Page 23: Core Android

Architecture by example - GPS Stock Apps User Apps

locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

locationManager.requestLocationUpdates(

LocationManager.GPS_PROVIDER, 0, 0, locationListener);

Page 24: Core Android

frameworks/base/location/java/android/location/LocationManager.java

try { mService.requestLocationUpdates(request,

transport, intent, packageName); } catch (RemoteException e) { Log.e(TAG, "RemoteException", e); }

Architecture by example - GPS

Framework / API System Services

Page 25: Core Android

frameworks/base/location/java/android/location/LocationManager.java

private final ILocationManager mService;

Architecture by example - GPS

Framework / API System Services

Page 26: Core Android

frameworks/base/location/java/android/location/ILocationListener.aidl

void requestLocationUpdates( in LocationRequest request, in ILocationListener listener, in PendingIntent intent, String packageName);

Architecture by example - GPS

Framework / API System Services

Page 27: Core Android

frameworks/base/services/java/com/android/server/LocationManagerService.java

LocationProviderInterface provider =

mProvidersByName.get(name);...provider.setRequest(providerRequest,

worksource);

Architecture by example - GPS

Framework / API System Services

Page 28: Core Android

frameworks/base/services/java/com/android/server/location/GpsLocationProvider.java

private native boolean native_start();

Architecture by example - GPS

Framework / API System Services

Page 29: Core Android

hardware/libhardware/include/hardware/gps.h

/** Represents the standard GPS interface. */typedef struct { int (*init)( GpsCallbacks* callbacks );

/** Starts navigating. */ int (*start)( void );...

Architecture by example - GPS

Libs HAL Init

Page 30: Core Android

development/tools/emulator/system/gps/gps_qemu.c

device/samsung/manta/gps/gps.exynos5.so

Architecture by example - GPS

Libs HAL Init

Page 31: Core Android

What’s next? Tips + Tricks •  Level 1:

Check source for samples and understanding

•  Level 2:

Compile your own emulator images

•  Level 3:

Get a supported nexus device and burn images

•  Level 4:

Get a development board an build android embedded Software

Page 32: Core Android

Level 1: grep $ jgrep LocationManager ./base/core/java/android/app/ContextImpl.java:60:import android.location.ILocationManager; ./base/core/java/android/app/ContextImpl.java:61:import android.location.LocationManager; ./base/core/java/android/app/ContextImpl.java:403: return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); ./base/core/java/android/content/Context.java:1749: * <dd> A {@link android.location.LocationManager} for controlling location ./base/core/java/android/content/Context.java:1795: * @see android.location.LocationManager ./base/core/java/android/content/Context.java:1912: * android.location.LocationManager} for controlling location ./base/core/java/android/content/Context.java:1916: * @see android.location.LocationManager ./base/core/java/android/provider/Settings.java:3096: * LocationManager service for testing purposes during application development. These ./base/core/java/android/webkit/GeolocationService.java:23:import android.location.LocationManager; ./base/core/java/android/webkit/GeolocationService.java:39: private LocationManager mLocationManager; ./base/core/java/android/webkit/GeolocationService.java:54: mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); ./base/core/java/android/webkit/GeolocationService.java:55: if (mLocationManager == null) { ./base/core/java/android/webkit/GeolocationService.java:118: if (LocationManager.NETWORK_PROVIDER.equal ....

Page 33: Core Android

Level 1: AndroidXRef

http://androidxref.com/

Page 34: Core Android

Level 1: explain-plz

https://github.com/timroes/explain-plz

@local:/Volumes/android/dalvik $ explain-plz Explanation for folder dalvik: This directory contains the Dalvik virtual machine and core class library, as well as related tools, libraries, and tests. Git project directory: dalvik Git fetch URL: https://android.googlesource.com/platform/dalvik Subfolders with explanation: dexdump dexgen dx opcode-gen tools/hprof-conv vm

Page 35: Core Android

Level 2: ccache $ export USE_CCACHE=1 $ export CCACHE_DIR=/<path_of_your_choice>/.ccache $ prebuilts/misc/linux-x86/ccache/ccache -M 50G The suggested cache size is 50-100G. You can watch ccache being used by doing the following: $ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s

http://source.android.com/source/building.html

Page 36: Core Android

Level 3

Page 37: Core Android

Level 4

https://android-build.linaro.org/

Page 38: Core Android

Credits http://www.ouya.tv/about/ https://mediacenter.motorola.com/Image-Gallery/MOTOACTV-Golf-Edition-8c1.aspx http://www.tolino.de https://www.honeywellaidc.com/en-US/resources/image-library/Pages/default.aspx?Category=7800&keywords=7800&title=7800&description=7800 https://android-build.linaro.org/ http://source.android.com/source/building.html

Page 39: Core Android

DANKE!