ANDROID SYSTEM ARCHITECTURE Instructor Mazhar Hussain OUTLINE Android

  • Slides: 39
Download presentation
ANDROID: SYSTEM ARCHITECTURE Instructor: Mazhar Hussain

ANDROID: SYSTEM ARCHITECTURE Instructor: Mazhar Hussain

OUTLINE Android Architecture: An Overview Android Components: Activities Android Components: Intents Android Components: Services

OUTLINE Android Architecture: An Overview Android Components: Activities Android Components: Intents Android Components: Services Android Components: Content Providers Android Application Distribution and Markets 2 Android Dalvik Java Virtual Machine

ANDROID … WHAT? Android 3 is a Linux-based platform for mobile devices … Operating

ANDROID … WHAT? Android 3 is a Linux-based platform for mobile devices … Operating System Middleware Applications Software Development Kit (SDK) Which kind of mobile devices … (examples) SMARTPHONES TABLETS EREADERS ANDROID TV GOOGLE GLASSES ?

ANDROID …WHEN? Ø Google buys Android from the Android Inch 2006 Ø Open Handset

ANDROID …WHEN? Ø Google buys Android from the Android Inch 2006 Ø Open Handset Alliance (OHA) created for open standards for mobile devices. Partners of OHA: 4 2005 Google, Motorola, Samsung, Vodafone, T-Mobile, etc 2007 2008 2009 Ø Android 1. 0 Released Ø The first Android smartphone: G 1 HTC-Dream Ø Android 1. 1 Released Android 1. 5 (Cup. Cake) Released Ø Time

ANDROID …WHEN? 2008 Android 1. 6 (Donut) Released Ø Android 2. 0 (Eclair) Released

ANDROID …WHEN? 2008 Android 1. 6 (Donut) Released Ø Android 2. 0 (Eclair) Released Ø Android 2. 2 (Froyo) Released Ø Android 2. 3 (Gingerbread) Released Ø Android 3. 0 (Honeycomb) Released 5 Ø 2009 2010 2011 2012 Time (First version for devices with larger screens such as tablets) Ø Android 4. 0 (Ice-Cream Sandwich) Released. (It merges the 3. x tab centric design and the v 2. x phone based design into a single version. )

ANDROID …WHEN? 2012 Ø Android 4. 2 (Jelly Bean) Released Ø 2013 Ø Ø

ANDROID …WHEN? 2012 Ø Android 4. 2 (Jelly Bean) Released Ø 2013 Ø Ø Ø KEY LIME PIE Gesture Mode for Accessibility Improved browser performance Easy data-sharing through NFC Improved camera and face recognition functionalities … API Level 17 (Android 4. 2): Time Ø Daydream: screensaver customization API Ø Support to multi-user environments Ø Nested fragments for UI improvements Ø … 6 Ø

ANDROID …WHEN? ANDROID DISTRIBUTIONS ANDROID APPLICATIONS 7 x http: //developer. android. com/about/dashboards/index. html http:

ANDROID …WHEN? ANDROID DISTRIBUTIONS ANDROID APPLICATIONS 7 x http: //developer. android. com/about/dashboards/index. html http: //www. appbrain. com/stats/android-marketapp-categories

ANDROID …WHEN? http: //en. wikipedia. org/wiki/Android_version_history 8 1. 6 -2. 0 ANDROID VERSION HISTORY

ANDROID …WHEN? http: //en. wikipedia. org/wiki/Android_version_history 8 1. 6 -2. 0 ANDROID VERSION HISTORY AND POPULARITY 2. 2. x 2. 3. x (2009 -2013) 4. x

THE ANDROID ARCHITECTURE 9 } Stack Architectu re Open Source Architecture (Apache/MIT License v.

THE ANDROID ARCHITECTURE 9 } Stack Architectu re Open Source Architecture (Apache/MIT License v. 2. 0) Business-friendly License

