Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and...

80
Google Android on the Beagleboard Introduction to the Android API, HAL and SDK Bill Gatliff [email protected] Freelance Embedded Systems Developer Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 1 / 80

Transcript of Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and...

Page 1: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Google Android on the BeagleboardIntroduction to the Android API, HAL and SDK

Bill [email protected]

Freelance Embedded Systems Developer

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 1 / 80

Page 2: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

What is Android?

“Android delivers a complete set of software formobile devices: an operating system, middleware andkey mobile applications.”

-- http://android.com/about/

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 2 / 80

Page 3: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

What is Android?

A software stack:

• ... and nothing more

(Albeit a pretty good one!)

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 3 / 80

Page 4: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

What is Android?

A ton of new code:

• Linux kernel port to MSM (Qualcomm) chipset

• Graphics, Audio and other APIs, implementations

• Development, debugging tools

• Includes “key mobile applications”

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 4 / 80

Page 5: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

What is Android?

Borrows heavily from existing code:

• Linux kernel for hardware abstraction

• SQLite

• libpng

• ...

http://source.android.com/projects

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 5 / 80

Page 6: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Configuring the BYOES Beagleboard

Steps:

• Select the Android kernel, rootfs

• Boot

On your workstation:

• Install Android development tools

• Set up USB networking

We can’t do all of that today!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 6 / 80

Page 7: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Configuring the BYOES Beagleboard

# /switchboot

***** SWITCH-UR-BOOT****Choose which file system to boot upon next reboot:

1. ESC-120 Kridner: Beagle 1012. ESC-160 Van Gend/MontaVista: debugging+power3. ESC-140 Fisher/RidgeRun4. ESC-228 Fisher/RidgeRun5. ESC-208 Gatliff: Android 1024x7686. ESC-208 Gatliff: Android 800x6007. ESC-180 Yau/HY-research: Bluetooth

Please enter: 5

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 7 / 80

Page 8: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Configuring the BYOES Beagleboard

# /switchboot

...

*** SUCCESS

The correct uImage and boot.scr have been setup.You can press the reset button now.

#

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 8 / 80

Page 9: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Configuring the BYOES Beagleboard

Some notes:

• Keyboard and mouse work differently

• (Just ignore the mouse altogether)

• You don’t have a GSM modem!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 9 / 80

Page 10: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Demonstration

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 10 / 80

Page 11: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

The Genesis of Android

Open Handset Alliance:

• Google, eBay, OMRON, PacketVideo, ...

• ASUSTeK, HTC, LG, Garmin, Motorola, ...

• Sprint Nextel, T-Mobile, ...

• ARM, Atheros, Broadcomm, Qualcomm, TI, ...

To date, more than 47 organizations

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 11 / 80

Page 12: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Android uses Java:

• ... everywhere

And so will you:

• But nothing prevents native processes

• Some native interfaces are available

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 12 / 80

Page 13: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Broad Java support:

• java.io

• java.net

• java.security

• java.sql ...

But only the mobile-appropriate bits!

• “Android is almost but not quite Java(tm)”

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 13 / 80

Page 14: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Strong security:

• Permissions-based

• Applications sandboxed in separate VMs

• Pervasive use of Linux process model

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 14 / 80

Page 15: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Built-in SQL:

• Property storage, retrieval

• Utilized by nearly all standard components

• Preferred, but not required

Specialized APIs:

• SurfaceFlinger

• AudioFlinger

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 15 / 80

Page 16: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Highly-optimized Java implementation:

• “Dalvik” VM implemented by Google

• Custom bytecode format, processor model

• Register-based, not stack-based

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 16 / 80

Page 17: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Why?

• “Didn’t want to pay Sun” (probably untrue)

• Very memory- and performance-efficient

• Highly tuned to limitations of small hardware

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 17 / 80

Page 18: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

Centralized object lifetime management:

• Tied to component model

• Tied to process model

• Tied to user interface model

• Tied to security model

• ...

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 18 / 80

Page 19: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Noteworthy Features

No main() functions per se:

• “Applications” are built from components on-the-fly

• “Activities”, “Intents”, etc.

• “Manifests” describe what components are available

See http://developer.android.com

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 19 / 80

Page 20: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Terminology

Activity :

• A single visual user interface component

• List of menu selections, icons, checkboxes, ...

• A reusable component

Service:

• “Headless” activity component

• Background processes

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 20 / 80

Page 21: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Terminology

Broadcast receiver :

• Component that receives announcements

• No user interface

• May launch an Activity in response

Content provider :

