You are on page 1of 62

An overview of the Android Mobile Platform

Brian Gupta & Nathan Freitas

Credits
Google Android team Patrick Brady (Google) IO http://
sites.google.com/site/io/anatomy-physiology-of-an-android

Jay Freeman (Saurik) - Debian port #android JesusFreke /Disconnect

What is Android?

Internal Architecture

The Linux Kernel in Android


Android is based on the Linux kernel Android is not Linux No native windowing system No glibc Does not include full set of standard linux
utilities

Kernel source at http://git.android.com

Why Linux kernel for Android ?


Great memory and process management Great permissions based security model Proven driver model Support for shared libraries Its already open source

Kernel Enhancements
Alarm Ashmem Binder Power Management Low memory killer Kernel debugger Logger

Kernel Enhancements: Binder


Driver to facilitate inter-process
communication

High performance through shared memory Per-process thread pool for processing
requests

Reference counting and mapping of object


references across processes

Synchronous calls between processes.

Binder in Action

Built on top of standard Linux power


management via wake locks

Kernel Enhancements: Power Management

More aggressive power manager Components make requests to keep power Supports different types of wake locks android.os.PowerManager

Libraries
Bionic Libc - custom libc implementation Function Libraries Native Servers Hardware Abstraction Libraries

Libraries: Bionic Libc


Custom libc implementation optimized for
embedded use

License BSD - Keeps GPL out of user space Size: loads in each process so it needs to be
small

Fast: limited CPU power (fast and small


pthread implementation)

Libraries: WebKit
Based on the open source WebKit browser Renders pages in full (desktop) mode Full CSS, JavaScript, DOM, Ajax support Single-column and Adaptive view rendering Really powerful

Libraries: Media Framework


Based on PacketVideo OpenCORE
platform

Supports standard audio, video and stills Support for hardware/software codecs

Libraries: SQLite
Light-weight transactional data store Back end for most platform data storage

Libraries: Flingers
Flingers are native servers that regulate all
the heavy lifting for System I/O

Surface Flinger Audio Flinger

Hardware Abstraction Layer


user space C/C++ library layer Standard interface that Android drivers
need to implement hardware interface

Separates Android platform logic from Plugabble : e.g. you can plug in OSS below

Dalvik Virtual Machine


Androids custom clean room
implementation virtual machine

provides application portability runs optimized le format (.dex) Java .class/.jar les converted into .dex at
build time

Supports multiple virtual machine


processes per VM

Core Libraries: Overview


Data Structures Utilities File access Network Access Graphics

http://developer.android.com/reference/packages.html

Core platform services


Activity manager Package manager Window manager Resource manager Content manager

Hardware Services
Telephony Location Bluetooth WiFi USB Sensor(s)

How Android boots

How Android boots: Init


Similar to linux based systems At startup the boot loader loads the linux
kernel and starts the init process

Runtime Walkthrough
USB Daemon (usbd) Android debug bridge Debugger Daemon Radio interface layer daemon

Runtime Walkthrough (2)


Initializes service manager Registers service manager as default

context manager for Binder service

Init and Zygote


Init process starts with the zygote process

a nascent process which strats the dalvik VM instance loads classes and listens on socket for request to spawn VMs Forks on request to create VM instances for managed processes Copy-on-write to maximize re-use and minimize footprint

Layer Interaction

App -> Runtime Service -> Lib App -> Runtime Service -> Native Service -> Lib App -> Runtime Service -> Native Daemon -> Lib

Android: Open Source Project

Open Source Licenses


GPL - Linux Kernel and modules, bluez BSD - Bionic Apache - almost everything else

Closed source Components



HTC RIL (radio interface) library and data les (this is glue between the telephony layer in android and the AT/QMI control channels provided via GPL kernel drivers) libhgl.so - Qualcomm/ati opengl ES library libqcamera.so - Qualcomm camera library akmd - software to process and adjust compass/accelerometer events Qualcomm h264 codec frontend (does some processing the dsp cannot do) frontend HW accel codec "Google apps" - Maps, Gmail, etc.

Project Status
Public vs private branches Repo, git and Gerrit Cupcake - development branch

http://source.android.com/roadmap/cupcake

Getting the source

http://source.android.com/download

Setting up your machine


Android development can be done on Ubuntu 32 bit (preferred) Ubuntu AMD64 MacOS X http://source.android.com/download

Setting up your machine (2)



Steps (at a glance) Non Android specic prereqs:

Install git and GPG for your platform JDK 5.0, update 12 or higher. The following packages: ex, bison, gperf, libsdl-dev, libesd0-dev, libwxgtk2.6-dev (optional), build-essential, zip, curl. You might also want Valgrind, a tool that will help you nd memory leaks, stack corruption, array bounds overows, etc. libreadline

