Top Banner
An overview of the Android Mobile Platform Brian Gupta & Nathan Freitas
62

An Introduction To Android

May 06, 2015

Download

Technology

natdefreitas

Presented by Brian Gupta ([email protected]) and Nathan Freitas ([email protected])

Learn more at http://tinyurl.com/androidfaq

Android is a fully integrated and open source bundle of software significantly lowers the current costs of developing mobile devices (currently runs on a cellphone (the HTC Dream/T-Mobile G1), and a number of unofficial "ports". It consists of an operating system, middleware, a user-friendly interface and powerful applications.

The talk will start with a review of the internal architecture of the Android platform, breaking down the various components, and examine how they work. Then we will review the latest status of the open source project, including how to get and build the source code, and how to get involved.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An Introduction To Android

An overview of the Android Mobile Platform

Brian Gupta & Nathan Freitas

Page 3: An Introduction To Android

What is Android?

Page 4: An Introduction To Android

Internal Architecture

Page 5: An Introduction To Android

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

Page 6: An Introduction To Android

Why Linux kernel for Android ?

• Great memory and process management

• Great permissions based security model

• Proven driver model

• Support for shared libraries

• It’s already open source

Page 7: An Introduction To Android

Kernel Enhancements

• Alarm

• Ashmem

• Binder

• Power Management

• Low memory killer

• Kernel debugger

• Logger

Page 8: An Introduction To Android

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.

Page 9: An Introduction To Android

Binder in Action

Page 10: An Introduction To Android

Kernel Enhancements: Power Management

• Built on top of standard Linux power management

• More aggressive power manager

• Components make requests to keep power via “wake locks”

• Supports different types of wake locks

• android.os.PowerManager

Page 11: An Introduction To Android

Libraries

• Bionic Libc - custom libc implementation

• Function Libraries

• Native Servers

• Hardware Abstraction Libraries

Page 12: An Introduction To Android

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)

Page 13: An Introduction To Android

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

Page 14: An Introduction To Android

Libraries: Media Framework

• Based on PacketVideo OpenCORE platform

• Supports standard audio, video and stills

• Support for hardware/software codecs

Page 15: An Introduction To Android

Libraries: SQLite

• Light-weight transactional data store

• Back end for most platform data storage

Page 16: An Introduction To Android

Libraries: Flingers

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

• Surface Flinger

• Audio Flinger

Page 17: An Introduction To Android

Hardware Abstraction Layer

• user space C/C++ library layer

• Standard interface that Android drivers need to implement

• Separates Android platform logic from hardware interface

• Plugabble : e.g. you can plug in OSS below

Page 18: An Introduction To Android

Dalvik Virtual Machine

• Android’s custom clean room implementation virtual machine

• provides application portability

• runs optimized file format (.dex)

• Java .class/.jar files converted into .dex at build time

• Supports multiple virtual machine processes per VM

Page 19: An Introduction To Android

Core Libraries: Overview

• Data Structures

• Utilities

• File access

• Network Access

• Graphics

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

Page 20: An Introduction To Android

Core platform services

• Activity manager

• Package manager

• Window manager

• Resource manager

• Content manager

Page 21: An Introduction To Android

Hardware Services

• Telephony

• Location

• Bluetooth

• WiFi

• USB

• Sensor(s)

Page 22: An Introduction To Android

How Android boots

Page 23: An Introduction To Android

How Android boots: Init

• Similar to linux based systems

• At startup the boot loader loads the linux kernel and starts the init process

Page 24: An Introduction To Android

Runtime Walkthrough

• USB Daemon (usbd)

• Android debug bridge

• Debugger Daemon

• Radio interface layer daemon

Page 25: An Introduction To Android

Runtime Walkthrough (2)

• Initializes service manager

• Registers service manager as default context manager for Binder service

Page 26: An Introduction To Android

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 VM’s

• Forks on request to create VM instances for managed processes

• Copy-on-write to maximize re-use and minimize footprint

Page 27: An Introduction To Android

Layer Interaction

• App -> Runtime Service -> Lib

• App -> Runtime Service -> Native Service -> Lib

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

Page 28: An Introduction To Android

Android: Open Source Project

Page 29: An Introduction To Android

Open Source Licenses

• GPL - Linux Kernel and modules, bluez

• BSD - Bionic

• Apache - almost everything else

Page 30: An Introduction To Android

Closed source Components

• HTC RIL (radio interface) library and data files (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.

Page 31: An Introduction To Android

Project Status

• Public vs private branches

• Repo, git and Gerrit

• Cupcake - development branch

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

Page 32: An Introduction To Android

Getting the source

• http://source.android.com/download

Page 33: An Introduction To Android

Setting up your machine

• Android development can be done on

• Ubuntu 32 bit (preferred)

• Ubuntu AMD64

• MacOS X

• http://source.android.com/download

Page 34: An Introduction To Android

Setting up your machine (2)

• Steps (at a glance)

• Non Android specific prereqs:

• Install git and GPG for your platform

• JDK 5.0, update 12 or higher.

• The following packages: flex, 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 find memory leaks, stack corruption, array bounds overflows, etc.

• libreadline

• Install repo script

• Create a working dir

• repo init, repo sync

• Build the code - "make"

Page 35: An Introduction To Android

How to get involved

Page 36: An Introduction To Android

Android Hardware

Page 37: An Introduction To Android

HTC Dream

G1 vs ADP1

Page 38: An Introduction To Android

Netbooks

Page 39: An Introduction To Android

Ports

• Nokia Internet Tablets

• Sharp Zaurus

• HTC Models

• Kaiser, Vogue, Polaris, Titan, Raphael & Diamond

• OpenMoko FreeRunner

Page 40: An Introduction To Android

Application Development

Nathan Freitas

Page 41: An Introduction To Android

The Basics

Android 1.1 SDK r1

with(or w/o)

Eclipse IDE

http://developer.android.com

Page 42: An Introduction To Android

Hello, Android

1)

