Introduction to Android (Jeudis du libre)

63
Introduction to Android Christophe Beyls Jeudis du Libre - April 2012

Transcript of Introduction to Android (Jeudis du libre)

Page 1: Introduction to Android (Jeudis du libre)

Introduction to AndroidChristophe Beyls

Jeudis du Libre - April 2012

Page 2: Introduction to Android (Jeudis du libre)

About the speaker

● Developer living in Brussels.● Uses various programming languages,

mostly Java and C#.● Likes coding, hacking devices, travelling,

movies, music, (LOL)cats.

● Worked for:

Page 3: Introduction to Android (Jeudis du libre)

Agenda

1. Introduction - Why Android?2. History3. System architecture and its free parts4. The SDK5. The building blocks of an Android

app6. Devices hacking and custom ROMs7. Questions & Answers.

Page 4: Introduction to Android (Jeudis du libre)

Why Android?

Page 5: Introduction to Android (Jeudis du libre)

Why Android?

Page 6: Introduction to Android (Jeudis du libre)

Why Android?

■ Open architecture.■ Apps may be distributed outside the Google

Play Store (Android Market) and installed on any device.

Page 7: Introduction to Android (Jeudis du libre)

History

■ 2003: Android Inc.founded by Andy Rubin.

■ 2005: Purchase by Google. ■ January 2007: Apple announces

the iPhone.■ June 2007: iPhone released.

Page 8: Introduction to Android (Jeudis du libre)

History

November 2007Google creates the Open Handset Alliance consortium with 34 founding members. Manufacturers: HTC, LG, Sony, Motorola, Samsung.Semiconductors: Qualcomm, Intel, nVidia, ...Operators: T-Mobile, Sprint, Telefónica...Software: eBay, Google, Nuance, ...

Page 9: Introduction to Android (Jeudis du libre)

History

November 2007: First beta SDK released.

Page 10: Introduction to Android (Jeudis du libre)

History

December 2007: Early prototype unveiled.

Page 11: Introduction to Android (Jeudis du libre)

History

February 2008: Apple releases the iPhone SDK.June 2008: Apple opens the App Store and releases the iPhone 3G.

Page 12: Introduction to Android (Jeudis du libre)

History

September 2008Android 1.0 on HTC Dream (T-Mobile G1).

Page 13: Introduction to Android (Jeudis du libre)

History

February 2009: Android 1.1 (bugfixes).April 2009: Android 1.5 Cupcake (Widgets, virtual keyboard).June 2009: 2 more Android phones released. September 2009: Android 1.6 Donut(Text-to-speech, multiple screen resolutions).

HTC Magic HTC Hero

Page 14: Introduction to Android (Jeudis du libre)

History

November 2009: Android 2.0 Eclair(HTML5, Contacts + Bluetooth APIs).January 2010: Nexus One released(first Google-branded phone).Android 2.1 (bugfixes, live wallpapers). April 2010: Apple iPad released.May 2010: Android 2.2 FroYo(speed, JIT compiler, push notifications, Adobe Flash support, WiFi hotspot).

Page 15: Introduction to Android (Jeudis du libre)

History

2Q10: Android outsells iOS devices worldwide.

Page 16: Introduction to Android (Jeudis du libre)

History

December 2010: Android 2.3 Gingerbreadon Google Nexus S.(Black interface, NFC, native SIP,WebM support)

Page 17: Introduction to Android (Jeudis du libre)

History

February 2011: Android 3.0 Honeycombon the first Android tablet: the Motorola Xoom.■ New UI: Holo theme, Fragments, Action Bar■ Full 2D hardware acceleration.

Page 18: Introduction to Android (Jeudis du libre)

History

3Q11: Android market share doubles compared to 3Q10 and becomes to most used mobile OS.

Page 19: Introduction to Android (Jeudis du libre)

History

November 2011:Android 4.0 Ice Cream Sandwichon Google/Samsung Galaxy Nexus.

■ Unified OS for Smartphonesand Tablets.

■ Faster, smoother■ Improved browser■ Roboto font■ Face unlock.

Page 20: Introduction to Android (Jeudis du libre)

System Architecture

Page 21: Introduction to Android (Jeudis du libre)

System architecture - Bionic libc

■ Fast, optimized for ARM■ Lightweight (200 ko), half the size of glibc■ No C++ Exceptions■ No Standard Template Library■ New pthreads implementation

[does not support pthread_cancel()]■ Can be exploited directly through NDK

(native development kit) BSD licencehttps://github.com/android/platform_bionic

Page 22: Introduction to Android (Jeudis du libre)

System architecture - WebKit

■ Developed by KDE, Apple, Nokia, Google and others.