Install repo script Create a working dir repo init, repo sync Build the code - "make"

How to get involved

Android Hardware

HTC Dream

G1 vs ADP1

Netbooks

Ports
Nokia Internet Tablets Sharp Zaurus HTC Models Kaiser,Vogue, Polaris, Titan, Raphael &
Diamond

OpenMoko FreeRunner

Application Development
Nathan Freitas

The Basics
with (or w/o)
Android 1.1 SDK r1 Eclipse IDE

http://developer.android.com

Hello, Android 1) 3)

2)

All the Tools Fit....


Android Emulator: A virtual mobile device that runs on your computer.You use the emulator to design, debug, and test your applications in an actual Android run-time environment. Android Development Tools Plugin (for the Eclipse IDE): The ADT plugin adds powerful extensions to the Eclipse integrated environment, making creating and debugging your Android applications easier and faster. If you use Eclipse, the ADT plugin gives you an incredible boost in developing Android applications. Hierarchy Viewer: The Hierarchy Viewer tool allows you to debug and optimize your user interface. It provides a visual representation of your layout's hierarchy of Views and a magnied inspector of the current display with a pixel grid, so you can get your layout just right. Draw 9-patch: The Draw 9-patch tool allows you to easily create a NinePatch graphic using a WYSIWYG editor. It also previews stretched versions of the image, and highlights the area in which content is allowed. Dalvik Debug Monitor Service (ddms): Integrated with Dalvik, the Android platform's custom VM, this tool lets you manage processes on an emulator or device and assists in debugging.You can use it to kill processes, select a specic process to debug, generate trace data, view heap and thread information, take screenshots of the emulator or device, and more. Android Debug Bridge (adb): The adb tool lets you install your application's .apk les on an emulator or device and access the emulator or device from a command line. You can also use it to link a standard debugger to application code running on an Android emulator or device. Android Asset Packaging Tool (aapt): The aapt tool lets you create .apk les containing the binaries and resources of Android applications. mksdcard: Helps you create a disk image that you can use with the emulator, to simulate the presence of an external storage card (such as an SD card).

Whats in an App?
Libraries Default Activity

Intents

Other Other Activities Other Activities Activities

Service Content Providers

Android Manifest

Drawable

Layouts

Values

Assets

Setting up the Manifest


<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.openideals.inaugreport" android:versionCode="1" android:versionName="1.0.0"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".InaugReportMainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.openideals.android.geo.LocationFinderActivity" android:label="@string/view_location_finder"/> <activity android:name=".ReportFormActivity" android:label="@string/view_report_form"/> <activity android:name="com.openideals.android.ui.InternalWebView" android:label="@string/internal_web_view" /> <activity android:name="com.openideals.android.geo.GeoRSSMapView" android:label="@string/geo_map_view" /> <uses-library android:name="com.google.android.maps" />

</application> </manifest>

Cong & Code Editing

Laying it All Out


<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollReportForm" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/inaug_report_no_seal_"> <LinearLayout android:id="@+id/layoutReportForm" android:label="Text Report" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="top" android:padding="6.0sp"> <TextView android:id="@+id/labelTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Title:"/> <EditText android:id="@+id/entryTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" /> <TextView android:id="@+id/labelReport" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:text="Your Report:"/>

Activity: Do Something!
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.reportform); ((Button)findViewById(R.id.btnReportFormSubmit)).setOnClickListener(this); ((Button)findViewById(R.id.btnReportFormCancel)).setOnClickListener(this); package com.openideals.inaugreport; import import import import import import import import import import import import import import import android.app.Activity; android.app.ProgressDialog; android.content.Intent; android.location.Location; android.os.Bundle; android.os.Handler; android.util.Log; android.view.View; android.view.View.OnClickListener; android.widget.ArrayAdapter; android.widget.Button; android.widget.CheckBox; android.widget.Spinner; android.widget.TextView; android.widget.Toast;

Toast.makeText(getBaseContext(), "There was a problem submitting your report. Wait a second, and then try again!", Toast.LENGTH_LONG).show();

import com.openideals.android.geo.LocationFinderActivity; import com.openideals.android.ui.HorizontalSlider; import com.openideals.android.ui.HorizontalSlider.OnProgressChangeListener;

private void showMain () { Intent iMain = new Intent(this, LocationFinderActivity.class); startActivity(iMain); }

DDMS Debugger

Launch the Emulator!

