Android Architecture PDF

Document Details

IntricateVerse

Uploaded by IntricateVerse

University of Bologna

Federico Montori

Tags

android architecture mobile development software engineering

Summary

This presentation discusses the architecture of the Android operating system, including its history, advancements, and key components. It details different versions and components of Android.

Full Transcript

Laboratorio di Applicazioni Mobili Bachelor in Computer Science & Computer Science for Management University of Bologna Android Architecture Federico Montori [email protected] 1 Table of Contents Android...

Laboratorio di Applicazioni Mobili Bachelor in Computer Science & Computer Science for Management University of Bologna Android Architecture Federico Montori [email protected] 1 Table of Contents Android History Android Data Android Architecture ○ Kernel ○ HAL ○ NDK ○ ART ○ APIs ○ System Apps Overview on App Components XML App Distribution 2 Android Android is a Linux-based platform for mobile touchscreen devices … Operating System Middleware Applications Software Development Kit (SDK) Which mobile devices? 3 SMARTPHONES TABLETS EREADERS ANDROID TV GOOGLE GLASSES AUTOMOTIVE Android 2005 Google buys Android from the Android Inc. 2006 Open Handset Alliance (OHA) created for open standards for mobile devices. Partners of OHA: Google, Motorola, Samsung, 2007 Vodafone, T-Mobile, etc. Android 1.0 Released 2008 The first Android smartphone: G1 HTC-Dream Few Google apps integrated directly with the OS 2009 Android 1.1 Released External Apps Time Android 1.5 (CupCake) Released On-screen keyboard 4 2008 Android Different screen sizes Android 1.6 (Donut) Released CDMA 2009 speech-to-text Android 2.0 (Eclair) Released pinch-to-zoom Android 2.2 (Froyo) Released bottom dock 2010 voice actions Android 2.3 (Gingerbread) Released The “design 2011 release” Android 3.0 (Honeycomb) Released (First version for devices with larger screens such as tablets) 2012 Android 4.0 (Ice-Cream Sandwich) Released. (It merges the 3.x tab centric design and the v2.x phone based design into a single version.) Time swiping for dismissing 5 card appearance Android 2012 Android 4.1 (Jelly Bean) Released 2013 Android 4.4 (Kitkat) Released OK (bu GO t on O hen GLE ly w ○ Wireless printing capability scr ! the 2014 ○ Ability for applications to use "immersive mode” een is o n… ○ Performance optimization ) ○ New experimental runtime virtual machine, ART… API Level 19 (Android 4.4): ○ ○ Support to new embedded sensors (e.g. STEP_DETECTOR) ○ Adaptive video playback functionalities ○ Read and write SMS and MMS messages ○ (managing default text messaging client) 6 Time Android 2014 Android 5.0 (Lollipop) Released ○ Material Design! ○ OK Google (the true one) ○ Lots of bugs... 2015 Android 6.0 (Marshmallow) Released ○ Fingerprint ○ USB-C 2016 ○ Runtime Permissions!!! Android 7.0 (Nougat) Released … pixel! ○ Google Assistant ○ Split screen, data saver... 7 Time Android 2017 Android 8.0 (Oreo) Released ○ Notification Channels and Snooze ○ picture-in-picture ○ Android Apps on Chromebooks 2018 Android 9.0 (Pie) Released ○ Brightness & Battery Management ○ Hybrid gestures system 2019 ○ Privacy & Security Android 10.0 (Q) Released ○ Expanded permission ○ swipe-driven 8 Time ○...No more sweets!!! Android 2020 In February Android 11.0 (R) Released ○ One-time permissions for temporary features (location, microphone and camera) 2021 ○ Exposure notification and privacy fixes In October Android 12.0 (S) Released ○ Location can be blurred even if required ○ Mostly optimizations and ○ graphical improvements Android 13.0 (Tiramisu) Released 2022 ○ per-app language personalization ○ permission for notification ○ gallery restricted access to apps 9 Time Android 2023 In October 2023 Android 14.0 (Upside Down Cake) Released ○ Mostly a UI improvement 2024 ○ Battery optimization 2025 10 Time Android Data Takeaway message: There is a lot of versioning to deal with… 11 Android Data Takeaway message: There is a lot of 11,868 different devices in 2013! different devices to take into account 12 Android Data Takeaway message: There is a lot of 24,093 different devices in 2015! different devices to take into account 13 Android Data Takeaway message: There is a lot of different devices to take into account 14 Android Data Takeaway message: There is a lot of different devices to take into account 15 Android Data Takeaway message: There is a lot of different conditions that we need to take into account 16 Android Architecture The rest of the course will be dedicated on how to build Apps… … but what is underneath? 17 Android Architecture OS is Built on top of Linux kernel Advantages: Portability (i.e. easy to compile on different hardware architectures) Security (e.g. secure multi-process environment) Power Management Android Runtime (ART) relies on the kernel for threads and memory management Manufacturers build drivers on top of a reliable kernel 18 Android Architecture User based permission model Processes are isolated Inter-process communication (IPC) Resources are protected from other processes Each application has its own User ID (UID) ○ This means that in Android, each App is a different Linux User Application Sandbox (process isolation) Verified boot 19 Android Architecture Android 5.0: ○ Mandatory Access Control (MAC) between system and apps, all third-party apps ran within the same SELinux context so inter-app isolation was primarily enforced by UID-based sandbox. Android 8.0: ○ limited system calls available to user-level apps 20 Android Architecture Android 9.0: ○ all non-privileged apps with SDK version >= 28 must run in individual SELinux sandboxes, providing MAC on a per-app basis Android 10: ○ apps have a limited raw view of the filesystem, with no direct access to paths like /sdcard/DCIM. However, apps retain full raw access to their package-specific paths 21 Android Architecture Hardware Abstraction Layer (HAL) Advantages: Shadows the real device Manages different devices of the same type Standard interface to expose lower level capabilities to higher level APIs 22 Android Architecture HAL: Standard interface defined by Android that manufacturers have to implement – Android is agnostic about lower level driver implementations. Application developers rely on common APIs Depending on the hardware, appropriate libraries are loaded 23 Android Architecture Native C/C++ Libraries Graphics (Surface Manager) Multimedia (Media Framework) Database DBMS (SQLite) Font Management (FreeType) WebKit C libraries (Bionic) 24 Android Architecture The NDK Enables C/C++ coding Useful if you want to interact/extend with some native libraries ○ Performance ○ Reuse your C/C++ libraries JAVA APIs are provided for most used libraries NDK can be installed as an Android Studio plugin public class myNDKActivity extends Activity { public native void doNothing() { } } 25 Android Architecture the NDK can be useful for cases in which you need to do one or more of the following: Squeeze extra performance out of a device to achieve low latency or run computationally intensive applications, such as games or physics simulations: https://developer.android.com/ndk/guides Reuse your own or other developers' C or C++ libraries. Usage: Use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework. 26 Android Architecture Android Runtime (ART) It is a Java Virtual Machine (JVM) implementation (not using the Oracle JVM) optimized for memory-constrained devices It has everything that an ordinary JVM has: interprets bytecode compilation of Java code into bytecode is done in the SDK!! a little differently though… 27 Android Architecture Starting from Android 5.0, ART is used instead of Dalvik Several enhancements such as stack size, error handling, Optimized Garbage collection, AOT... Designed to run multiple VM on low end devices Runs DEX bytecode Ahead-of-time (AOT) and Just-in-time (JIT) compilation AOT: At install time, ART compiles APPs using an on-device tool called dex2oat ○ Code compiled at installation JIT: code profiling ○ Code partially interpreted when compiled is not available 28 Android Architecture There is a lot more to it nowadays. DEX files need to be interpreted by the VM (or JIT compiled). OAT files are already “machine level” code, so more similar to pure compilation. We have a daemon that looks for uncompiled apps when the device is idle and compiles them through. Compiled apps may be recompiled sometimes by JIT if the conditions have changed… 29 Android Architecture AOT and JIT replace the code interpretation that was classic for Java. However, their management is complex (see aside). Do not confuse AOT and JIT with the “compilation” that takes place when developing the app and outputs an APK… ○ The latter outputs bytecode, which still is not machine code. 30 Android Architecture APIs (Core Components of Android) Activity Manager Packet Manager Telephony Manager Location Manager Contents Provider Notification Manager … 31 Android Architecture View System ○ Through which you build the APP UI Resource Manager ○ Through which you handle resources Notification Manager ○ Through which you can access to different kind of notifications Activity Manager ○ Which handles the Activity lifecycle and provides a back stack Content Providers ○ To share data among APPs 32 Android Architecture System Apps Applications that come with the system by default and have enhanced privileges. e.g. the alarm clock can wake up the phone even if it is turned off. This is unimplementable by a developer. 33 App Components Activities Views Resources Intents Services Persistence 34 App Components An Activity corresponds to a single screen Android HelloWorld of the Application. An Application can be composed of Button1 multiples screens (Activities). Hello World! The Home Activity is shown when the user launches an application. Different activities can exchange information one with each other. 35 App Components Each activity is composed by a list of graphics components. Some of these components (called Views) can interact with the user by handling events (e.g. Buttons). Two ways to build the graphic interface: Programmatic Approach: Button button = new Button (this); TextView text = new TextView(); text.setText(“Hello world”); 36 App Components Each activity is composed by a list of graphics components. Some of these components (called Views) can interact with the user by handling events (e.g. Buttons). Two ways to build the graphic interface: Declarative Approach: 37 XML Extensible Markup Language (XML) lets you define and store data in a shareable manner. Data is organized in a tree and each element contains text and/or children and it is wrapped between a start and an end tag. 30 38 App Components Build the application layout through XML files. Define different XML layouts for Device 1 Device 2 HIGH screen pixel density LOW screen pixel density different devices At runtime, Android detects the current Java App Code device configuration and loads the appropriate resources No need to recompile! This stands for all other resources XML Layout File XML Layout File 39 Device 1 Device 2 App Components Android applications typically use both the approaches! DECLARATIVE APPROACH Define the Application layouts XML Code and resources used by the Application (e.g. labels). PROGRAMMATIC APPROACH Manages the events, and handles the interaction with the Java Code 40 user. App Components Views can generate events (caused by human interactions) that must be managed by the Android-developer through CALLBACKS (from now on you need to know what these are) TextEdit Button public void onClick(View arg0) { if (arg0 == Button) { } } 41 App Components Main difference between Android programming and Java (Oracle) programming: Mobile devices have constrained resource capabilities Activity lifecycle depends on users’ choice (i.e. change of visibility) as well as on system constraints (i.e. memory shortage). Developer must implement lifecycle methods to account for state changes of each Activity … there is no main function. This is a reactive programming style! 42 App Components Intents: asynchronous messages to activate core Android components (e.g. Activities). Explicit Intent 🡪 The component (e.g. Activity1) specifies the destination of the intent (e.g. Activity2). LOGIN Welcome Luca! luca Activity1 Activity2 PASSWORD ********** Login Intent Login 43 App Components Intents: asynchronous messages to activate core Android components (e.g. Activities). Implicit Intent →The component (e.g. Activity1) specifies the type of the intent (e.g. “View a video”). Activity2 Multiple choices } might be available Activity1 to the user! Intent- View Filters Activity3 Implicit Intent 44 App Components Services: like Activities, but run in background and do not provide an user interface. Used for non-interactive tasks (e.g. networking). Starting Destroyed onCreate() onDestroy() onStart() Running (on background) 45 App Components Android 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. Applications statically declare the permissions they require. User must give his/her consensus upon using the feature. Permission must be asked at runtime too. ANDROIDMANIFEST.XML

Use Quizgecko on...
Browser
Browser