■ Android 2.2+ uses faster V8 javascript engine instead of JavascriptCore.

■ No differences between Android browser and webviews embedded in apps.

Page 23: Introduction to Android (Jeudis du libre)

System architecture -Media Framework

Based on OpenCORE and Stagefright (2.2+).

Page 24: Introduction to Android (Jeudis du libre)

System architecture -Media Framework - Base support

■ Audio codecs: AAC, MP3, AMR, PCM, MIDI, Ogg Vorbis, FLAC (3.1+)

■ Image codecs: JPEG, GIF, BMP, PNG, WebP (4.0+)

■ Video codecs: H.263, H.264, MPEG-4 SP, VP8 (2.3.3+)

■ Containers: 3GPP, MPEG-4,Matroska (.mkv) (4.0+)

■ Manufacturers may add more codecs.

Italic = patent-free

Page 25: Introduction to Android (Jeudis du libre)

System architecture - Runtime

■ Android uses only the Java language,not the Java platform.

■ Dalvik Virtual Machine developed by Google.

■ Uses minimal memory.■ Java bytecode is converted to smaller

Dalvik bytecode at build time (.dex files).■ Uses Just-In-Time compilation since

Android 2.2 for better performance.■ Standard library is based on Apache

Harmony open source implementation.

Page 26: Introduction to Android (Jeudis du libre)

Android Open Source Project (AOSP)

source.android.com

Page 27: Introduction to Android (Jeudis du libre)

Android Open Source Project (AOSP)

Almost... fully open:■ Google publishes source code when they

decide it.■ No real interaction with Google teams.■ Not everything is open source:

○ Proprietary binary drivers○ Google Apps: Google Maps, Gmail, Google

Contacts/Calendar/Bookmarks Sync, Google Talk, Play Store (Android Market), Youtube, Weather widget, Text-To-Speech, Voice Search.

Page 28: Introduction to Android (Jeudis du libre)

The SDK

iPhone / iPad■ Hardware: Mac (with latest Mac OS X)■ IDE: XCode (free)■ Language: Objective-C. Windows Phone 7 / Windows 8■ Hardware: PC with Microsoft Windows■ IDE: Microsoft Visual Studio (free)■ Language: C#, Visual Basic.

Page 29: Introduction to Android (Jeudis du libre)

The SDK

Android■ Hardware: Any x86■ IDE: Eclipse, Netbeans, IntelliJ IDEA■ Language: Java.

Page 30: Introduction to Android (Jeudis du libre)

Installing the SDK

developer.android.com/sdk

Page 31: Introduction to Android (Jeudis du libre)

Official SDK Tools

■ ADB (Android Debug Bridge)■ ARM Emulator (based on QEMU)■ DDMS (Dalvik Debug Monitor Server)■ Proguard (Java optimizer & obfuscator)■ ADT Plugin for Eclipse:

○ Project wizards○ Java editor with code completion, refactoring, ...○ Lint integration○ Visual layout editor

+ NDK (Native Development Kit)

Page 32: Introduction to Android (Jeudis du libre)

Official SDK Tools - ADT Plugin

Page 33: Introduction to Android (Jeudis du libre)

Official SDK Tools - ADT Plugin

Page 34: Introduction to Android (Jeudis du libre)

Official SDK Tools - ADT Plugin

Page 35: Introduction to Android (Jeudis du libre)

Official SDK Tools - ADT Plugin

Resources■ By language■ By screen density■ By screen orientation■ By Android version

Page 36: Introduction to Android (Jeudis du libre)

Official SDK Tools - ADT Plugin

Page 37: Introduction to Android (Jeudis du libre)

User Interface

developer.android.com/design

Page 38: Introduction to Android (Jeudis du libre)

Android apps: the building blocks

Activities: screens with a life cycle.

Page 39: Introduction to Android (Jeudis du libre)

Android apps: the building blocks

Fragments: portions of screens with a life cycle.

Page 40: Introduction to Android (Jeudis du libre)

Android apps: the building blocks

■ Background services.

■ Intents: IPC mechanism betweenActivities and/or Services.Action + Data○ Action: View, Edit, Dial, ..., custom actions○ Data: URL scheme or any MIME type.

■ Everything in the system use intents

and is interchangeable.

Page 41: Introduction to Android (Jeudis du libre)

Android apps: the building blocks

Special apps:■ Live wallpapers■ Widgets

Page 42: Introduction to Android (Jeudis du libre)

Diversity

Development challenges: ■ Write fast high-level code or use NDK

■ Support multiple devices types○ Phones○ Tablets○ Google TVs

■ Support multiple Android versions.

Page 43: Introduction to Android (Jeudis du libre)

