Lecture 3 Android Internals

Similar documents
Android Internals. Lecture 3. Operating Systems Practical. 19 October 2016

Android Internals. Lecture 1. Android and Low-level Optimizations Summer School. 13 July 2015

Lecture 1 - Introduction to Android

Another difference is that the kernel includes only the suspend to memory mechanism, and not the suspend to hard disk, which is used on PCs.

Introduction. Lecture 1. Operating Systems Practical. 5 October 2016

Android: Under the Hood. GDG-SG DevFest 5th Nov 2016 Jason Zaman

Kernel hacking su Android. Better Embedded Andrea Righi

ANDROID NATIVE APP: INTRODUCTION TO ANDROID. Roberto Beraldi

Japan Linux Symposium Daisuke Numaguchi Tetsuo Handa Giuseppe La Tona NTT DATA CORPORATION

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Android Fundamentals - Part 1

Android System Development Training 4-day session

UnCovert: Evaluating thermal covert channels on Android systems. Pascal Wild

Android Internals and the Dalvik VM!

Minimizing Boot Time of Android Based Devices

Android System Development Day-4. Team Emertxe

Android AOSP Overview. Karthik Dantu and Steve Ko

Towards Verifying Android Apps for the Absence of No-Sleep Energy Bugs

DeepDroid: Dynamically Enforcing Enterprise Policy on Android Devices

CS378 - Mobile Computing. Anatomy of an Android App and the App Lifecycle

Drowsy Power Management. Matthew Lentz James Litton Bobby Bhattacharjee University of Maryland

MY FIRST ANDROID TM. Peter Aagaard Kristensen

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

In a Bind? Android s Binder in depth. Jonathan Levin

Android Architecture and Binder. Dhinakaran Pandiyan Saketh Paranjape

Lecture 2 Android SDK

Understanding and Detecting Wake Lock Misuses for Android Applications

Lecture 1 Introduction to Android. App Development for Mobile Devices. App Development for Mobile Devices. Announcement.

21. This is a screenshot of the Android Studio Debugger. It shows the current thread and the object tree for a certain variable.

Introduction to Android

Understanding and Detecting Wake Lock Misuses for Android Applications

The Penguin and the Droid

Android on Tizen. Moscow State University

Security-enabled Middleware for Android on Odroid

ios vs Android By: Group 2

Customization of Android and Performance Analysis of Android Applications in Different Environments

Chapter 2: Operating-System Structures

Android Memory Management

Mobile Application Development - Android

CS260 Intro to Java & Android 04.Android Intro

Mobile and Ubiquitous Computing: Android Programming (part 1)

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Services are software components designed specifically to perform long background operations.

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Chapter 2. Operating-System Structures

CHAPTER 3 - PROCESS CONCEPT


COLLEGE OF ENGINEERING, NASHIK-4

The Case for Security Enhanced (SE) Android. Stephen Smalley Trusted Systems Research National Security Agency

Mobile OS. Symbian. BlackBerry. ios. Window mobile. Android

Interoperation of tasks

Lecture 4 Native libraries

Analysis on Process Code schedule of Android Dalvik Virtual Machine

Security Philosophy. Humans have difficulty understanding risk

Android framework. How to use it and extend it

Android - open source mobile platform

Required Core Java for Android application development

Introduction to Android

An Introduction to Android. Jason Chen Developer Advocate Google I/O 2008

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

SHARED ADDRESS TRANSLATION REVISITED

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

2 Lecture Embedded System Security A.-R. Darmstadt, Android Security Extensions

Android Overview. Most of the material in this section comes from

Developer s overview of the Android platform

Operating- System Structures

Lecture 08. Android Permissions Demystified. Adrienne Porter Felt, Erika Chin, Steve Hanna, Dawn Song, David Wagner. Operating Systems Practical

Android System Power and Performance Analyzer

Sandboxing an Android application through system call interposition

Android App Development

Android Application Development

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

Android Programming in Bluetooth Cochlea Group

ITG Software Engineering

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

