Android Overview

Marko Gargenta marakana.com

© 2011 About Marko Gargenta

Developer of Android Bootcamp for Marakana.

Instructor for 1,000s of developers on Android at Qualcomm, Cisco, Motorola, DoD and other great orgs.

Author of Learning Android published by O’Reilly.

Speaker at OSCON (3x), ACM, IEEE, SDC, AnDevCon.

Co-Founder of SFAndroid.org

Co-Chair of Android Open conference: AndroidOpen.com

© 2011 Agenda

• Android Then & Now • Hello World! • Android versions • Main Building Blocks • Android @Work • Architecng an App • The Stack • Android UI • Operang System Features • Android Security • Building Custom ROM • Summary

© 2011 ANDROID THEN & NOW

© 2011 History

2005 buys Android, Inc. Work on Dalvik starts 2007 Open Handset Alliance announced Early Soware Development Kit 2008 HTC G1 Announced SDK 1.0 Released 2009 G2 + 20 other phones released Cupcake, Donut, Éclair 2010 Zillion devices FroYo, Gingerbread, JIT 2011 Games, Tablets, TVs

Future? Beyond phones

© 2011 Today 45%

40%

35%

30% Android 25% Blackberry Apple iOS 20% Windows Palm 15% Symbian

10%

5%

0% Qtr2 2009 Qtr3 2009 Qtr4 2009 Qtr1 2010 Qtr2 2010

Android grows to 36% of US (Big 4) Smartphone Share, surpassing RIM – and growth will continue to accelerate over time

© 2011 And @Workplace

© 2011 Plaorm Versions Version API Level Nickname Android 1.0 1 Android Android 1.1 2 Android Android 1.5 3 Cupcake Android 1.6 4 Donut Android 2.0 5 Éclair Android 2.01 6 Éclair Android 2.1 7 Éclair Android 2.2 8 FroYo Android 2.3 9 Gingerbread Android 2.3.3 10 Gingerbread Android 3.0 11 Honeycomb Android X.X XX Ice cream

© 2011 Version Distribuon

Source: Android.com

© 2011 Historical Distribuon

Source: Android.com

© 2011 Add-Ons

SenseUI TouchWiz MotoBlur

© 2011 HTC Sense

Much improved UI. Completely new apps and widgets. Overall different feel: Tasks before Apps. A smart way of innovating on top of Android Open Source project. © 2011 Motorola Motoblur

New skin, new apps new widgets. All backed with an online service. Very social-centric.

© 2011 Samsung TouchWiz

More intuitive home screen, but real crown jewel is Swype.

© 2011 “With Google”

Devices that have “with Google” add-on feature a set of Google’s proprietary applications, such as Maps, , Gtalk, and many others.

OEMs and carriers typically enter into a licensing agreement with Google in order to distribute Google version of Android.

© 2011 Android Fragmentaon?

Android Compatibility Test Suite: Defines “Android Compatible” Prevents incompatible releases Provides self testing

Fragmentations lines include: - Versions of Android - Add-ons by OEMs/Carriers - Device capabilities

Best practices in app development eliminate these issues. CTS ensures compliance.

© 2011 Hardware Requirements • Must have a screen of any size. • Must have a so keyboard. Hardware keyword is oponal. • Must support touch screen input • Should have the following sensors: Accelerometer, Magnetometer, GPS, Gyroscope. • Should include WiFi, Bluetooth. Telephony oponal.

© 2011 Hardware Requirements (cont’d) • Should include Near Field Communicaon. • Must have some network capability. • Should have rear-facing camera. Front camera is oponal. • Memory must be: 125MB+ (system), 150MB+ (user data), 1GB+ (storage) • Must implement USB port.

© 2011 FroYo: Speed with JIT

