Google Android On The Beagleboard: Introduction To The Android API, HAL and SDK
Google Android On The Beagleboard: Introduction To The Android API, HAL and SDK
Bill Gatliff
[email protected] Freelance Embedded Systems Developer
1 / 65
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 / 65
What is Android?
A software stack:
... and nothing more
3 / 65
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 / 65
What is Android?
Borrows heavily from existing code:
Linux kernel for hardware abstraction SQLite libpng ...
http://source.android.com/projects
5 / 65
On your workstation:
Install Android development tools Set up USB networking
6 / 65
Please enter: 5
7 / 65
# /switchboot ... *** SUCCESS The correct uImage and boot.scr have been setup. You can press the reset button now. #
8 / 65
Also:
You need the Android SDK v. 1.6
9 / 65
Hello, Android!
Lets start simple:
Hello, world! Command-line tools only
$ android create project --target 2 --name Hello --path ./helloworld --activity HelloWorld --package example.HelloWorld $ cd helloworld/ $ vi src/example/HelloWorld/HelloWorld.java
10 / 65
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); } }
11 / 65
Hello, Android!
Build:
Create a debugging-enabled package
$ ant debug ... debug: [echo] running zip align on final apk... [echo] Debug Package: bin/Hello-debug.apk BUILD SUCCESSFUL $
12 / 65
Hello, Android!
Create a Virtual Device:
(Well use real hardware later)
$ android create avd --name virtual1_6 --target 2 ... Created AVD virtual1_6 based on Android 1.6... $ emulator @virtual1_6
13 / 65
Hello, Android!
Download the Package:
Tap the icon to start it running
$ adb install bin/Hello-debug.apk
14 / 65
Hello, Android!
... or:
Launch from the shell
$ adb shell # am start -a android.intent.action.MAIN -n example.HelloWorld/.HelloWorld
15 / 65
16 / 65
17 / 65
Helps automate:
Set up new Android projects Create new applications, components Debugging
18 / 65
Then:
Point Eclipse to the Android SDK directory Window | Preferences | Android (See the instructions on developer.android.com)
19 / 65
20 / 65
Noteworthy Features
Android uses Java:
... everywhere
21 / 65
Noteworthy Features
Broad Java support:
java.io java.net java.security java.sql ...
22 / 65
Terminology
Activity :
A single visual user interface component List of menu selections, icons, checkboxes, ... A reusable component
Service:
Headless activity component Background processes
23 / 65
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
24 / 65
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
25 / 65
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
26 / 65
Terminology
Task stack :
Sequences of application-centric Activity classes Foreground is visible to user BACK key returns to most-recent Activity
27 / 65
Terminology
In other words:
Not the Linux concept of application!
28 / 65
Example
Display a map:
Utilize a preexisting Activity class Call startActivity() to launch it Control returns when the map activity exits
29 / 65
30 / 65
In Android:
XML-based layouts, values
31 / 65
Why?
Swap main.xml les to change layouts Swap strings.xml les to translate Separate logic from presentation
32 / 65
33 / 65
34 / 65
35 / 65
Power Management
Obviously important!
Can be a difcult problem to solve Too much model exposure is bad Too little is also bad
36 / 65
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
37 / 65
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
38 / 65
Power Management
SCREEN_BRIGHT_WAKE_LOCK
CPU on, screen bright, keyboard off
FULL_WAKE_LOCK
CPU on, screen on, keyboard bright
39 / 65
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();
40 / 65
MediaRecorder class:
Support for audio recording only Video recording is planned
41 / 65
Example
1 2 3 4 5 6 7
42 / 65
Audioinger :
Centralized audio stream management
43 / 65
Linux Kernel
Important enhancements:
logger binder ram_console timed_gpio Double-buffered framebuffer (*)
44 / 65
Linux Kernel
logger:
Miscdevice for logle-like functionality
binder:
Android IPC subsystem High performance, security-aware
45 / 65
Linux Kernel
ram_console:
RAM-based console device /proc/last_kmsg
timed_gpio:
GPIO that automagically turns itself back off
46 / 65
Linux Kernel
Double-buffered framebuffer:
Added by platform support authors Not Android-specic, but not widely available
47 / 65
http://source.android.com/
48 / 65
49 / 65
# repo init -b cupcake -u git://android.git.kernel.org/platform/manifest.git # repo sync ... apply tweaks ... # make [TARGET_PRODUCT=freerunner] # make [TARGET_PRODUCT=beagleboard]
50 / 65
51 / 65
52 / 65
53 / 65
sys/ system/
fonts/ framework/
lib/ media/
usr/ xbin/
54 / 65
55 / 65
56 / 65
57 / 65
58 / 65
59 / 65
60 / 65
61 / 65
And obviously:
Mobile platforms Touch-oriented interfaces Network-centric applications
62 / 65
63 / 65
64 / 65
Bill Gatliff
[email protected] Freelance Embedded Systems Developer
65 / 65