THE ANDROID ARCHITECTURE 10 Built on top of Linux kernel (v. 2. 6 -3.

THE ANDROID ARCHITECTURE 10 Built on top of Linux kernel (v. 2. 6 -3. 0) Advantages: Ø Portability (i. e. easy to compile on different harwdare architectures) Ø Security (e. g. secure multi-process environment) Ø Power Management

THE ANDROID ARCHITECTURE Native Libraries (C/C++ code) ØGraphics (Surface Manager) 11 ØMultimedia (Media Framework)

THE ANDROID ARCHITECTURE Native Libraries (C/C++ code) ØGraphics (Surface Manager) 11 ØMultimedia (Media Framework) ØDatabase DBMS (SQLite) ØFont Management (Free. Type) Ø Web. Kit ØC libraries (Bionic) Ø….

THE ANDROID ARCHITECTURE Application Libraries (Core Components of Android) 12 ØActivity Manager ØPacket Manager

THE ANDROID ARCHITECTURE Application Libraries (Core Components of Android) 12 ØActivity Manager ØPacket Manager ØTelephony Manager ØLocation Manager ØContents Provider ØNotification Manager Ø….

THE ANDROID ARCHITECTURE Applications 13 (Written in Java code) ØAndroid Play Store ØEntertainment ØProductivity

THE ANDROID ARCHITECTURE Applications 13 (Written in Java code) ØAndroid Play Store ØEntertainment ØProductivity ØPersonalization ØEducation ØGeocommunication Ø….

THE ANDROID ARCHITECTURE 14 Dalvik Virtual Machine (VM) ØNovel Java Virtual Machine implementation (not

THE ANDROID ARCHITECTURE 14 Dalvik Virtual Machine (VM) ØNovel Java Virtual Machine implementation (not using the Oracle JVM) ØOpen License (Oracle JVM is not open!) ØOptimized for memory-constrained devices ØFaster than Oracle JVM

DALVIK JAVA VIRTUAL MACHINE (JVM) Java Standard Edition Java Compiler Java Byte Code Stack-based

DALVIK JAVA VIRTUAL MACHINE (JVM) Java Standard Edition Java Compiler Java Byte Code Stack-based byte-code Java Virtual Machine (JVM) Java Source Code Java Compiler 15 Java Source Code Java Byte Code Dalvik Virtual Machine (VM) Dex Compiler Register-based byte-code

ANDROID APPLICATIONS DESIGN APPLICATION DESIGN: Definition Ø Events Management Ø Application Data Management Ø

ANDROID APPLICATIONS DESIGN APPLICATION DESIGN: Definition Ø Events Management Ø Application Data Management Ø Background Ø User Operations Notifications 16 Ø GUI

ANDROID APPLICATIONS DESIGN APPLICATION COMPONENTS Ø Intents Ø Services Ø Content Ø Providers Broadcast

ANDROID APPLICATIONS DESIGN APPLICATION COMPONENTS Ø Intents Ø Services Ø Content Ø Providers Broadcast Receivers 17 Ø Activities

ANDROID COMPONENTS: ACTIVITIES Ø An 18 Activity corresponds to a single screen of the

ANDROID COMPONENTS: ACTIVITIES Ø An 18 Activity corresponds to a single screen of the Application. Android Hello. World Button 1 Hello World! Ø An Application can be composed of multiples screens (Activities). Ø The Home Activity is shown when the user launches an application. Ø Different activities can exhange information one with each other.

ANDROID COMPONENTS: ACTIVITIES Ø Each 19 activity is composed by a list of graphics

ANDROID COMPONENTS: ACTIVITIES Ø Each 19 activity is composed by a list of graphics components. Ø Some of these components (also called Views) can interact with the user by handling events (e. g. Buttons). PROGRAMMATIC APPROACH Ø Two ways to build the graphic interface: Example: Button button=new Button (this); Text. View text= new Text. View(); text. set. Text(“Hello world”);

ANDROID COMPONENTS: ACTIVITIES Ø Each 20 activity is composed by a list of graphics

ANDROID COMPONENTS: ACTIVITIES Ø Each 20 activity is composed by a list of graphics components. Ø Some of these components (also called Views) can interact with the user by handling events (e. g. Buttons). DECLARATIVE APPROACH Ø Two ways to build the graphic interface: Example: < Text. View android. text=@string/hello” android: textcolor=@color/blue android: layout_width=“fill_parent” android: layout_height=“wrap_content” /> < Button android. id=“@+id/Button 01” android: textcolor=“@color/blue” android: layout_width=“fill_parent” android: layout_height=“wrap_content” />

ANDROID COMPONENTS: ACTIVITIES EXAMPLE - 21 Build the application layout through XML files (like

ANDROID COMPONENTS: ACTIVITIES EXAMPLE - 21 Build the application layout through XML files (like HTML) - Device 1 Device 2 HIGH screen pixel density LOW screen pixel density Java App Code XML Layout File Device 1 Device 2 - - Define two different XML layouts for two different devices At runtime, Android detects the current device configuration and loads the appropriate resources for the application No need to recompile! Just add a new XML file if

ANDROID COMPONENTS: ACTIVITIES Ø Android 22 applications typically use both the approaches! DECLARATIVE APPROACH

ANDROID COMPONENTS: ACTIVITIES Ø Android 22 applications typically use both the approaches! DECLARATIVE APPROACH XML Code Define the Application layouts and resources used by the Application (e. g. labels). PROGRAMMATIC APPROACH Java Code Manages the events, and handles the interaction with the user.

ANDROID COMPONENTS: ACTIVITIES Ø Views Text. Edit Button 23 can generate events (caused by

ANDROID COMPONENTS: ACTIVITIES Ø Views Text. Edit Button 23 can generate events (caused by human interactions) that must be managed by the Android-developer. ESEMPIO public void on. Click(View arg 0) { if (arg 0 == Button) { // Manage Button events } }

ANDROID COMPONENTS: ACTIVITIES Ø The Ø Activities 24 Activity Manager is responsible for creating,

ANDROID COMPONENTS: ACTIVITIES Ø The Ø Activities 24 Activity Manager is responsible for creating, destroying, managing activities. can be on different states: starting, running, stopped, destroyed, paused. Ø Only one activity can be on the running state at a time. Ø Activities are organized on a stack, and have an event-driven

ANDROID COMPONENTS: ACTIVITIES Ø Ø 25 Main difference between Android-programming and Java (Oracle) -programming:

ANDROID COMPONENTS: ACTIVITIES Ø Ø 25 Main difference between Android-programming and Java (Oracle) -programming: Mobile devices have constrained resource capabilities! Ø Activity lifetime depends on users’ choice (i. e. change of visibility) as well as on system contraints (i. e. memory shortage). Ø Developer must implement lifecycle methods to account for state changes of each Activity …

ANDROID COMPONENTS: ACTIVITIES public class My. App extends Activity { Called when the Activity

ANDROID COMPONENTS: ACTIVITIES public class My. App extends Activity { Called when the Activity is created the first time. 26 public void on. Create() {. . . } public void on. Pause() { public void on. Stop() { Called when the Activity is partially visible. . } Called when the Activity is no longer visible. public void on. Destroy(){. . . } …. } Called when the Activity is dismissed.

ANDROID COMPONENTS: INTENTS Ø Intents: 27 asynchronous messages to activate core Android components (e.

ANDROID COMPONENTS: INTENTS Ø Intents: 27 asynchronous messages to activate core Android components (e. g. Activities). Ø Explicit Intent The component (e. g. Activity 1) specifies the destination of the intent (e. g. Activity 2). LOGIN Welcome Marco! Activity 2 Activity 1 marco PASSWO RD ***** Login Intent Login

ANDROID COMPONENTS: INTENTS Ø Intents: Activity 2 Multiple choices might be available to the

ANDROID COMPONENTS: INTENTS Ø Intents: Activity 2 Multiple choices might be available to the user! View Implicit Intent Activity 2 Activity 1 28 asynchronous messages to activate core Android components (e. g. Activities). Ø Implicit Intent The component (e. g. Activity 1) specifies the type of the intent (e. g. “View a video”). } Intent. Filters

ANDROID COMPONENTS: SERVICES Ø Services: 29 like Activities, but run in background and do

ANDROID COMPONENTS: SERVICES Ø Services: 29 like Activities, but run in background and do not provide an user interface. Ø Used for non-interactive tasks (e. g. networking). Ø Service life-time composed of 3 states: Destroy ed Starting on. Create() on. Start() on. Destroy() Running (on background)

ANDROID COMPONENTS: CONTENT PROVIDERS Ø Each APP insert( ) update() delete () query( )

ANDROID COMPONENTS: CONTENT PROVIDERS Ø Each APP insert( ) update() delete () query( ) Conte nt Provid er DB e. g. Photo Gallery 30 Android application has its own private set of data (managed through files or through SQLite database). Ø Content Providers: Standard interface to access and share data among different applications.

ANDROID COMPONENTS: BROADCAST RECEIVERS Ø Publish/Subscribe Ø Broadcast Receivers: An application can be signaled

ANDROID COMPONENTS: BROADCAST RECEIVERS Ø Publish/Subscribe Ø Broadcast Receivers: An application can be signaled of external events. Ø Notification types: Call incoming, SMS delivery, Wifi 31 paradigm

ANDROID COMPONENTS: BROADCAST RECEIVERS BROADCAST RECEIVER example s. append((wifi. List. get(i)). to. String()); s.

ANDROID COMPONENTS: BROADCAST RECEIVERS BROADCAST RECEIVER example s. append((wifi. List. get(i)). to. String()); s. append("\n"); } main. Text. set. Text(sb); 32 class Wifi. Receiver extends Broadcast. Receiver { public void on. Receive(Context c, Intent intent) { String s = new String. Builder(); wifi. List = main. Wifi. get. Scan. Results(); for(int i = 0; i < wifi. List. size(); i++){ s. append(new Integer(i+1). to. String() + ". ");

ANDROID COMPONENTS: BROADCAST RECEIVERS BROADCAST RECEIVER example Wifi. Receiver receiver. Wifi; List<Scan. Result> wifi.

ANDROID COMPONENTS: BROADCAST RECEIVERS BROADCAST RECEIVER example Wifi. Receiver receiver. Wifi; List<Scan. Result> wifi. List; public void on. Create(Bundle saved. Instance. State) { … main. Wifi = (Wifi. Manager) get. System. Service(Context. WIFI_SERVICE); receiver. Wifi = new Wifi. Receiver(); register. Receiver(receiver. Wifi, new Intent. Filter(Wifi. Manager. SCAN_RESULTS_AVAILABLE_AC TION)); main. Wifi. start. Scan(); } 33 public class Wifi. Tester extends Activity { Wifi. Manager main. Wifi;

ANDROID COMPONENTS: SYSTEM API 34 Ø Using the components described so far, Android applications

ANDROID COMPONENTS: SYSTEM API 34 Ø Using the components described so far, Android applications can then leverage the system API … SOME EXAMPLEs … Ø Ø Ø Telephony Manager data access (call, SMS, etc) Sensor management (GPS, accelerometer, etc) Network connectivity (Wifi, bluetooth, NFC, etc) Web surfing (HTTP client, Web. View, etc) Storage management (files, SQLite db, etc) ….

ANDROID COMPONENTS: GOOGLE API 35 Ø … or easily interface with other Google services:

ANDROID COMPONENTS: GOOGLE API 35 Ø … or easily interface with other Google services:

Android Application Distribution Ø 36 APK FILE XM L File s Each Android application

Android Application Distribution Ø 36 APK FILE XM L File s Each Android application is contained on a single APK file. C Ø Java Byte-code (compiled for Dalvik JVM) Ø Resources (e. g. images. videos, XML layout files) Ø Libraries (optimal native C/C++ code)

ANDROID APPLICATION DISTRIBUTION Ø Each 37 application must be signed through a key before

ANDROID APPLICATION DISTRIBUTION Ø Each 37 application must be signed through a key before being distributed. Ø Applications can be distributed via Web or via Stores. Ø Android Play Store: application store run by Google … but several other application stores are available (they are just

ANDROID APPLICATION SECURITY Ø Android Ø Applications 38 applications run with a distinct system

ANDROID APPLICATION SECURITY Ø Android Ø Applications 38 applications run with a distinct system identity (Linux user ID and group ID), in an isolated way. Ø Applications must explicitly share resources and data. They do this by declaring the permissions they need for additional capabilities. statically declare the permissions ANDROIDMANIFEST. XML they require. <uses-permission Ø User must android: name=“android. permission. IACCESS_FINE_LO give his/her consensus during the installation. <uses-permission android: name=“android. permission. INTERNET" />

QUESTIONS/COMMENTS? 39

QUESTIONS/COMMENTS? 39