• New User Features – Updated Home, Camera, Gallery, Portable hotspot – Support for Exchange (security, remote wipe, calendars, auto-discovery, global addresses) • New Plaorm Technologies – Media (hp/progressive streaming) and Bluetooth • New Developer Services and APIs – Cloud to Device Messaging – Apps on SDCard, media framework, graphics, backup, device manager, UI frameworks

© 2011 Gingerbread: Gaming New User Features • Updated user interface • Power management, app control • Download manager for long downloads • Storage manager for private content on sdcard • Improved power management and app control • Mulple camera support • Copy-paste features • Redesigned keyboard

© 2011 Gingerbread: Gaming New Developer Features • Performance improvements for gaming • Improved sensor support • Nave acvity support • Near-Field Communicaon (NFC) • WebM/VP8 playback and AAC encoding • SIP VoIP support • Support for extra-large screen (WXGA++) • Ext4 instead of yaffs file system

© 2011 HONEYCOMB

© 2011 Honeycomb: Tablets • Honeycomb is Tablet-opmized Android • As-is will not be supported on mobile phones • Currently two separate paths for Android • Source code likely won’t be available • Will merge in ice cream

© 2011 Honeycomb: Designed for Opmized for devices with larger screen sizes, parcularly tablets • Brand new, truly virtual and “holographic” 3d- like UI design • Elegant, content-focused interacon model • Support for mul-core devices • Hardware acceleraon

© 2011 Honeycomb: Android Wins Focus on Android strengths people love • Refined multasking • Rich noficaons • Home screen customizaon • Widgets • Video chat via

© 2011 Honeycomb: New UI New UI paradigms for interacon, navigaon, and customizaon • Extended set of UI objects • Powerful graphics • Media capabilies

© 2011 New UI Objects & Paradigms • System Bar, for global status and noficaons • Acon Bar, for applicaon control • Customizable Home screens • Recent Apps, for easy visual multasking

© 2011 Redesigned keyboard • Entering text faster and more accurate on larger screen • Reshaped and reposioned keys for improved targeng • New keys such as Tab • Touch-hold menus • Voice/keyboard input mode switching • Improved text selecon, copy and paste

© 2011 New connecvity opons • Built-in Media/Photo Transfer Protocol for fast USB connecon to cameras and computers • Support for external keyboard via USB or Bluetooth • Faster Wifi scanning • Bluetooth tethering so other devices can share network

© 2011 Updated set of standard apps • Browser – Mulple tabs – Incognito mode – Multouch support • Camera and Gallery – Redesigned for large screen – Time-lapse video recording – Full-screen Gallery

© 2011 Updated set of standard apps • Contacts – Two-pane UI and Fast Scroll to easily organize and locate contacts – Card-like UI for easier reading and eding of contacts – Improved support for internaonal number formats • Email – New two-pane UI for more efficient emailing – Sync aachments for later viewing

© 2011 ANDROID @WORK – A GOOGLE PERSPECTIVE

© 2011 CIO’s Consideraons • Security • Device Management • Apps

© 2011 Security • Protect against loss or the • Protect against intercepon • Employees are the weak link • Enforcement & crypto are key

© 2011 Device Management • Onboard the users • Set up security and usage policies • Supporng users • Keep tabs on deployed devices

© 2011 App Deployment & Management • Determine key mobile apps • Buy or Build • Distribute apps to devices • Manage updates • Set app usage policies

© 2011 Google’s Approach • Android’s Approach • Users come first • Enterprise money is real • Unlock dual use devices for our users • Keep it open and let the ecosystem run

© 2011 More Enterprise Support

© 2011 ANDROID STACK

© 2011 The Stack

Applications

Home Contacts Phone Browser Other

Application Framework

Activity Window Content View Manager Manager Providers System

Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager

Libraries Surface Media SQLite Android Runtime Manager Framework Core Libs OpenGL FreeType WebKit

Dalvik VM SGL SSL libc

Display Camera Linux Kernel Flash Binder Driver Driver Driver Driver

Keypad WiFi Audio Power Driver Driver Driver Mgmt © 2011 Linux Kernel

