33
CS 423 – Operating Systems Design CS 423 – Operating Systems Design Lecture 24 – Google Android System 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

Lecture 24 – Google Android System

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 24 – Google Android System

CS 423 – Operating Systems DesignCS 423 – Operating Systems Design

Lecture 24 – Google Android System Lecture 24 – Google Android System

Klara NahrstedtFall 2011

Based on slides from Andrew S. Tanenbaum textbook and other web-material (see acknowledgements)

cs423 Fall 2011 1

Page 2: Lecture 24 – Google Android System

OverviewOverviewAdministrative ◦ MP3 going on◦ Pickup Midterms and HWs◦ Reboot your VM if you have not done so

Android HistoryAndroid ArchitectureSelected Important and New Concepts

cs423 Fall 2011 2

Page 3: Lecture 24 – Google Android System

What is Android?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

Page 4: Lecture 24 – Google Android System

Why Android ?Why Android ?A simple and powerful SDKNo licensing, distribution, or

development feesDevelopment over many platform ◦ Linux, Mac OS, windows

Excellent documentationThriving developer community

Page 5: Lecture 24 – Google Android System

History of Android (1) History of Android (1) Google purchases startup company Android Inc.

2005 ◦ 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 another2008 – Android Dev Phone 1 (Android OS 1.1) ◦ Applications running without being tied to any cell

phone provider network !!!

cs423 Fall 2011

Page 6: Lecture 24 – Google Android System

History of Android (2)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

Page 7: Lecture 24 – Google Android System

Android FeaturesAndroid FeaturesApplication 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 OpenGLSQLite for structured data storageMedia support for audio/video/still image

formats (MPEG4, H. 264, MP3, JPG, …)

cs423 Fall 2011Source: http://developer.android.com/guide/basics/what-is-android.html

Page 8: Lecture 24 – Google Android System

Android FeaturesAndroid FeaturesGSM telephonyBluetooth, 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 service (map – Google API)Manufacturer Independent Abstractions to Hardware

cs423 Fall 2011Source: http://developer.android.com/guide/basics/what-is-android.html

Page 9: Lecture 24 – Google Android System

Android Architecture Android Architecture

cs423 Fall 2011

Page 10: Lecture 24 – Google Android System

Android Application Framework Android Application Framework Open development platformCapabilities to build extremely rich and

innovative applicationsDevelopers ◦ 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

Page 11: Lecture 24 – Google Android System

Android Application Framework 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 browserContent 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

Page 12: Lecture 24 – Google Android System

Android Application Framework

GUI

ToastTextView

Radio

ToastSliderButton

View 1

View 2

Resource Provider

Strings Storage

Content Provider

Contacts Media

Activity

ActivityManager

NotificationManager

Service

BroadcastListener

Page 13: Lecture 24 – Google Android System

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

Linux Kernel

Dalvik VM

Dalvik VM

Dalvik VM

DEX DEXActivity Service

ResourcesDEX

Page 14: Lecture 24 – Google Android System

● 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

Android DEXFile Header

String Table

Class List

Field Table

Method Table

Local Variable List

...

DEX File Format

Page 15: Lecture 24 – Google Android System

Android KernelAndroid KernelRelies on Linux version 2.6 for core

servicesSecurity◦ Leverage Linux Users and Permissions

Memory managementProcess managementNetwork stackDriver model

cs423 Fall 2011

Page 16: Lecture 24 – Google Android System

Android Application Android Application ArchitectureArchitectureViews:◦ 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

Page 17: Lecture 24 – Google Android System

Android Application Android Application ArchitectureArchitectureServices (Background)◦ 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

Intent

Page 18: Lecture 24 – Google Android System

ViewViewLayout of visual interface

Java Code ◦ Initialize

◦ Access TextView myTextView =

(TextView)findViewById(R.id.myTextView);

<?xml version=”1.0” encoding=”utf-8”?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent”><TextView android:id=”@+id/myTextView” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”Hello World, HelloWorld”/></LinearLayout>

@Overridepublic void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.screen);}

screen.xml

Page 19: Lecture 24 – Google Android System

View ComponentView ComponentWidget Toolbox◦ TextView, EditText,Button, Form, TimePicker…◦ ListView (PeerList)Update list by arraysArrayAdaptermyListView.setAdapter

◦ LayoutPositions of controlsLinearLayout, Relativelayout

◦ http://developer.android.com/guide/tutorials/views/index.html

Menu◦ Exit app

Page 20: Lecture 24 – Google Android System

ActivityActivityForeground Activity: suspended when

invisible◦ Visual, interactive◦ Ex: Game, Map

Background Service: Little interaction ◦ Ex: Hardware, power management

Page 21: Lecture 24 – Google Android System

User Interaction Event User Interaction Event onKeyDown. onKeyUp onTrackBallEvent onTouchEvent

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; }});}

registerButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {….}}

Page 22: Lecture 24 – Google Android System

User Interaction Event User Interaction Event onKeyDown. onKeyUp onTrackBallEvent onTouchEvent

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; }});}

registerButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {….}}

Page 23: Lecture 24 – Google Android System

Application and Component GluesApplication and Component GluesAn intent is an abstract description of an

operation to be performed.◦ Launch an activityExplicit

Implicit: Android selects the best startActivity();◦ Subactivity: feedbackChild: use intent as feedback, setResultParent: onActivityResultstartActivityForResult◦ Action, data, extra parameterintent.putExtra(name, property);

Ex: Intent intent = new Intent(MyActivity.this, MyOtherActivity.class);

Im: Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse(“tel:555-2368”));

Page 24: Lecture 24 – Google Android System

IntentIntentBroadcast◦ 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.

<activity …> <intent-filter> <actionandroid:name=”com.paad.earthquake.intent.action.SHOW_DAMAGE”> </action> <category android:name=”android.intent.category.DEFAULT”/> <categoryandroid:name=”android.intent.category.ALTERNATIVE_SELECTED”/> <data android:mimeType=”vnd.earthquake.cursor.item/*”/> </intent-filter></activity>

Manifest.xml

Page 25: Lecture 24 – Google Android System

Intent from Peerlist to MessagingIntent from Peerlist to Messaging

PeerList Messaging

Select a peerSend Intent

Page 26: Lecture 24 – Google Android System

ServiceService Service class◦ public class MyService extends Service ◦ public void onStart() {…}

Manifest.xml◦ <service android:enabled=”true”

android:name=”.MyService”></service>

Control◦ startService◦ stopService

Communication◦ Bind service with activity: use public method and properties◦ Intent

Page 27: Lecture 24 – Google Android System

Working in BackgroundWorking in BackgroundServices ◦ 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

Page 28: Lecture 24 – Google Android System

Activity Lifetime

Page 29: Lecture 24 – Google Android System

Declaration of App – Manifest.xmlDeclaration of App – Manifest.xml Service Activity (intent-filter) Permission◦ Don’t forget. Otherwise, your

programming won’t work

Page 30: Lecture 24 – Google Android System

External ResourcesExternal Resourcesvalues/◦ String, color, array, dimension, style theme

drawables/◦ Image

layout/◦ screen.xml

Page 31: Lecture 24 – Google Android System

ToolsTools 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

Page 32: Lecture 24 – Google Android System

Conclusion Conclusion Important concepts at the application

framework levelNew concepts◦ Activities, Broadcast Listeners, Intents◦ Paying attention to GUI And Overall User

interactions◦ Specialized lifecycle

cs423 Fall 2011 32

Page 33: Lecture 24 – Google Android System

ReferenceReferenceOnline 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)