CS 423 – Operating Systems Design
Lecture 24 – Google Android System Klara Nahrstedt Fall 2011 Based on slides from Andrew S. Tanenbaum textbook and other web-material (see acknowledgements)
cs423 Fall 2011
1
Overview Administrative
◦ MP3 going on ◦ Pickup Midterms and HWs ◦ Reboot your VM if you have not done so Android
History Android Architecture Selected Important and New Concepts
cs423 Fall 2011
2
What is Android? Google
OHA (Open Handset Alliance)
◦ The first truly open and comprehensive platform for mobile devices, all of the software to run a mobile phone but without the proprietary obstacles that have hindered mobile innovation. ◦ Linux OS kernel ◦ Java programming ◦ Open source libraries: SQLite, WebKit, OpenGL
Why Android ? A
simple and powerful SDK No licensing, distribution, or development fees Development over many platform ◦ Linux, Mac OS, windows Excellent
documentation Thriving developer community
History of Android (1) Google
2005
purchases startup company Android Inc.
◦ Development of Android Platform starts
2007
– Open Handset Alliance around Android Platform
◦ Sprint, T-Mobile, Motorola, Samsung, Sony Ericsson, Toshiba, Vodafone, Google, Intel, Texas Instrument ◦ Key architectural goals of Android Platform was always openness ◦ Allow applications to interact with one another and reuse components from one another
2008
– Android Dev Phone 1 (Android OS 1.1)
◦ Applications running without being tied to any cell phone provider network !!! cs423 Fall 2011
History of Android (2) 2009
◦ April 2009 – release 1.5 Android OS with advanced media-recording, widgets, live folders ◦ September 2009 – release 1.6 Android OS with advanced search capabilities, text to speech, gesture and multi-touch
2010
◦ Android 2.0 – usage of HTML
2011
◦ Android 2.2 (Fro Yo) ◦ Android 2.3 (Gingerbread) ◦ Android 3.0 (Honeycomb) cs423 Fall 2011
Android Features Application
framework
◦ Enabling reuse and replacement of components
Dalvik
virtual machine optimized for mobile devices Integrated browser based on open source WebKit engine Optimized graphics
◦ Powered by custom 2F graphics library, 3D graphics based on OpenGL
SQLite for structured data storage Media support for audio/video/still image
formats (MPEG4, H. 264, MP3, JPG, …)
Source: http://developer.android.com/guide/basics/what-is-android.html
cs423 Fall 2011
Android Features GSM
telephony Bluetooth, EDGE, 3G, WiFi (hardware dependent) Camera, GPS, compass, accelerometer (hardware dependent) Rich development environment ◦ Including device emulator, tools for debugging, memory and performance profiling and plugin for Eclipse IDE Location-based Manufacturer
service (map – Google API)
Independent Abstractions to Hardware
Source: http://developer.android.com/guide/basics/what-is-android.html
cs423 Fall 2011
Android Architecture
cs423 Fall 2011
Android Application Framework Open development platform Capabilities to build extremely
innovative applications Developers
rich and
◦ take advantage of device hardware, access location information, run background services, set alarms, notifications to the status bar, etc ◦ Have full access to the same framework APIs used by core apps ◦ Application architecture designed to simplify reuse of components ◦ Any app can publish its capabilities and any other app may then make use of those capabilities (subjet to security constraints) cs423 Fall 2011
Android Application Framework Underlying
all applications is a set of services and
systems: Rich and extensible set of views
◦ They can be used to build app including lists, grids, text boxes, buttons, even embeddable web browser
Content
providers that enable apps to access data from other apps (such as contacts) or to share their won data Resource manager, providing access to non-code resources such as localized strings, graphics, layout files Notification manager that enables all apps to display custom alerts in the status bar Activity manager that manages lifecycle of apps and provides common navigation back-stack cs423 Fall 2011
Android Application Framework Contacts
Media
Content Provider View 1 Notification Manager
Activity G U I
Service Activity Manager
Broadcast Listener Resource Provider Strings
Storage
Radio TextView Toast
View 2 Button Slider Toast
Android Runtime Every Android
app runs its own process, with its own instance of the Dalvik virtual machine
Dalvik
has been written so that it can run multiple VMs efficiently
Dalvik VM
executes files in Dalvik Executable (.dex) format
D Resources E X Activity Service Dalvik VM
DEX
DEX
Dalvik VM
Dalvik VM
Linux Kernel
Android DEX ●
Optimized for minimal memory footprint ●
●
●
Global String Table
Runs classes compiled by Java language complier that have been transformed into .dex format by included “dx” tool Relies on linux kernel for threading and low-level memory management
File Header String Table Class List Field Table Method Table ... Local Variable List DEX File Format
Android Kernel Relies
on Linux version 2.6 for core services Security ◦ Leverage Linux Users and Permissions Memory
management Process management Network stack Driver model cs423 Fall 2011
Android Application Architecture Views:
◦ Building block for user interface components. Activities
◦ A single, focused thing that the user can do. ◦ Interaction with users: creating a window to place UI ◦ full-screen windows, floating windows, embedded inside of another activity ◦ Ex: Registration, Peerlist, Messaging GUI
Android Application Architecture Services
(Background)
Intent
◦ Ex: Network Communication Intent
◦ Inter-communication among activities or services Resource
◦ Externalization of strings and graphics Notification
◦ signaling users: Light, sound, icon, dialog, notification ◦ Ex: new message arrives Content
Providers
◦ share data between applications
Layout
Java
View
of visual interface
Code
◦ Initialize
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.screen); }
◦ Access TextView myTextView = (TextView)findViewById(R.id.myTextView);
screen.xml
View Component
Widget
Toolbox
◦ TextView, EditText,Button, Form, TimePicker… ◦ ListView (PeerList)
Update list by arrays ArrayAdapter myListView.setAdapter
◦ Layout
Positions of controls LinearLayout, Relativelayout ◦ http://developer.android.com/guide/tutorials/views/index.html
Menu
◦ Exit app
Activity Foreground
invisible
Activity: suspended when
◦ Visual, interactive ◦ Ex: Game, Map
Background
Service: Little interaction
◦ Ex: Hardware, power management
User Interaction Event
onKeyDown. onKeyUp onTrackBallEvent onTouchEvent
registerButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {….}} myEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { … return true; } return false; }});}
User Interaction Event
onKeyDown. onKeyUp onTrackBallEvent onTouchEvent
registerButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {….}} myEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { … return true; } return false; }});}
Application and Component Glues An
intent is an abstract description of an operation to be performed.
Intent intent = new ◦ Launch an activity Ex: Intent(MyActivity.this, MyOtherActivity.class);
Explicit
Im: Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:555-2368”));
Implicit: Android selects the best startActivity();
◦ Subactivity: feedback
Child: use intent as feedback, setResult Parent: onActivityResult startActivityForResult
◦ Action, data, extra parameter
intent.putExtra(name, property);
Intent Broadcast
◦ announce application events system-wide ◦ sendBroadcast ◦ MyBroadcastReceiver extends BroadcastReceiver ◦ registerReceiver (in java / in xml)
Intent
Filter
◦ Register Activities, Services, and Broadcast Receivers as being capable of performing an action on a particular kind of data.
Manifest.xml
Intent from Peerlist to Messaging
Select a peer Send Intent
PeerList
Messaging
Service
Service class ◦ public class MyService extends Service ◦ public void onStart() {…}
Manifest.xml ◦
Control ◦ startService ◦ stopService
Communication ◦ Bind service with activity: use public method and properties ◦ Intent
Working in Background Services
◦ NO GUI, higher priority than inactive Activities ◦ Usage: responding to events, polling for data, updating Content Providers.
◦ However, all in the main thread Background
threads
Activity Lifetime
Declaration of App – Manifest.xml
Service Activity (intent-filter) Permission ◦ Don’t forget. Otherwise, your programming won’t work
External Resources values/
◦ String, color, array, dimension, style theme drawables/
◦ Image layout/
◦ screen.xml
Tools
The Android Emulator ◦ Implementation of the Android virtual machine ◦ Test and debug your android applications.
Dalvik Debug Monitoring Service (DDMS) ◦ Monitor and Control the Dalvik virtual machines ◦ Logcat (see logged msgs)
Android Debug Bridge (ADB) ◦ Manage the state of an emulator instance or Android-powered device ◦ Copy files, install compiled application packages, and run shell commands.
Traceview ◦ Graphical analysis tool for viewing the trace logs from your Android application ◦ Debug your application and profile its performance
MkSDCard ◦ Creates an SDCard disk image
Conclusion Important
concepts at the application framework level New concepts ◦ Activities, Broadcast Listeners, Intents ◦ Paying attention to GUI And Overall User interactions ◦ Specialized lifecycle
cs423 Fall 2011
32
Reference Online
development guide
◦ http://developer.android.com/guide/index.html
Book
resource
◦ “Professional Android Application Development”, by Reto Meier, (Wrox, amazon link) ◦ “Android A programmers guide”, by J.F. DiMarzio, (McGraw Hill, amazon link) ◦ “Beginning.Android”, by Mark L. Murphy, (Apress, amazon link) ◦ “Pro Android”, by Sayed Y. Hashimi, Satya Komatineni, (Apress, amazon link)