Android™ Stack Android runs on Linux. Applications

Home Contacts Phone Browser Other Linux provides: Hardware abstraction layer Memory management Application Framework Activity Window Content View Process management Manager Manager Providers System Networking Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager

Users never see Linux sub system Libraries Surface Media SQLite Android Runtime Manager Framework The adb shell command opens Core Libs Linux shell OpenGL FreeType WebKit Dalvik VM SGL SSL libc

Display Camera Linux Kernel Flash Binder Driver Driver Driver Driver

Keypad WiFi Audio Power Driver Driver Driver Mgmt

© 2011 Nave Libraries

Pieces borrowed from other Applications

open source projects: Home Contacts Phone Browser Other

Bionic, a super fast and small Application Framework license-friendly libc library optimized Activity Window Content View for Android Manager Manager Providers System

Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager WebKit library for fast HTML rendering Libraries Surface Media SQLite Android Runtime Manager Framework OpenGL for graphics Core Libs OpenGL FreeType WebKit

Dalvik VM Media codecs offer support for SGL SSL libc major audio/video codecs

Display Camera Linux Kernel Flash Binder Driver Driver SQLite database Driver Driver Keypad WiFi Audio Power Driver Driver Driver Mgmt Much more… © 2011 Dalvik

Dalvik VM is Android implementation of Java VM

Dalvik is optimized for mobile devices: • Battery consumption • CPU capabilities

Key Dalvik differences: • Register-based versus stack-based VM • Dalvik runs .dex • More efficient and compact implementation • Different set of Java libraries than JDK

© 2011 Applicaon Framework

Applications The rich set of system services wrapped in an intuitive Java API. Home Contacts Phone Browser Other

This ecosystem that developers Application Framework

can easily tap into is what makes Activity Window Content View writing apps for Android easy. Manager Manager Providers System Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager Location, web, telephony, WiFi, Bluetooth, notifications, media, Libraries Surface Media SQLite Android Runtime camera, just to name a few. Manager Framework Core Libs OpenGL FreeType WebKit

Dalvik VM SGL SSL libc

Display Camera Linux Kernel Flash Binder Driver Driver Driver Driver

Keypad WiFi Audio Power Driver Driver Driver Mgmt

© 2011 Applicaons

Dalvik Executable + Resources = APK Must be signed (but debug key is okay for development) Many markets with different policies

© 2011 App Distribuon • One of the markets • Side loading • Internal app directory

© 2011 Markets • Google Android Market • Amazon Android Market • Other emerging markets

© 2011 Side Loading

© 2011 Internal App Directory

© 2011 OPERATING SYSTEM FEATURES

© 2011 Mulmedia

AudioPlayer lets you simply specify the audio resource and play it.

VideoView is a View that you can drop anywhere in your activity, point to a video file and play it.

XML:

© 2011 Supported Media Formats

Audio AAC LC/LTP, HE-AACv1 (AAC+), HE- AACv2, AMR-NB, AMR-WB, MP3, MIDI, RTTTL/RTX, Ogg, PCM/WAVE

Video H.263, H.264, MPEG-4, VP8

Image JPEG, GIF, PNG, BMP

RTSP and HTTP progressive streaming. HTTP live streaming coming soon. More native support in the works.

Native support available via Khronos OpenMax IL

© 2011 File System

The file system has three main mount points. One for system, one for the apps, and one for whatever.

Each app has its own sandbox easily accessible to it. No one else can access its data. The sandbox is in /data/data/com.marakana.yamba/

SDCard is expected to always be there. It’s a good place for large files, such as movies and music. Everyone can access it.

System partition is where the entire Android operating system is, customized by OEM or not.

© 2011 Cloud to Device Push

Big deal for many pull-based apps. Will make devices use less battery.

© 2011 C2DM – The Big Picture

© 2011 Exchange Support

Wireless synchronization with Exchange. Supports Email, Calendar, Contacts. Administrators can set login policies and remotely wipe the data.