• Provides application data to others

• The only way to share data

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 21 / 80

Page 22: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Terminology

Intent :

• Message to a component (or broadcast)

• Similar to a remote procedure call

• “Make a phone call”, “the battery is low”, ...

Intent filter :

• Specifies which Intents a component can handle

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 22 / 80

Page 23: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Terminology

Application:

• Sequence of one or more Activities

• Manifest tells which Activity to run first

• Activities might come from other applications

Process model:

• Each application is a unique Linux user

• Each application is a unique process

• Activities often in different processes

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 23 / 80

Page 24: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Terminology

Task stack :

• Sequences of application-centric Activity classes

• Foreground is visible to user

• BACK key returns to most-recent Activity

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 24 / 80

Page 25: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Terminology

In other words:

• Not the Linux concept of “application”!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 25 / 80

Page 26: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Example

Display a map:

• Utilize a preexisting Activity class

• Call startActivity() to launch it

• Control returns when the map activity exits

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 26 / 80

Page 27: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Power Management

Obviously important!

• Can be a difficult problem to solve

• Too much model exposure is bad

• Too little is also bad

Extends the Linux device model:

• Introduces “wake locks”

• See android.os.PowerManager

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 27 / 80

Page 28: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Power Management

In a nutshell:

• Applications don’t control power at all

• Applications hold “locks” on power states

• If no locks are held, Android powers down

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 28 / 80

Page 29: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Power Management

PARTIAL_WAKE_LOCK

• CPU on, screen off, keyboard off

• Cannot power down via power button

SCREEN_DIM_WAKE_LOCK

• CPU on, screen dim, keyboard off

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 29 / 80

Page 30: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Power Management

SCREEN_BRIGHT_WAKE_LOCK

• CPU on, screen bright, keyboard off

FULL_WAKE_LOCK

• CPU on, screen on, keyboard bright

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 30 / 80

Page 31: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Example

1 PowerManager pm =2 (PowerManager) getSystemService(Context.POWER_SERVIC E);3 PowerManager.WakeLock wl =4 pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "t ag");56 wl.acquire();7 // ..screen will stay on during this section..8 wl.release();

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 31 / 80

Page 32: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Audio and Video APIs

MediaPlayer class:

• Standard support for many data formats

• URI invokes appropriate input method

• Consistent API regardless of data source

MediaRecorder class:

• Support for audio recording only

• Video recording is “planned”

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 32 / 80

Page 33: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Example

1 MediaPlayer mp = new MediaPlayer();23 mp.setDataSource(PATH_TO_FILE);4 mp.prepare();5 mp.start();6 mp.pause();7 mp.stop();

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 33 / 80

Page 34: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Audio and Video APIs

Surfaceflinger :

• Centralized framebuffer management

• Related to 2D h/w acceleration

Audioflinger :

• Centralized audio stream management

You don’t work with these directly!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 34 / 80

Page 35: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Android Build System

Usual suspects:

• git , repo

• ant

• make

Plus enhancements:

• Package management

• Application templates

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 35 / 80

Page 36: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Android Package System

APK files:

• Package manifests

• Classes

• Dalvik bytecodes

• Signatures, if any

Term.apk

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 36 / 80

Page 37: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Developer Tasks

Generally speaking, only two:

• Implement HAL requirements

• Implement application-specific Activity classes

As always, however:

• The devil is in the details!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 37 / 80

Page 38: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Developer Tasks

HAL requirements:

• A.k.a. “Linux kernel port”

• Adapt init.rc

• Native code, as needed

Activity classes:

• “Writing the application”

See, it isn’t so different!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 38 / 80

Page 39: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

System Initialization

init.rc

• Functionally equivalent to inittab

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 39 / 80

Page 40: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

System Initialization

1 on init2 sysclktz 03 loglevel 34 # setup the global environment5 export PATH /sbin:/system/sbin:/system/bin:/system/xb in6 export LD_LIBRARY_PATH /system/lib7 export ANDROID_BOOTLOGO 18 export ANDROID_ROOT /system9 export ANDROID_ASSETS /system/app

10 export ANDROID_DATA /data11 export EXTERNAL_STORAGE /sdcard

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 40 / 80

Page 41: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

System Initialization

77 on boot78 # basic network init79 ifup lo80 hostname localhost81 domainname localdomain8283 # set RLIMIT_NICE to allow priorities from 19 to -2084 setrlimit 13 40 408586 # Define the oom_adj values for the classes of processes that can be87 # killed by the kernel. These are used in ActivityManagerSer vice.88 setprop ro.FOREGROUND_APP_ADJ 089 setprop ro.VISIBLE_APP_ADJ 190 setprop ro.SECONDARY_SERVER_ADJ 2

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 41 / 80