2)

3)

Page 43: An Introduction To Android

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 magnified 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 specific 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 files 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 files 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).

Page 44: An Introduction To Android

What’s in an App?

Drawable Layouts Values Assets

Android Manifest

DefaultActivity

OtherActivitiesOther

ActivitiesOtherActivities

Libraries

Service

ContentProviders

Intents

Page 45: An Introduction To Android

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>

Page 46: An Introduction To Android

Config & Code Editing

Page 47: An Introduction To Android

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_">

<LinearLayoutandroid: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:"/>

Page 48: An Introduction To Android

Activity: Do Something!package com.openideals.inaugreport;

import android.app.Activity;import android.app.ProgressDialog;import android.content.Intent;import android.location.Location;import android.os.Bundle;import android.os.Handler;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.CheckBox;import android.widget.Spinner;import android.widget.TextView;import android.widget.Toast;

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

}

/** 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); }

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

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

Page 49: An Introduction To Android

“DDMS” Debugger

Page 50: An Introduction To Android

Launch the Emulator!

Page 51: An Introduction To Android

Title Action DescriptionCall android.intent.action.CALL Perform a call to someone specified by the data.Capture an image android.media.action.IMAGE_CAPTURE An application implementing this intent protocol allows the user

to capture an image.Check for Update org.openintents.intents.CHECK_VERSION Preliminary protocol until Market improves update facitilities!Connect host org.theb.ssh.action.CONNECT_HOST Connect to a host.Create shortcut android.intent.action.CREATE_SHORTCUT Creates a shortcut on the main screen.Delete data android.intent.action.DELETE Delete the given data from its container.Dial a number android.intent.action.DIAL Dial a number as specified by the data.Edit data android.intent.action.EDIT Provide explicit editable access to the given data.

Edit title com.android.notepad.action.EDIT_TITLE Edit the title of a content.Encode com.google.zxing.client.android.ENCODE Encode to barcode and display on screen.Environmental measurement com.borntotinker.intent.action.MEASURE An open ended intent to collect information from the android

phone's surroundings.Flickr photo com.google.android.photostream.FLICKR_PHOTO Show a flickr photo.Flickr stream com.google.android.photostream.FLICKR_STREAM Display a Flickr stream.Get content android.intent.action.GET_CONTENT Allow the user to select a particular kind of data and return it.Insert data android.intent.action.INSERT Insert an empty item into the given container.List all applications android.intent.action.ALL_APPS List all available applications.Main android.intent.action.MAIN Start as a main entry point, does not expect to receive data.Pick data android.intent.action.PICK Pick an item from the data, returning what was selected.

Pick directory org.openintents.action.PICK_DIRECTORY Pick a directory (folder) through a file manager.Pick file org.openintents.action.PICK_FILE Pick a file through a file manager.Record sound android.provider.MediaStore.RECORD_SOUND Start SoundRecorder application to record sound.

Resolve unresolved intents org.openintents.intents.UNRESOLVED_INTENT Delegates the user to a selection of possible applications that can resolve the given intent.

Ringtone picker android.intent.action.RINGTONE_PICKER Show a ringtone picker.Scan com.google.zxing.client.android.SCAN Scan a barcode.Search android.intent.action.SEARCH Perform a search.Search book contents com.google.zxing.client.android.SEARCH_BOOK_CONTENTS Use Google Book Search to search the contents of the book

provided.Send a message to the given uri android.intent.action.SENDTO Send a message to someone specified by the data.Send data to someone android.intent.action.SEND Deliver some data to someone else.Send Twitter Message com.twidroid.SendTweet Send a Twitter/Identi.ca Message thru Twidroid.Set wallpaper android.intent.action.SET_WALLPAPER Show settings for choosing wallpaperShare (through QR code) com.google.zxing.client.android.SHARE Display an item as QR code to scan with a phone.

Show about dialog org.openintents.action.SHOW_ABOUT_DIALOG Show an about dialog to display information about your application.

Show radar com.google.android.radar.SHOW_RADAR Display a radar like view centered around the current position and mark the given location

Tag data org.openintents.action.TAG Add a tag to the given data.View data android.intent.action.VIEW Display the data to the user.Web search android.intent.action.WEB_SEARCH Perform a web search.

OpenIntents.org

Page 52: An Introduction To Android

Geo Report App

Page 53: An Introduction To Android

GeoMapping Results

Page 54: An Introduction To Android

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.

Page 55: An Introduction To Android

Application Development

Nathan [email protected]

blog: openideals.comconsulting: olivercoady.com

Page 56: An Introduction To Android

Phone Hacking

Page 57: An Introduction To Android

Getting rootBy getting root you can update the bootloader and

install custom firmware

Page 58: An Introduction To Android

Why custom firmware?

• Include bug fixes from git source

• Phone tethering hack

• Multi-touch hack

• Install Debian userspace

• busybox + lots of commands

• added a /system/etc/resolv.conf file 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 firmware

• added a modified /system/etc/security/cacerts.bks file, which contains additional certificates for cacert.org (courtesy of Disconnect)

Page 59: An Introduction To Android

Getting and installing custom firmware

Look for the latest JesusFreke custom firmware

Page 60: An Introduction To Android

Building custom firmware

• 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/

Page 61: An Introduction To Android

Installing Debian on the G1

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