SSL Support Remote Wipe Wipe on incorrect password aempts Aachments Enabled Max Aachment Size Require Manual Sync When Roaming Allow HTML Email Max Email Age Filter Max Email Body Truncaon Size Max Email HTML Body Truncaon Size Device Password Enabled Alphanumeric Device Password Required Min Device Password Length Max Inacvity Time Device Lock Max Device Password Failed Aempts Allow Simple Device Password Device Password Expiraon SSL/Cert issues on Device Password History some devices © 2011 VPN Support

Support for VPN built-in: PPTP, L2TP, L2TP/IPSec PSK VPN, L2TP/IPsec CRT VPN

Still not Enterprise-Grade. “VPNs are dangerous because they can monitor all traffic”. Up to OEMs to work it out. Cisco and Motorola are.

Third Party VNP solutions: Cisco AnyConnect: Available on some devices already Juniper Junos Pulse: available today SonicWall VPN: available today Checkpoint, Nortel, etc. May require “rooted” device due to need to access system.

© 2011 Device Administraon

New in FroYo: Android Device Admin API.

Administrator can set: Enable passwords Set password quality Max failed logins Prompt for new password Remotely wipe device data Lock the device

App requests Device Admin permissions. If granted, admin policies apply. If not, app doesn’t work.

Policies could be hard-coded or dynamic.

Third-party enterprise solutions use this framework to build DM policies. © 2011 Policy Management Apps

© 2011 Policy Management Process • User intervenon is required to “bootstrap” a device into a fully-configured, secure configuraon – Allow paral progress, and restarts – Use noficaons & dialogs when restarng the security flow - tell the user what’s happening

© 2011 HELLO WORLD!

© 2011 Android SDK - What’s In The Box

SDK

Tools Docs Platforms Data Skins Images Samples Add-ons Google

© 2011 Create New Project

Use the Eclipse tool to create a new Android project.

Here are some key constructs:

Project Eclipse construct Target minimum to run App name whatever Package Java package Acvity Java class

© 2011 Anatomy of An App

Java Code + XML and Other Resources + Manifest File = Android App

© 2011 Running on Emulator

Emulator, not a simulator © 2011 MAIN BUILDING BLOCKS

© 2011 Yamba Demo

Let’s see a real-world medium complexity Android app in action:

Yamba: Yet Another Micro Blogging App

© 2011 Acvies

Android Application An Activity Another Another Main Activity represents a screen Activity Activity or a window. Sort of.

© 2011 Acvity Lifecycle Activities have a well- defined lifecycle. The Android OS manages your activity by changing its state. You fill in the blanks.

© 2011 Intents

Intents represent events or actions.

They are to Android apps what hyperlinks are to websites. Sort of.

Intents can be implicit or explicit.

© 2011 Services

Services are code that runs in the background. They can be started and stopped. Services doesn’t have UI.

© 2011 Service Lifecycle

Service also has a lifecycle, but it’s much simpler than activity’s.

An activity typically starts and stops a service to do some work for it in the background, such as play music, check for new tweets, etc.

Services can be bound or unbound.

© 2011 Remote Services

© 2011 Content Providers

Content Providers share content with applications across application boundaries. Examples of built-in Content Providers are: Contacts, MediaStore, Settings and more.

© 2011 Content Provider Example

© 2011 Broadcast Receivers

An Intent-based publish-subscribe mechanism. Great for listening system events such as SMS .

© 2011 Architecture of An App

An Android application is a collection of many different building blocks. They are loosely coupled and can be reconfigured by the developer easily, or at least that’s the intention.

Let’s look at 7 stages of Yamba next.

© 2011 Yamba Part 1

© 2011 Yamba Part 2

© 2011 Yamba Part 3

© 2011 Yamba Part 4

© 2011 Yamba Part 5

© 2011 Yamba Part 6

© 2011 Yamba Part 7