Page 42: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

System Initialization

161 ## Daemon processes to be run by init.162 ##163 service console /system/bin/sh164 console165166 # adbd is controlled by the persist.service.adb.enable sys tem property167 service adbd /sbin/adbd168 disabled169170 # adbd on at boot in emulator171 on property:ro.kernel.qemu=1172 start adbd173174 on property:persist.service.adb.enable=1175 start adbd

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 42 / 80

Page 43: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Linux Kernel

Important enhancements:

• logger

• binder

• ram_console

• timed_gpio

• Double-buffered framebuffer (*)

All are staged for kernel.org release

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 43 / 80

Page 44: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Linux Kernel

logger :

• Miscdevice for logfile-like functionality

binder :

• Android IPC subsystem

• High performance, security-aware

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 44 / 80

Page 45: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Linux Kernel

ram_console :

• RAM-based console device

• /proc/last_kmsg

timed_gpio :

• GPIO that automagically turns itself back off

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 45 / 80

Page 46: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Linux Kernel

Double-buffered framebuffer:

• Added by platform support authors

• Not Android-specific, but not widely available

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 46 / 80

Page 47: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Building the Android Runtime

General procedure:

• Get the code

• Build it

• Install it

• :)

http://source.android.com/

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 47 / 80

Page 48: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Building the Android Runtime

The code:

• 2.1GB (!) of git trees

• Uses the repo tool to manage

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 48 / 80

Page 49: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Building the Android Runtime

# repo init -b cupcake -ugit://android.git.kernel.org/platform/manifest.git

# repo sync

... apply tweaks ...

# make [TARGET_PRODUCT=freerunner]

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 49 / 80

Page 50: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Installing Android into a Target

Build products:

• userdata.img

• ramdisk.img

• system.img

• kernel.img

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 50 / 80

Page 51: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Installing Android into a Target

And also:

• out/target/product/<name>/root

• out/target/product/<name>/system

• out/target/product/<name>/data

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 51 / 80

Page 52: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Installing Android into a Target

“What’s in there?”

• The Android filesystem

# ls rootdata/ init init.rc sys/default.prop init.goldfish.rc proc/ system/dev/ initlogo.rle sbin/

# ls systemapp/ build.prop fonts/ lib/ usr/bin/ etc/ framework/ media/ xbin/

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 52 / 80

Page 53: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Installing Android into a Target

Combine into unified tree:

• ... to export over NFS, perhaps

# mkdir /exports/android# cd root && tar c * | tar x -C /exports/android# cd system && tar c * | tar x -C /exports/android

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 53 / 80

Page 54: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Installing Android into a Target

Or, of course:

• Install images into the target system as-is

• (Formats vary depending on the target)

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 54 / 80

Page 55: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

The Android SDK

Key components:

• Compilers, other tools

• Documentation

• Examples

• Hardware emulator

• Android Debug Bridge (adb)

See http://android.com

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 55 / 80

Page 56: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Preparing the Beagleboard

Getting ready:

• Configure USB network connection

• Test adb

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 56 / 80

Page 57: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Preparing the Beagleboard

Connect OTG port:

• Configure USB networking, verify

$ dmesg...$ sudo ifconfig eth2 192.168.99.101 up$ ping 192.168.99.100

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 57 / 80

Page 58: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Preparing the Beagleboard

Launch a shell via adb :

• The shell is actually on the target!

$ ADBHOST=192.168.99.100 adb kill-server$ ADBHOST=192.168.99.100 adb shell#

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 58 / 80

Page 59: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android!

Let’s start simple:

• “Hello, world!”

• Command-line tools only

$ activitycreator --out helloworldexample.helloworld.HelloWorld

$ cd helloworld/$ vi src/example/helloworld/HelloWorld.java

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 59 / 80

Page 60: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android!

1 package example.helloworld;23 import android.app.Activity;4 import android.os.Bundle;5 import android.widget.TextView;67 public class HelloWorld extends Activity8 {9 /** Called when the activity is first created. */

10 @Override11 public void onCreate(Bundle savedInstanceState)12 {13 super.onCreate(savedInstanceState);14 TextView tv = new TextView(this);15 tv.setText("Hello, ESC BYOE attendees!");16 setContentView(tv);17 }18 }

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 60 / 80

Page 61: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android!

Now:

• Build

• Install

