Kernel hacking su Android. Better Embedded Andrea Righi

Similar documents
Lecture 3 Android Internals

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

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

Lecture 1 - Introduction to Android

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


Android System Development Training 4-day session

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.

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

Android Internals and the Dalvik VM!

Itron Riva Dev Software Development Getting Started Guide

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

Linux Power Management

Google Android on the Beagleboard

Mobile and Ubiquitous Computing: Android Programming (part 1)

Android Sdk Setup For Windows 7 32 Bit Full Version

QEMU: Architecture and Internals Lecture for the Embedded Systems Course CSD, University of Crete (April 18, 2016)

Android AOSP Overview. Karthik Dantu and Steve Ko

Android System Power and Performance Analyzer

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

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

SSE3052: Embedded Systems Practice

syscall_intercept A user space library for intercepting system calls Author Name, Company Krzysztof Czuryło, Intel

Chapter 2. Operating-System Structures

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

Google Android on the Beagleboard

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

NDK OVERVIEW OF THE ANDROID NATIVE DEVELOPMENT KIT

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

Installing and configuring an Android device emulator. EntwicklerCamp 2012

Operating System Services. User Services. System Operation Services. User Operating System Interface - CLI. A View of Operating System Services

Tutorial on Basic Android Setup

IJREAT International Journal of Research in Engineering & Advanced Technology, Volume 1, Issue 5, Oct-Nov, 2013 ISSN:

SEEDAndroid User Manual

Android Power Panagement

Chapter 2: Operating-System Structures

Scrivere device driver su Linux. Better Embedded 2012 Andrea Righi

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

ANDROID NATIVE APP: INTRODUCTION TO ANDROID. Roberto Beraldi

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

Understand Linux Components

Advanced Android Power Management and Implementation of Wakelocks

Efficient Memory Management on Mobile Devices

Android. Separated Kernel build might break the Android build process. Toolchain

Programming Concepts and Skills. Creating an Android Project

Android Programming in Bluetooth Cochlea Group

Basic Android Setup for Machine Vision Fall 2015

Managing network connectivity

Android PC Splash Brothers Design Specifications

Application Access to Persistent Memory The State of the Nation(s)!

Around Android. Essential Android features illustrated by a walk through a practical example

INDUSTRIALIZE YOUR ROM COOKING: Good practices

Install ADB on Windows

Deby - Reproducible and Maintainable Embedded Linux Environment with Poky

DEVELOPERS MANUAL. Philip SUPER HAPPY FUN FUN INC Research Blvd. Suite C-220 Austin, TX, 78759

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

EL2310 Scientific Programming

Power Management for Embedded Systems

Android Memory Management

The Kernel Abstraction. Chapter 2 OSPP Part I

Introduction to Computer Systems

Embedded Systems Programming

CSE 351. Introduction & Course Tools

Building an Android* command-line application using the NDK build tools

Mobile and Wireless Systems Programming

Tegra 250 Development Kit Android Setup Experience

Lab2 - Bootloader. Conventions. Department of Computer Science and Information Engineering National Taiwan University

The Beast We Call A3. CS 161: Lecture 10 3/7/17

Android Forensics. Investigation, Analysis, Google Android. and Mobile Security for. Andrew Hoog. John McCash, Technical Editor SYNGRESS

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Project 2: Android Scheduler

CS260 Intro to Java & Android 04.Android Intro

MY FIRST ANDROID TM. Peter Aagaard Kristensen

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

Operating Systems Design 25. Power Management. Paul Krzyzanowski

Abusing Android In-app Billing feature thanks to a misunderstood integration. Insomni hack 18 22/03/2018 Jérémy MATOS

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

CS 3305 Intro to Threads. Lecture 6

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14

xpress Release Notes

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

OWASP German Chapter Stammtisch Initiative/Ruhrpott. Android App Pentest Workshop 101

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

Android Application Sandbox. Thomas Bläsing DAI-Labor TU Berlin

Introduction to Computer Systems

REX-RED Community Android 4.3

Definition: An operating system is the software that manages resources

CSE 153 Design of Operating Systems Fall 2018

Wirtschaftsinformatik Skiseminar ao. Prof. Dr. Rony G. Flatscher. Seminar paper presentation Dennis Robert Stöhr

Operating Systems. VI. Threads. Eurecom. Processes and Threads Multithreading Models

Running on the Bare Metal with GeekOS

Infrastructure Middleware (Part 3): Android Runtime Core & Native Libraries

Android Software Development Kit (Part I)

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

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Lab 5: Android Development Environment

Mon Sep 17, 2007 Lecture 3: Process Management

Part A: Setup your kernel development environment

CSE 303 Lecture 8. Intro to C programming

Release Notes Zebra TC51, TC56, TC70x and TC75x Android M LifeGuard Update 10 Release for Non-GMS

Transcription:

Kernel hacking su Android

Agenda Overview Android Programming Android Power Management Q/A

Overview

What is Android OS? Linux kernel Android patches Bionic libc Dalvik VM (Java Virtual Machine) Application framework Apps

Android: kernel modifications binder: IPC (i.e., communication between window manager and client) ashmem: shared memory (process cache) pmem: physically contiguous memory allocator logger: custom system logging facility wakelock: power management (hold machine awake on a per-event basis until wakelock is released) early suspend: suspend/resume hooks to be called when user-visible sleep state change lowmemorykiller (aka Viking Killer): custom OOM killer tunable from userspace (memory thresholds and oom_adjust thresholds) alarm timers: RTC-based wakeup timed gpio: driver that allows userspace programs to access and manipulate gpio pins and restore their state automatically after a specified timeout ram console: store kernel log to a persistent RAM area, so that after a kernel panic it can be viewed via /proc/last_kmsg USB gadget driver (ADB) YAFFS2 filesystem Lots of other small fixes and hacks...