Diversity - Android versions

Page 44: Introduction to Android (Jeudis du libre)

Diversity - Android versions

99%

Page 45: Introduction to Android (Jeudis du libre)

Diversity - Android versions

Use features of newer Android versionswhile staying compatible with older runtimes:Isolate special functionality in separate classes. MyInterface implementation;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)

implementation = new FroYoImplementation();else

implementation = new CompatibleImplementation();

Page 46: Introduction to Android (Jeudis du libre)

The upgrade problem

Manufacturers provide custom user interfaces.

HTC SenseSony Ericsson

Timescape Samsung TouchWiz

Page 47: Introduction to Android (Jeudis du libre)

The upgrade problem

■ Updating the custom user interface to a new Android version requires a lot of work.

■ Manufacturers focus on selling you their latest hardware, not providing support for older hardware.

■ On Android, upgrades usually depend on carriers. (The Proximus case)

■ Many manufacturers don't do OTA updates.■ Average official support time:

○ 3 years for Apple○ <= 2 years for most Android phones.

Page 48: Introduction to Android (Jeudis du libre)

The upgrade solution:Installing community ROMs

Why hack ?■ Give choice to the user.■ Remove bloatware.■ Provide longer term support and upgrades. Custom ROMs:Complete firmware (OS, UI, base applications) created by the community.

Page 49: Introduction to Android (Jeudis du libre)

Hacking - Custom ROMs

Different kinds of custom ROMs:■ Modified original vendor versions■ Ported from another device (experimental)■ Build from source (AOSP) Hack challenges■ Locked hardware (HTC S-ON).■ Binary drivers:

Radio (Wifi - Bluetooth - GPS), Graphics, NFC, sometimes accelerometers.

Page 50: Introduction to Android (Jeudis du libre)

Hacking

Warning: voids warranty.

Successfully hacked:

HTC G1, HTC Magic, HTC Hero, HTC Desire, HTC Legend, Dell Streak, Samsung Galaxy S, Samsung Galaxy Gio, Samsung Galaxy Tab, Acer Liquid, ZTE Blade, Motorola Xoom,Sony Ericsson Xperia X10.

Page 51: Introduction to Android (Jeudis du libre)

Hacking - The Bible

forum.xda-developers.com

Page 52: Introduction to Android (Jeudis du libre)

Hacking - Custom ROMs

Cyanogenmod - www.cyanogenmod.com

Page 53: Introduction to Android (Jeudis du libre)

Hacking - Custom ROMs

MIUI - miuiandroid.com

Page 54: Introduction to Android (Jeudis du libre)

BootloaderIPL SPL Kernel

RecoveryRadio

System

Data

Hacking basics

■ ROM

■ Recovery Boot modes:■ Normal OS■ Recovery■ SPL (Flash mode)

Page 55: Introduction to Android (Jeudis du libre)

Hacking basics

Custom ROM:Zip file containing■ system files■ kernel■ optionnally radio. Can be installed easilyusing a custom recovery.

Page 56: Introduction to Android (Jeudis du libre)

Hacking basics - 1. Flash tools

FastBoot (Google, HTC, Sony Ericsson) ■ Android standard command line Flash Tool■ Available in the SDK (Win, Mac, Linux)■ Useful commands: fastboot oem unlockfastboot flash recovery recovery.imgfastboot boot recovery.imgfastboot erase data -w

Page 57: Introduction to Android (Jeudis du libre)

Hacking basics - 1. Flash tools

Samsung ODIN (Windows)

Page 58: Introduction to Android (Jeudis du libre)

Hacking basics - 2. Root access

■ Root access allows to perform restricted operations like:○ writing files on system partition○ flashing a custom recovery directly from Android

OS. ■ It requires:

○ Patching or replacing the kernel○ - or -○ Use phone-specific kernel exploits

(mainly through ADB).

Page 59: Introduction to Android (Jeudis du libre)

Hacking basics - 2. Root access

Page 60: Introduction to Android (Jeudis du libre)

Recap: How to change your ROM

1. Go to a forum / wiki and learn the procedure2. Use:

a. fastbootb. the vendor flash toolc. a root hackto install a custom recovery on your phone.

3. Download a custom ROM as zip file and place it to your SD card/internal storage.

4. Reboot your phone in custom recovery and install the ROM. Reboot. Done.

Page 61: Introduction to Android (Jeudis du libre)

Hacking basics - Custom recovery

ClockworkModrecovery

Page 62: Introduction to Android (Jeudis du libre)

Hacking basics - Custom recovery

Page 63: Introduction to Android (Jeudis du libre)

Thank you for watching.

Questions? Twitter: @BladeCoderWeb: digitalia.be