• Browse to the icon, tap to launch

$ ant$ ADBHOST=192.168.99.100 adb

install bin/HelloWorld-debug.apk

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 61 / 80

Page 62: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android!

Or:

• Launch from the shell

$ ADBHOST=192.168.99.100 adb shell# am start -a android.intent.action.MAIN -n

example.helloworld/example.helloworld.HelloWorld

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 62 / 80

Page 63: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android!

Tidy up:

• Uninstall the application

$ ADBHOST=192.168.99.100 adbuninstall example.helloworld

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 63 / 80

Page 64: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Eclipse Android Plugin

Android Development Tool (ADT):

• Custom plugin for Eclipse IDE

Helps automate:

• Set up new Android projects

• Create new applications, components

• Debugging

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 64 / 80

Page 65: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Eclipse Android Plugin

Install Eclipse, then:

• Click Help | Software Updates...

• https://dl-ssl.google.com/android/eclipse/

• Click Install...

Then:

• Point Eclipse to the Android SDK directory

• Window | Preferences | Android

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 65 / 80

Page 66: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Demonstration

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 66 / 80

Page 67: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Declarative vs. Procedural Programming

“Programmatic” UI layout:

• UI comes directly from source code

• Manual connections between views

• Small UI changes can mean big source code changes

• Application is “brittle”

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 67 / 80

Page 68: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Declarative vs. Procedural Programming

A better way:

• Use a declarative approach

• Describe what you want, not how to get it

• Let the UI framework fill in the details

In Android:

• XML-based layouts, values

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 68 / 80

Page 69: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android! with XML

Applied to “Hello, Android!”:

• Move the layout to XML

• Move the text to a resource

Why?

• Swap main.xml files to change layouts

• Swap strings.xml files to translate

• Separate logic from presentation

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 69 / 80

Page 70: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android! with XML

res/layout/main.xml :

• Describes the layout

1 <?xml version="1.0" encoding="utf-8"?>2 <TextView xmlns:android="http://schemas.android.com/ apk/res/android"3 android:layout_width="fill_parent"4 android:layout_height="fill_parent"5 android:text="@string/hello"/>

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 70 / 80

Page 71: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android! with XML

res/values/strings.xml :

• Defines the string resource

1 <?xml version="1.0" encoding="utf-8"?>2 <resources>3 <string name="hello">Welcome to Android string resources !</string>4 <string name="app_name">Hello, Android</string>5 </resources>

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 71 / 80

Page 72: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Hello, Android! with XML

HelloWorld class then becomes:

• “Just do what main.xml says”

1 package com.example.hello;23 import android.app.Activity;4 import android.os.Bundle;56 public class HelloAndroid extends Activity {7 /** Called when the activity is first created. */8 @Override9 public void onCreate(Bundle savedInstanceState) {

10 super.onCreate(savedInstanceState);11 setContentView(R.layout.main);12 }13 }

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 72 / 80

Page 73: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Demonstration

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 73 / 80

Page 74: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Emulation

Android SDK includes QEMU:

• Complete hardware emulation

• ... without the hardware!

• Includes a Linux kernel, filesystem

... and Eclipse can’t tell the difference!

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 74 / 80

Page 75: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

“But what does all this mean?”

Why I’m excited about Android:

• New ideas on current challenges

• New developers, community

• Relatively feature-complete

• Still under active development

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 75 / 80

Page 76: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

“But what does all this mean?”

But expecially:

• Intended, designed for community development

• (And delivers on that promise)

• Easy to get started, but still challenging

Not just a new API:

• Also an entirely new approach, context

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 76 / 80

Page 77: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

“But what does all this mean?”

What Android seems good for:

• Open development models

• Highly-configurable systems

And obviously:

• Mobile platforms

• Touch-oriented interfaces

• Network-centric applications

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 77 / 80

Page 78: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

“But what does all this mean?”

What Android might not be good for:

• Very low-end hardware

• Highly proprietary systems

Maybe, maybe not:

• Static systems

• Single-task systems

• No networking requirements

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 78 / 80

Page 79: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

“But what does all this mean?”

But who knows, really? :)

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 79 / 80

Page 80: Google Android on the Beagleboard - Amazon Web Services · Introduction to the Android API, HAL and SDK Bill Gatliff bgat@billgatliff.com ... • Install Android development tools

Google Android on the BeagleboardIntroduction to the Android API, HAL and SDK

Bill [email protected]

Freelance Embedded Systems Developer

Copyright © Bill Gatliff, 2009 Google Android on the Beagleboard 80 / 80