Professional Documents
Culture Documents
BeagleBoard ESC-268
BeagleBoard ESC-268
BeagleBoard ESC-268
Bill Gatliff
bgat@billgatliff.com Freelance Embedded Systems Developer
1 / 80
What is Android?
Android delivers a complete set of software for mobile devices: an operating system, middleware and key mobile applications.
-- http://android.com/about/
2 / 80
What is Android?
A software stack:
... and nothing more
3 / 80
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
4 / 80
What is Android?
Borrows heavily from existing code:
Linux kernel for hardware abstraction SQLite libpng ...
http://source.android.com/projects
5 / 80
On your workstation:
Install Android development tools Set up USB networking
6 / 80
Please enter: 5
7 / 80
# /switchboot ... *** SUCCESS The correct uImage and boot.scr have been setup. You can press the reset button now. #
8 / 80
9 / 80
Demonstration
10 / 80
11 / 80
Noteworthy Features
Android uses Java:
... everywhere
12 / 80
Noteworthy Features
Broad Java support:
java.io java.net java.security java.sql ...
13 / 80
Noteworthy Features
Strong security:
Permissions-based Applications sandboxed in separate VMs Pervasive use of Linux process model
14 / 80
Noteworthy Features
Built-in SQL:
Property storage, retrieval Utilized by nearly all standard components Preferred, but not required
Specialized APIs:
SurfaceFlinger AudioFlinger
15 / 80
Noteworthy Features
Highly-optimized Java implementation:
Dalvik VM implemented by Google Custom bytecode format, processor model Register-based, not stack-based
16 / 80
Noteworthy Features
Why?
Didnt want to pay Sun (probably untrue) Very memory- and performance-efcient Highly tuned to limitations of small hardware
17 / 80
Noteworthy Features
Centralized object lifetime management:
Tied to component model Tied to process model Tied to user interface model Tied to security model ...
18 / 80
Noteworthy Features
No main() functions per se:
Applications are built from components on-the-y Activities, Intents, etc. Manifests describe what components are available
See http://developer.android.com
19 / 80
Terminology
Activity :
A single visual user interface component List of menu selections, icons, checkboxes, ... A reusable component
Service:
Headless activity component Background processes
20 / 80
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
21 / 80
Terminology
Intent:
Message to a component (or broadcast) Similar to a remote procedure call Make a phone call, the battery is low, ...
Intent lter :
Species which Intents a component can handle
22 / 80
Terminology
Application:
Sequence of one or more Activities Manifest tells which Activity to run rst 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
23 / 80
Terminology
Task stack :
Sequences of application-centric Activity classes Foreground is visible to user BACK key returns to most-recent Activity
24 / 80
Terminology
In other words:
Not the Linux concept of application!
25 / 80
Example
Display a map:
Utilize a preexisting Activity class Call startActivity() to launch it Control returns when the map activity exits
26 / 80
Power Management
Obviously important!
Can be a difcult problem to solve Too much model exposure is bad Too little is also bad
27 / 80
Power Management
In a nutshell:
Applications dont control power at all Applications hold locks on power states If no locks are held, Android powers down
28 / 80
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
29 / 80
Power Management
SCREEN_BRIGHT_WAKE_LOCK
CPU on, screen bright, keyboard off
FULL_WAKE_LOCK
CPU on, screen on, keyboard bright
30 / 80
Example
1 2 3 4 5 6 7 8
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "tag"); wl.acquire(); // ..screen will stay on during this section.. wl.release();
31 / 80
MediaRecorder class:
Support for audio recording only Video recording is planned
32 / 80
Example
1 2 3 4 5 6 7
33 / 80
Audioinger :
Centralized audio stream management
34 / 80
Plus enhancements:
Package management Application templates
35 / 80
Term.apk
36 / 80
Developer Tasks
Generally speaking, only two:
Implement HAL requirements Implement application-specic Activity classes
As always, however:
The devil is in the details!
37 / 80
Developer Tasks
HAL requirements:
A.k.a. Linux kernel port Adapt init.rc Native code, as needed
Activity classes:
Writing the application
38 / 80
System Initialization
init.rc
Functionally equivalent to inittab
39 / 80
System Initialization
1 2 3 4 5 6 7 8 9 10 11
on init sysclktz 0 loglevel 3 # setup the global environment export PATH /sbin:/system/sbin:/system/bin:/system/xbin export LD_LIBRARY_PATH /system/lib export ANDROID_BOOTLOGO 1 export ANDROID_ROOT /system export ANDROID_ASSETS /system/app export ANDROID_DATA /data export EXTERNAL_STORAGE /sdcard
40 / 80
System Initialization
77 78 79 80 81 82 83 84 85 86 87 88 89 90
on boot # basic network init ifup lo hostname localhost domainname localdomain # set RLIMIT_NICE to allow priorities from 19 to -20 setrlimit 13 40 40 # Define the oom_adj values for the classes of processes that can be # killed by the kernel. These are used in ActivityManagerService. setprop ro.FOREGROUND_APP_ADJ 0 setprop ro.VISIBLE_APP_ADJ 1 setprop ro.SECONDARY_SERVER_ADJ 2
41 / 80
System Initialization
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
## Daemon processes to be run by init. ## service console /system/bin/sh console # adbd is controlled by the persist.service.adb.enable system property service adbd /sbin/adbd disabled # adbd on at boot in emulator on property:ro.kernel.qemu=1 start adbd on property:persist.service.adb.enable=1 start adbd
42 / 80
Linux Kernel
Important enhancements:
logger binder ram_console timed_gpio Double-buffered framebuffer (*)
43 / 80
Linux Kernel
logger:
Miscdevice for logle-like functionality
binder:
Android IPC subsystem High performance, security-aware
44 / 80
Linux Kernel
ram_console:
RAM-based console device /proc/last_kmsg
timed_gpio:
GPIO that automagically turns itself back off
45 / 80
Linux Kernel
Double-buffered framebuffer:
Added by platform support authors Not Android-specic, but not widely available
46 / 80
http://source.android.com/
47 / 80
48 / 80
# repo init -b cupcake -u git://android.git.kernel.org/platform/manifest.git # repo sync ... apply tweaks ... # make [TARGET_PRODUCT=freerunner]
49 / 80
50 / 80
51 / 80
sys/ system/
fonts/ framework/
lib/ media/
usr/ xbin/
52 / 80
53 / 80
54 / 80
See http://android.com
55 / 80
56 / 80
57 / 80
58 / 80
Hello, Android!
Lets start simple:
Hello, world! Command-line tools only
$ activitycreator --out helloworld example.helloworld.HelloWorld $ cd helloworld/ $ vi src/example/helloworld/HelloWorld.java
59 / 80
Hello, Android!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package example.helloworld; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloWorld extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello, ESC BYOE attendees!"); setContentView(tv); } }
60 / 80
Hello, Android!
Now:
Build Install Browse to the icon, tap to launch
$ ant $ ADBHOST=192.168.99.100 adb install bin/HelloWorld-debug.apk
61 / 80
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
62 / 80
Hello, Android!
Tidy up:
Uninstall the application
$ ADBHOST=192.168.99.100 adb uninstall example.helloworld
63 / 80
Helps automate:
Set up new Android projects Create new applications, components Debugging
64 / 80
Then:
Point Eclipse to the Android SDK directory Window | Preferences | Android
65 / 80
Demonstration
66 / 80
67 / 80
In Android:
XML-based layouts, values
68 / 80
Why?
Swap main.xml les to change layouts Swap strings.xml les to translate Separate logic from presentation
69 / 80
70 / 80
71 / 80
72 / 80
Demonstration
73 / 80
Emulation
Android SDK includes QEMU:
Complete hardware emulation ... without the hardware! Includes a Linux kernel, lesystem
74 / 80
75 / 80
76 / 80
And obviously:
Mobile platforms Touch-oriented interfaces Network-centric applications
77 / 80
78 / 80
79 / 80
Bill Gatliff
bgat@billgatliff.com Freelance Embedded Systems Developer
80 / 80