© 2011 ANDROID USER INTERFACE

© 2011 Two UI Approaches

Procedural Declarave

You write Java code You write XML code Similar to Swing or AWT Similar to HTML of a web page

You can mix and match both styles. Best practice:

• Start with XML and declare most of UI • Switch to Java and implement the UI logic

© 2011 XML-Based User Interface

Use WYSIWYG tools to build powerful XML-based UI. Easily customize it from Java. Separate concerns.

© 2011 Views and Layouts

Layouts contain widgets and other layouts forming a “composite” pattern.

© 2011 Linear Layout

One of the most commonly used layouts. It lays its children next to each other, either horizontally or vertically.

© 2011 Relave Layout

Children of relative layout are placed in relationship to each other. This layout is efficient.

© 2011 Table Layout

Table layout puts its children into table rows and columns. It is similar to an HTML table.

© 2011 Frame Layout

Frame layout places its children on top of each other, like a deck of cards. It is useful for widgets such as tabs or as a placeholder for views added programmatically.

© 2011 Common UI Components

Android UI includes many common modern UI widgets, such as Buttons, Tabs, Progress Bars, Date and Time Pickers, etc.

© 2011 Selecon Components

Some UI widgets may be linked to zillion pieces of data. Examples are ListView and Spinners (pull-downs).

© 2011 Adapters

Adapter Data Source

To make sure they run smoothly, Android uses Adapters to connect them to their data sources. A typical data source is an Array or a Database.

© 2011 Complex Components

Certain high-level components are simply available just like Views. Adding a Map or a Video to your application is almost like adding a Button or a piece of text.

© 2011 Menus and Dialogs

© 2011 Graphics & Animaon

Android has rich support for 2D graphics. You can draw & animate from XML. You can use OpenGL for 3D graphics.

© 2011 Mulmedia

AudioPlayer lets you simply specify the audio resource and play it.

VideoView is a View that you can drop anywhere in your activity, point to a video file and play it.

XML:

© 2011 ANDROID SECURITY

© 2011 Security Overview

No app can adversely impact other apps, user, or OS Cannot read/write user’s private data Cannot read other app’s data Cannot perform network access Cannot keep device awake, and so on

Each application is its own sandbox To share resources, apps need to request permissions User must grant permissions at install time

Linux manages security Not up to Dalvik (Java) but outsourced to Linux Native code (NDK) also adheres to sandboxing

© 2011 Applicaon Sandboxing

An application is an island on its own.

It contains any number of Activities, Services, Receivers and Providers.

It has its own file system, database, place to store native libraries.

No other app can access any of its data without prior permission.

© 2011 Permissions

A component that does something potentially dangerous can require callers to have permission to access it.

App that wants to use it must have user grant it permission.

Permissions are granted at install time. All or nothing. Forever.

© 2011 Some System Permissions

ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ACCESS_NETWORK_STATE ACCESS_WIFI_STATE BATTERY_STATS BLUETOOTH CALL_PHONE CALL_PRIVILEGED CAMERA DEVICE_POWER GET_ACCOUNTS GET_TASKS INSTALL_PACKAGES INTERNET KILL_BACKGROUND_PROCESSES NFC READ_CALENDAR READ_CONTACTS RECEIVE_SMS RECORD_AUDIO WRITE_EXTERNAL_STORAGE WRITE_SETTINGS

© 2011 BUILDING CUSTOM ROM

© 2011 Customizing The Build • Building from source • Source code overview • Adding applicaons • Adding nave Libraries • Changing startup process • Changing permissions • Modifying frameworks • Linux kernel

© 2011 What about Linux Kernel? • Separate fork of Linux Kernel • Android’s code deleted from Linux distribuon • Linux kernel separate GPL project • AOSP provides kernel as precompiled module

© 2011 Building AOS From Source • Read hp://source.android.com/source/ download.html • Setup development tools • Download REPO • Inialize REPO • Sync REPO • Build code