OpenIntents.org
Title Call Capture an image Check for Update Connect host Create shortcut Delete data Dial a number Edit data Edit title Encode Environmental measurement Flickr photo Flickr stream Get content Insert data List all applications Main Pick data Pick directory Pick le Record sound Resolve unresolved intents Ringtone picker Scan Search Search book contents Send a message to the given uri Send data to someone Send Twitter Message Set wallpaper Share (through QR code) Show about dialog Show radar Tag data View data Web search Action android.intent.action.CALL android.media.action.IMAGE_CAPTURE org.openintents.intents.CHECK_VERSION org.theb.ssh.action.CONNECT_HOST android.intent.action.CREATE_SHORTCUT android.intent.action.DELETE android.intent.action.DIAL android.intent.action.EDIT com.android.notepad.action.EDIT_TITLE com.google.zxing.client.android.ENCODE com.borntotinker.intent.action.MEASURE com.google.android.photostream.FLICKR_PHOTO com.google.android.photostream.FLICKR_STREAM android.intent.action.GET_CONTENT android.intent.action.INSERT android.intent.action.ALL_APPS android.intent.action.MAIN android.intent.action.PICK org.openintents.action.PICK_DIRECTORY org.openintents.action.PICK_FILE android.provider.MediaStore.RECORD_SOUND org.openintents.intents.UNRESOLVED_INTENT Description Perform a call to someone specied by the data. An application implementing this intent protocol allows the user to capture an image. Preliminary protocol until Market improves update facitilities! Connect to a host. Creates a shortcut on the main screen. Delete the given data from its container. Dial a number as specied by the data. Provide explicit editable access to the given data. Edit the title of a content. Encode to barcode and display on screen. An open ended intent to collect information from the android phone's surroundings. Show a ickr photo. Display a Flickr stream. Allow the user to select a particular kind of data and return it. Insert an empty item into the given container. List all available applications. Start as a main entry point, does not expect to receive data. Pick an item from the data, returning what was selected. Pick a directory (folder) through a le manager. Pick a le through a le manager. Start SoundRecorder application to record sound.

Delegates the user to a selection of possible applications that can resolve the given intent. android.intent.action.RINGTONE_PICKER Show a ringtone picker. com.google.zxing.client.android.SCAN Scan a barcode. android.intent.action.SEARCH Perform a search. com.google.zxing.client.android.SEARCH_BOOK_CONTENTS Use Google Book Search to search the contents of the book provided. android.intent.action.SENDTO Send a message to someone specied by the data. android.intent.action.SEND Deliver some data to someone else. com.twidroid.SendTweet Send a Twitter/Identi.ca Message thru Twidroid. android.intent.action.SET_WALLPAPER Show settings for choosing wallpaper com.google.zxing.client.android.SHARE Display an item as QR code to scan with a phone. org.openintents.action.SHOW_ABOUT_DIALOG com.google.android.radar.SHOW_RADAR org.openintents.action.TAG android.intent.action.VIEW android.intent.action.WEB_SEARCH Show an about dialog to display information about your application. Display a radar like view centered around the current position and mark the given location Add a tag to the given data. Display the data to the user. Perform a web search.

Geo Report App

GeoMapping Results

PhoneGap webOS

PhoneGap is a development tool that allows web developers to take advantage of the core features in the iPhone, Android, and Blackberry SDK using JavaScript.

Nathan Freitas nathan@olivercoady.com blog: openideals.com consulting: olivercoady.com

Application Development

Phone Hacking

Getting root
By getting root you can update the bootloader and install custom rmware

Why custom rmware?



Include bug xes from git source Phone tethering hack Multi-touch hack Install Debian userspace busybox + lots of commands added a /system/etc/ resolv.conf le with the 4.2.2 family of DNS servers, to allow busybox's ping, wget, etc. to resolve host names

add useful kernel modules (ext2, cifs, ++) unionfs Phone backup utility Change splash screen Custom compiled rmware added a modied /system/ etc/security/cacerts.bks le, which contains additional certicates for cacert.org (courtesy of Disconnect)

Getting and installing custom rmware


Look for the latest JesusFreke custom rmware

Building custom rmware


Jesus Freke's instructions here: http://forum.xda-developers.com/
showthread.php?t=466174

Jesus Freke's latest build environment here: http://jf.andblogs.net/2009/02/11/jfv143/

Installing Debian on the G1

Jay Freeman's (Saurik) instructions: http://www.saurikurik.com/id/10

Resources

FAQ http://tinyurl.com/ androidfaq IRC

Text

Android New York City: #androidnyc@irc.freenode .net

General Android: #android@irc.freenode.net Android application development: #androiddev@irc.freenode.net Android hacking: #android@irc.saurik.net

Mailing lists

http://code.google.com/ android/groups.html AndroidNYC Meetup http://www.meetup.com/ androidnyc

My email: Brian.gupta@brandorr.com

You might also like