COSC 3P97 Mobile Computing

Android App Development

Chapter 2: System Structures. Operating System Concepts 9 th Edition

IJRDTM Kailash ISBN No Vol.17 Issue

Applications Mobiles et Internet des Objets Introduction a l architecture d Android

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Chapter 3: Processes. Operating System Concepts 9 th Edition

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

User Guide. Android x86 Modified System. Sponsor: Huan Ren. Compiled by: Zachary Bair, Taronish Daruwalla, Joshua Duong, and Anthony Nguyen

Slides on cross- domain call and Remote Procedure Call (RPC)

Securing Android-Powered Mobile Devices Using SELinux

Android App Development. Muhammad Sharjeel COMSATS Institute of Information Technology, Lahore

Sista: Improving Cog s JIT performance. Clément Béra

Introduction to Android Android Smartphone Programming. Outline University of Freiburg. What is Android? Background University of Freiburg.

Android Debugging ART

Chapter 2: System Structures

ANDROID SYLLABUS. Advanced Android

ELEC 377 Operating Systems. Week 1 Class 2

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Four Components of a Computer System

Improving the bootup speed of AOSP

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Android Debugging and Performance Analysis

Transcription:

Lecture 3 Android Internals This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Linux Kernel Androidized kernel Hundreds of patches over the standard kernel Device-specific functionality, fixes, enhancements Many features get into the mainline kernel Androidisms Wakelocks Low-Memory Killer Binder Anonymous Shared Memory Alarm Logger 2

Wakelocks The Android kernel goes to sleep as often as possible Sometimes you want to keep the system from going to sleep Input from the user, critical operations Wakelocks keep the system awake A wakelock must be obtained by the application when it needs to stay awake Apps communicate with the Power Manager Service when they require a wakelock Device drivers call in-kernel wakelock primitives Included in mainline 3

Low-Memory Killer Linux OOM killer Prevents the activation of the OOM killer (system unlikely to run out of memory) Kills processes with components unused for a long time Based on OOM adjustments mechanism Different OOM kill priorities for different processes The userspace may control OOM killing policies Policies applied at startup by init Modified and enforced by Activity Manager 4

Low-Memory Killer Levels assigned to processes based on their components Levels from -17 to 15 (high -> killed) Threshold (MinFree) for each type of process Foreground app - application in foreground Visible app - visible but not in foreground Secondary server - service Hidden app - hidden, needed by a running app Content provider - provide data Empty app - app not active Starts killing when the threshold is reached 5

Anonymous Shared Memory (ashmem) IPC mechanism SysV IPC can lead to resource leakage in the kernel (vulnerability) Similar to POSIX SHM, differences: Uses reference counting to destroy the memory regions Shrink mapped regions when the system needs memory To shrink a region it must be unpinned First process creates region, uses Binder to share descriptor with other processes System services rely on ashmem Surface Flinger, Audio Flinger Driver included in the staging tree 6

Alarm Uses the RTC and HRT functionalities The setitimer() does not work when the system is suspended (HRT) The application receives the signal when the device wakes up Using RTC, the alarm will be fired even if the system is suspended RTC hardware device Uses HRT by default When the system is about to suspend, it uses RTC 7

Alarm /dev/alarm character device, ioctl() SystemClock, AlarmManager class rely on the driver SystemClock - obtain and set time AlarmManager - provide alarms to apps The driver and AlarmManager use WakeLocks The app that receives the alarm runs before the system is suspended again Included in the staging tree 8

Logger Uses kernel buffers for logging data Circular buffers in RAM No task switch, no writing in files (compared to syslog) Avoiding write operations in files is critical on Android devices Each buffer - separate entry in /dev/log (Events, System, Radio, Main) logcat displays the Main buffer by default 9

Logger Log and EventLog classes - public API Developers use Log EventLog used by the system components Diagnostic events Slog - system use (AOSP) 10

Logging Messages Through liblog library Logging from java classes Used by logcat Formatting and filtering Log message Priority, tag and data for each event Priority: verbose, debug, info, warn, error Tag: identifies the component that generated the message Staging tree 11