© 2011 Source Overview • /bionic/ is where bionic library is • /build/ is the main make file system • /dalvik/ is where Dalvik VM and dex compiler are • /development/ is for development tools and sample apps • /device/ is for device-specific code • /external/ is where most of Nave Libraries live

© 2011 Source Overview (cont’d) • /frameworks/ is where all the Android Frameworks are • /hardware/ is for HAL (hardware-abstracon layer) and other hardware-specific code • /out/ is where the final build is placed • /packages/ is where default apps and similar goes • /prebuilt/ is for pre-build code, such as Linux Kernel

© 2011 Source Overview (cont’d two) • /sdk/ is for the Android SDK tools • /system/ is for system configuraon files, such as init.d, etc.

© 2011 Adding Apps • Place your app project source code in / packages/apps/! • Create Android.mk file for the app • Edit /build/target/product/ core.mk (or similar) and add your applicaon in the list of PRODUCT_PACKAGES! • Run mm in the directory of the app • Run make snod in the root of the source

© 2011 Adding Nave Libraries • Place your nave library source code in / external/! • Create Android.mk file for the library • Edit /build/target/product/ core.mk (or similar) and add your applicaon in the list of PRODUCT_PACKAGES! • Run make

© 2011 Changing init.rc Startup • Read /system/core/init/ readme.txt! • Edit /system/core/rootdir/init.rc! • Run make

© 2011 Changing Permissions • Edit /system/core/include/ private/ android_filesystem_config.h! • You can edit Linux users, groups, directory and file permissions in this file • Run make!

© 2011 Modifying Frameworks • Look for Java Manager in /frameworks/ base/ ! • Start from Java and track it to lower levels • Keep in mind Java Nave Interface (JNI) calls and Binder Inter Process Communicaon (IPC) calls

© 2011 Example: Sensors Framework • Java Manager: /frameworks/base/core/java/ android/hardware/SensorManager.java • JNI: /frameworks/base/core/jni/ android_hardware_SensorManager.cpp • C Code: /hardware/libhardware/include/ hardware/sensors.h

© 2011 Audio Framework

© 2011 Camera and Video Framework

© 2011 Creang Audio Driver • Create shared library that implements the AudioHardwareInterface. • Name it libaudio.so • Place libaudio sources and Android.mk in vendor/acme/chipset_or_board/libaudio/

© 2011 Sample Android.mk for libaudio

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)

LOCAL_MODULE := libaudio

LOCAL_SHARED_LIBRARIES := \ libcutils \ libutils \ libmedia \ libhardware

LOCAL_SRC_FILES += MyAudioHardware.cpp

LOCAL_CFLAGS +=

LOCAL_C_INCLUDES +=

LOCAL_STATIC_LIBRARIES += libaudiointerface

include $(BUILD_SHARED_LIBRARY)

© 2011 Building Camera Library • Create shared library that implements CameraHardwareInterface.h • Name it libcamera.so • Place libcamera source and Android.mk file in vendor/acme/chipset_or_board/libcamera/ • See frameworks/base/services/camera for fake camera

© 2011 Sample Android.mk for libcamera

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)

LOCAL_MODULE := libcamera

LOCAL_SHARED_LIBRARIES := \ libutils \ librpc \ liblog

LOCAL_SRC_FILES += MyCameraHardware.cpp

LOCAL_CFLAGS +=

LOCAL_C_INCLUDES +=

LOCAL_STATIC_LIBRARIES += \ libcamera-common \ libclock-rpc \ libcommondefs-rpc

include $(BUILD_SHARED_LIBRARY)

© 2011 Summary

Android is open and complete system for mobile development. It is based on Java and augmented with XML.

Android is being adopted very quickly both by users, carriers, and manufacturers.

It takes about 3-5 days of intensive training to learn Android application development for someone who has basic Java (or similar) experience.

Marko Gargenta, Marakana.com [email protected] +1-415-647-7000

© 2011