Native libraries Bionic libc Custom libc implementation, optimized for embedded use (optimized for size) Don't support all the POSIX features Not compatible with GNU Libc (glibc) Native code must linked against bionc libc (or statically linked)

Android Programming

Programming model Android applications are written in Java Class libraries are similar to Java SE but not equal Dalvik VM is a register-based architecture that dynamically translates from Java byte code into native architecture instructions However It's still Linux, so we can build and run native Linux applications Use the JNI bridge to bind C functions into the Java code

Android applications Applications are distributed as Android packages (.apk) Everything is needed to run an application is bundled inside the.apk Basically an enhanced ZIP file

Typical directory tree in Android / (initrd ro) /system (ro) /system/bin /system/etc /system/lib /system/usr /data (applications data rw) /cache (applications cache rw) /mnt/sdcard (removable storage rw)

Toolchain From http://developer.android.com Android SDK http://developer.android.com/sdk/index.html Android NDK http://developer.android.com/sdk/ndk/index.html From http://www.codesourcery.com ARM toolchain to recompile the Linux kernel (get the one targeted at EABI ) https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription3053 ARM toolchain for native userspace applications (get the one targeted at "GNU/Linux") https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription3057

Android emulator: goldfish The Android emulator runs a virtual CPU that Google calls Goldfish. Goldfish executes ARM926T instructions and has hooks for input and output -- such as reading key presses from or displaying video output in the emulator These interfaces are implemented in files specific tothe Goldfish emulator and will not be compiled into a kernel that runs on real devices.

Create an Android application # create a new project android create project --package com.develer.hello --activity HelloAndroid \ --target 2 --path./helloandroid # build in release mode ant release # sign a apk jarsigner -verbose -keystore ~/certs/android.keystore \./bin/helloandroid-unsigned.apk arighi # align the apk zipalign -v 4./bin/HelloAndroid-unsigned.apk./bin/HelloAndroid.apk # install adb install./bin/helloandroid.apk # uninstall adb uninstall HelloAndroid

Create a native ARM application #include <stdio.h> int main(int argc, char **argv) { printf( Hello, world!\n ); return 0; } Build & run: $ arm-none-linux-gnueabi-gcc -static -o hello hello.c $ adb push hello /data/local/tmp/hello $ adb shell chmod 777 /data/local/tmp/hello $ adb shell /data/local/tmp/hello

Run a custom kernel (Android emulator) $ git clone https://android.googlesource.com/kernel/goldfish $ git checkout android-goldfish-2.6.29 $ export PATH=/opt/toolchain/arm-eabi-2011.03-42/bin:$PATH $ make ARCH=arm CROSS_COMPILE=arm-none-eabi- goldfish_defconfig $ make ARCH=arm CROSS_COMPILE=arm-none-eabi- $ emulator -kernel arch/arm/boot/zimage -avd <AVD_NAME>

Android Power Management

Android typical use case Most of the time the device is in you pocket, completely in idle (suspend) You pull it ouf of your pocket maybe once, twice in a hour Check the email, facebook, twitter, etc. for short bursts of time

Android Power Management Android will opportunistically enter a full system suspend state This forcibly stops processes from running Your battery last longer and your phone doesn't melt in your pocket

CPU State Running Idle Deep sleep Suspend Powered off

Android PM Features Early suspend Wakelocks Alarm Timer

Early suspend Suspend / resume kernel hooks called when user-visible sleep states change User-space framework writes the state to /sys/power/request_state

Early suspend static struct early_suspend _powersave_early_suspend = {.suspend = powersave_early_suspend,.resume = powersave_late_resume, }; register_early_suspend(&_powersave_early_suspend); unregister_early_suspend(&_powersave_early_suspend);

Wake locks 1/2 Used by applications to prevent the system from entering suspend or low-power state Driver API struct wake_lock name wake_lock_init()/wake_lock()/wake_unlock() Userspace API Write lockname (and optionally lockname timeout) to /sys/power/wake_lock Write lockname to /sys/power/wake_unlock

Wake locks 2/2 Custom solution not integrated with the Linux Power Management (PM) subsystem Components make requests to keep the power on through wake locks (use wake locks carefully!!!) Support different types of wake locks: FULL_WAKE_LOCK: cpu on, keyboard on, screen at full brightness PARTIAL_WAKE_LOCK: cpu on SCREEN_DIM_WAKE_LOCK: screen on (but may be dimmed), keyboard backlights allowed to go off...

Wake lock: Java interface PowerManager pm = (PowerManager)mContext.getSystemService( Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newwakelock( PowerManager.SCREEN_DIM_WAKE_LOCK PowerManager.ON_AFTER_RELEASE, TAG); wl.acquire(); //... wl.release();

Android alarm Tell the kernel when it should wake-up hrtimer: when the system is running RTC: when the system is suspended

Android alarm static struct alarm my_alarm; alarm_init(&my_alarm, ANDROID_ALARM_RTC_WAKEUP, my_alarm_handler); alarm_start_range(&my_alarm, expire_start, expire_end); alarm_cancel(&my_alarm);

References Official Android developers website: http://developer.android.com/ Embedded Linux wiki (Android Portal): http://elinux.org/android_portal The xda-developers forum: http://www.xda-developers.com/ mysuspend source code available at github.com: https://github.com/arighi/mysuspend

Q/A You're very welcome! Twitter @arighi #bem2012