Logging System 12

Binder History RPC mechanism Initially in BeOS (then bought by Palm) OpenBinder project OpenBinder developers working in Android team Android Binder does not derive from OpenBinder Clean re-write of the same functionality OpenBinder documentation for understanding the mechanism Binder driver in the staging tree from kernel 3.3 13

Binder Remote object invocation Remote services as objects Interface definition and reference to it Cornerstone of Android architecture Apps talk to System Server Apps talk to other service components Developers don t use the Binder directly Use interfaces and stubs generated with the aidl tool 14

Binder Driver Part of the Binder implemented in a kernel driver Character device /dev/binder Uses ioctl() calls Transmit parcels of data (serialized) between entities 15

Android Framework On top of the native userspace android.* packages, System Services, Android Runtime Code in /frameworks directory in AOSP Key building blocks: Service Manager, Dalvik, Zygote 16

System Services Form an object-oriented OS on top of Linux System Server All components run in the system_server process Many Java-based services/managers, 2 C-based services Power Manager, Activity Manager, Location Manager, etc. Surface Flinger, Sensor Service (C/C++) Media Server mediaserver process C/C++ code Audio Flinger, Media Player Service, Camera Service 17

Service Manager Performs system service handle lookups The Yellow pages book of all services A service must be registered to the Service Manager to be available Started by init before any other service Opens /dev/binder and becomes the Context Manager of the Binder Binder ID 0 = magic object = Service Manager 18

Service Manager System Server registers every service with the Service Manager Any app that wants to talk to a system service: Asks the Service Manager for a handle getsystemservice() Invokes the methods of the service using the handle Not used by an app to access its own service Used by the dumpsys utility to obtain the status of the system services 19

Dalvik Dalvik virtual machine Java VM optimized for mobile architectures Lower memory footprint Works with.dex files instead of.jar files Incompatible with Java bytecode Register based, not stack based 16 bit instructions 20

Dalvik Includes Just-in-Time (JIT) compiler ARM, x86, MIPS Translates bytecode into binary machine instructions Code runs directly on the CPU, not one instruction at a time by the VM The conversion is stored and used next time the application runs Apps run much faster 21

Zygote Daemon used to launch apps Listens to connections on its socket for requests to start apps /dev/socket/zygote When it gets a request, it forks itself and launches the app Preloads (in RAM) all Java classes and resources needed by an app Copy-on-write (COW) Classes and resources are not modified, so all apps use them from Zygote (only one copy in RAM) The System Server is started explicitly by Zygote The PPID of all apps is the PID of Zygote 22

Activity Manager One of the most important services in the System Server Handles application lifecycle Broadcasts intents Starting new components (activities, services) Fetching Content Providers Responsible with the Application Not Responding (ANR) messages Involved in Permission checks OOM adjustments for the Low-Memory Killer Task management 23

Activity Manager Starts the Launcher (with Intent.CATEGORY_HOME) When an app is started from Launcher Launcher s onclick() callback is called Launcher calls the startactivity() from ActivityManager (through Binder) ActivityManager calls startviazygote() method Opens socket to Zygote and asks to start the activity am command for invoking the functionality of the ActivityManager isuseramonkey() 24

Package Manager Manages the.apk files in the systems API for installing, uninstalling, upgrading.apk files system_server and installd processes Ensures that the JIT versions of the dex bytecode is available before the app is started Resolves intents pm command for invoking the functionality of the PackageManager 25

Power Manager Control the power state of the device Handles WakeLocks Includes the WakeLock class acquire(), release() Apps request WakeLocks from PowerManager All calls to the Power Management (kernel) go through PowerManager Can force device to go to sleep Set the brightness of the backlights 26

Bibliography Karim Yaghmour, Embedded Android: Porting, Extending, and Customizing, Chapter 2 27

Keywords WakeLocks Low-Memory killer Binder Ashmem Alarm Logger System Server Service Manager Dalvik Zygote Activity Manager Package Manager 28