SlideShare a Scribd company logo
1 of 34
Download to read offline
Kernel Hacking on Android




A quick look into the Android kernel...




          Andrea Righi <andrea@betterlinux.com>
Agenda
●   Overview
●   Android Programming
●   Android Power Management
●   Q/A




                Andrea Righi <andrea@betterlinux.com>
Overview




Andrea Righi <andrea@betterlinux.com>
Introduction
●   Android is a software stack for mobile devices,
    such as smartphones and tablet computers
●   It is developed by the Open Handset Alliance
    led by Google
●   Android was listed as the best-selling
    smartphone platform worldwide in Q4 2010 by
    Canalys



                  Andrea Righi <andrea@betterlinux.com>
Android OS
●   Android consists of a:
    ●   kernel (Linux, modified by Google)
    ●   userspace libraries and APIs written in C
    ●   an application framework (Dalvik Java Virtual
        Machine)
    ●   application software running inside the application
        framework




                      Andrea Righi <andrea@betterlinux.com>
Andrea Righi <andrea@betterlinux.com>
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)
●   ...
                                  Andrea Righi <andrea@betterlinux.com>
Native libraries
●   Bionic libc
    ●   Custom libc implementation, optimized for
        embedded use (optimized for size)
    ●   Don't support certain POSIX features
    ●   Not compatible with GNU Libc (glibc)
    ●   Native code must linked against bionc libc (or
        statically linked)




                      Andrea Righi <andrea@betterlinux.com>
Android Programming




  Andrea Righi <andrea@betterlinux.com>
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
                      Andrea Righi <andrea@betterlinux.com>
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




                  Andrea Righi <andrea@betterlinux.com>
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)

                          Andrea Righi <andrea@betterlinux.com>
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


                              Andrea Righi <andrea@betterlinux.com>
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.

                  Andrea Righi <andrea@betterlinux.com>
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

                                Andrea Righi <andrea@betterlinux.com>
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



                              Andrea Righi <andrea@betterlinux.com>
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>




                           Andrea Righi <andrea@betterlinux.com>
Android Power Management




     Andrea Righi <andrea@betterlinux.com>
Battery life
●   The three most important considerations for
    mobile applications are:
    ●   battery life
    ●   battery life
    ●   and battery life
●   After all, if the battery is dead, no one can use
    your application...



                       Andrea Righi <andrea@betterlinux.com>
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




                      Andrea Righi <andrea@betterlinux.com>
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




                   Andrea Righi <andrea@betterlinux.com>
Battery consumption




   Andrea Righi <andrea@betterlinux.com>
CPU states
●   Running
●   Idle
●   Deep sleep
●   Suspend
●   Powered off




                  Andrea Righi <andrea@betterlinux.com>
Background activity
●   Example, an application that periodically checks
    emails:
    ●   The device wakes up
    ●   Pulls up the radio stack
    ●   Does a DNS request
    ●   Does a network connection
    ●   Pulling down some data
    ●   Parsing data on the fly (cpu)
    ●   Takes a few seconds to the device to settle down and
        fall to sleep mode again
                      Andrea Righi <andrea@betterlinux.com>
Battery cost example
●   Cost during a given hour
    ●   Full idle:
         –   5mAh
    ●   Network stack + CPU:
         –   350 mAh
    ●   Background app (i.e., network update)
         –   6 times / h x 8 sec x 350 mAh => 4.67mAh
●   Even a simple innocent background app can
    drain the battery life quickly

                         Andrea Righi <andrea@betterlinux.com>
Wake locks
●   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
                     Andrea Righi <andrea@betterlinux.com>
Wake locks
●   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
    ●   ...
                      Andrea Righi <andrea@betterlinux.com>
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();




                         Andrea Righi <andrea@betterlinux.com>
Early suspend
●   Suspend / resume kernel hooks called when
    user-visible sleep states change
●   User-space framework writes the state to
    /sys/power/request_state




                  Andrea Righi <andrea@betterlinux.com>
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);




                           Andrea Righi <andrea@betterlinux.com>
Android alarm
●   Tell the kernel when it should wake-up
    ●   hrtimer: when the system is running
    ●   RTC: when the system is suspended




                     Andrea Righi <andrea@betterlinux.com>
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);




                            Andrea Righi <andrea@betterlinux.com>
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
                      Andrea Righi <andrea@betterlinux.com>
Q/A
●   You're very welcome!




                 Andrea Righi <andrea@betterlinux.com>

More Related Content

What's hot

Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel BugsJiahong Fang
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011pundiramit
 
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)Matthias Brugger
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Tip: How to enable wireless debugging with Android?
Tip: How to enable wireless debugging with Android?Tip: How to enable wireless debugging with Android?
Tip: How to enable wireless debugging with Android?Sarath C
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Android Security, From the Ground Up
Android Security, From the Ground UpAndroid Security, From the Ground Up
Android Security, From the Ground UpOpersys inc.
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
How to Make Android's Bootable Recovery Work For You by Drew Suarez
How to Make Android's Bootable Recovery Work For You by Drew SuarezHow to Make Android's Bootable Recovery Work For You by Drew Suarez
How to Make Android's Bootable Recovery Work For You by Drew SuarezShakacon
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updatesGary Bisson
 

What's hot (20)

Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel Bugs
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Tip: How to enable wireless debugging with Android?
Tip: How to enable wireless debugging with Android?Tip: How to enable wireless debugging with Android?
Tip: How to enable wireless debugging with Android?
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Android Security, From the Ground Up
Android Security, From the Ground UpAndroid Security, From the Ground Up
Android Security, From the Ground Up
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
Hacking Android OS
Hacking Android OSHacking Android OS
Hacking Android OS
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Android Booting Scenarios
Android Booting ScenariosAndroid Booting Scenarios
Android Booting Scenarios
 
How to Make Android's Bootable Recovery Work For You by Drew Suarez
How to Make Android's Bootable Recovery Work For You by Drew SuarezHow to Make Android's Bootable Recovery Work For You by Drew Suarez
How to Make Android's Bootable Recovery Work For You by Drew Suarez
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
 

Viewers also liked

An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...William Liang
 
Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016perillamint
 
Being a hack engineer
Being a hack engineerBeing a hack engineer
Being a hack engineerNukelabs
 
Hardware-Assisted Rootkits & Instrumentation
Hardware-Assisted Rootkits & InstrumentationHardware-Assisted Rootkits & Instrumentation
Hardware-Assisted Rootkits & InstrumentationEndgameInc
 
Android Wear Hackathon 요리 레시피 앱 발표자료
Android Wear Hackathon 요리 레시피 앱 발표자료Android Wear Hackathon 요리 레시피 앱 발표자료
Android Wear Hackathon 요리 레시피 앱 발표자료HwanIk Kim
 
How and Why You Should Become a Kernel Hacker - FOSS.IN/2007
How and Why You Should Become a Kernel Hacker - FOSS.IN/2007How and Why You Should Become a Kernel Hacker - FOSS.IN/2007
How and Why You Should Become a Kernel Hacker - FOSS.IN/2007James Morris
 
모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]
모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]
모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]JM code group
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel ProgrammingNalin Sharma
 
What is Kernel, basic idea of kernel
What is Kernel, basic idea of kernelWhat is Kernel, basic idea of kernel
What is Kernel, basic idea of kernelNeel Parikh
 
Hacking with Linux on Android devices #MOCPON
Hacking with Linux on Android devices    #MOCPONHacking with Linux on Android devices    #MOCPON
Hacking with Linux on Android devices #MOCPONNetwalker lab kapper
 
안드로이드 스터디 Jni 발표 자료 Rev05 송형주
안드로이드 스터디 Jni 발표 자료 Rev05 송형주안드로이드 스터디 Jni 발표 자료 Rev05 송형주
안드로이드 스터디 Jni 발표 자료 Rev05 송형주iamhjoo (송형주)
 

Viewers also liked (12)

An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...
 
Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016
 
Being a hack engineer
Being a hack engineerBeing a hack engineer
Being a hack engineer
 
Hardware-Assisted Rootkits & Instrumentation
Hardware-Assisted Rootkits & InstrumentationHardware-Assisted Rootkits & Instrumentation
Hardware-Assisted Rootkits & Instrumentation
 
Android Wear Hackathon 요리 레시피 앱 발표자료
Android Wear Hackathon 요리 레시피 앱 발표자료Android Wear Hackathon 요리 레시피 앱 발표자료
Android Wear Hackathon 요리 레시피 앱 발표자료
 
How and Why You Should Become a Kernel Hacker - FOSS.IN/2007
How and Why You Should Become a Kernel Hacker - FOSS.IN/2007How and Why You Should Become a Kernel Hacker - FOSS.IN/2007
How and Why You Should Become a Kernel Hacker - FOSS.IN/2007
 
모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]
모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]
모바일침해사례 Kinfosec 강장묵교수님140729 [호환 모드]
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
What is Kernel, basic idea of kernel
What is Kernel, basic idea of kernelWhat is Kernel, basic idea of kernel
What is Kernel, basic idea of kernel
 
Hacking with Linux on Android devices #MOCPON
Hacking with Linux on Android devices    #MOCPONHacking with Linux on Android devices    #MOCPON
Hacking with Linux on Android devices #MOCPON
 
Kernel (OS)
Kernel (OS)Kernel (OS)
Kernel (OS)
 
안드로이드 스터디 Jni 발표 자료 Rev05 송형주
안드로이드 스터디 Jni 발표 자료 Rev05 송형주안드로이드 스터디 Jni 발표 자료 Rev05 송형주
안드로이드 스터디 Jni 발표 자료 Rev05 송형주
 

Similar to Workshop su Android Kernel Hacking

Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Security Issues in Android Custom ROM
Security Issues in Android Custom ROMSecurity Issues in Android Custom ROM
Security Issues in Android Custom ROMAnant Shrivastava
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentKarim Yaghmour
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Opersys inc.
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Androidnatdefreitas
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Opersys inc.
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIOpersys inc.
 
Iot world 2018 presentation
Iot world 2018 presentationIot world 2018 presentation
Iot world 2018 presentationNicola La Gloria
 
Eclipse Iot Day 2018 Presentation
Eclipse Iot Day 2018 PresentationEclipse Iot Day 2018 Presentation
Eclipse Iot Day 2018 PresentationKynetics
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VOpersys inc.
 
Dropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stackDropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stackJacek Furmankiewicz
 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UIOpersys inc.
 

Similar to Workshop su Android Kernel Hacking (20)

Android Attacks
Android AttacksAndroid Attacks
Android Attacks
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Security Issues in Android Custom ROM
Security Issues in Android Custom ROMSecurity Issues in Android Custom ROM
Security Issues in Android Custom ROM
 
Security Issues in Android Custom Rom
Security Issues in Android Custom RomSecurity Issues in Android Custom Rom
Security Issues in Android Custom Rom
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
 
Iot world 2018 presentation
Iot world 2018 presentationIot world 2018 presentation
Iot world 2018 presentation
 
Eclipse Iot Day 2018 Presentation
Eclipse Iot Day 2018 PresentationEclipse Iot Day 2018 Presentation
Eclipse Iot Day 2018 Presentation
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon V
 
Dropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stackDropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stack
 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UI
 

More from Develer S.r.l.

Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linuxTrace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linuxDeveler S.r.l.
 
Cloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshopCloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshopDeveler S.r.l.
 
BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011Develer S.r.l.
 
Qt roadmap: the future of Qt
Qt roadmap: the future of QtQt roadmap: the future of Qt
Qt roadmap: the future of QtDeveler S.r.l.
 
Qt Quick for dynamic UI development
Qt Quick for dynamic UI developmentQt Quick for dynamic UI development
Qt Quick for dynamic UI developmentDeveler S.r.l.
 
Qt licensing: making the right choice
Qt licensing: making the right choiceQt licensing: making the right choice
Qt licensing: making the right choiceDeveler S.r.l.
 
Qt everywhere a c++ abstraction platform
Qt everywhere   a c++ abstraction platformQt everywhere   a c++ abstraction platform
Qt everywhere a c++ abstraction platformDeveler S.r.l.
 
Qt Creator: the secret weapon of any c++ programmer
Qt Creator: the secret weapon of any c++ programmerQt Creator: the secret weapon of any c++ programmer
Qt Creator: the secret weapon of any c++ programmerDeveler S.r.l.
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application developmentDeveler S.r.l.
 
Hybrid development using Qt webkit
Hybrid development using Qt webkitHybrid development using Qt webkit
Hybrid development using Qt webkitDeveler S.r.l.
 
Smashing the bottleneck: Qt application profiling
Smashing the bottleneck: Qt application profilingSmashing the bottleneck: Qt application profiling
Smashing the bottleneck: Qt application profilingDeveler S.r.l.
 
Crossing the border with Qt: the i18n system
Crossing the border with Qt: the i18n systemCrossing the border with Qt: the i18n system
Crossing the border with Qt: the i18n systemDeveler S.r.l.
 
BeRTOS: Sistema Real Time Embedded Free
BeRTOS: Sistema Real Time Embedded FreeBeRTOS: Sistema Real Time Embedded Free
BeRTOS: Sistema Real Time Embedded FreeDeveler S.r.l.
 
BeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSBeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSDeveler S.r.l.
 
Develer - Company Profile
Develer - Company ProfileDeveler - Company Profile
Develer - Company ProfileDeveler S.r.l.
 
Bettersoftware Feedback 2009
Bettersoftware Feedback 2009Bettersoftware Feedback 2009
Bettersoftware Feedback 2009Develer S.r.l.
 

More from Develer S.r.l. (20)

Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linuxTrace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
 
Sw libero rf
Sw libero rfSw libero rf
Sw libero rf
 
Engagement small
Engagement smallEngagement small
Engagement small
 
Farepipi
FarepipiFarepipi
Farepipi
 
Cloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshopCloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshop
 
BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011
 
Qt roadmap: the future of Qt
Qt roadmap: the future of QtQt roadmap: the future of Qt
Qt roadmap: the future of Qt
 
Qt Quick in depth
Qt Quick in depthQt Quick in depth
Qt Quick in depth
 
Qt Quick for dynamic UI development
Qt Quick for dynamic UI developmentQt Quick for dynamic UI development
Qt Quick for dynamic UI development
 
Qt licensing: making the right choice
Qt licensing: making the right choiceQt licensing: making the right choice
Qt licensing: making the right choice
 
Qt everywhere a c++ abstraction platform
Qt everywhere   a c++ abstraction platformQt everywhere   a c++ abstraction platform
Qt everywhere a c++ abstraction platform
 
Qt Creator: the secret weapon of any c++ programmer
Qt Creator: the secret weapon of any c++ programmerQt Creator: the secret weapon of any c++ programmer
Qt Creator: the secret weapon of any c++ programmer
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application development
 
Hybrid development using Qt webkit
Hybrid development using Qt webkitHybrid development using Qt webkit
Hybrid development using Qt webkit
 
Smashing the bottleneck: Qt application profiling
Smashing the bottleneck: Qt application profilingSmashing the bottleneck: Qt application profiling
Smashing the bottleneck: Qt application profiling
 
Crossing the border with Qt: the i18n system
Crossing the border with Qt: the i18n systemCrossing the border with Qt: the i18n system
Crossing the border with Qt: the i18n system
 
BeRTOS: Sistema Real Time Embedded Free
BeRTOS: Sistema Real Time Embedded FreeBeRTOS: Sistema Real Time Embedded Free
BeRTOS: Sistema Real Time Embedded Free
 
BeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSBeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOS
 
Develer - Company Profile
Develer - Company ProfileDeveler - Company Profile
Develer - Company Profile
 
Bettersoftware Feedback 2009
Bettersoftware Feedback 2009Bettersoftware Feedback 2009
Bettersoftware Feedback 2009
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Workshop su Android Kernel Hacking

  • 1. Kernel Hacking on Android A quick look into the Android kernel... Andrea Righi <andrea@betterlinux.com>
  • 2. Agenda ● Overview ● Android Programming ● Android Power Management ● Q/A Andrea Righi <andrea@betterlinux.com>
  • 4. Introduction ● Android is a software stack for mobile devices, such as smartphones and tablet computers ● It is developed by the Open Handset Alliance led by Google ● Android was listed as the best-selling smartphone platform worldwide in Q4 2010 by Canalys Andrea Righi <andrea@betterlinux.com>
  • 5. Android OS ● Android consists of a: ● kernel (Linux, modified by Google) ● userspace libraries and APIs written in C ● an application framework (Dalvik Java Virtual Machine) ● application software running inside the application framework Andrea Righi <andrea@betterlinux.com>
  • 7. 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) ● ... Andrea Righi <andrea@betterlinux.com>
  • 8. Native libraries ● Bionic libc ● Custom libc implementation, optimized for embedded use (optimized for size) ● Don't support certain POSIX features ● Not compatible with GNU Libc (glibc) ● Native code must linked against bionc libc (or statically linked) Andrea Righi <andrea@betterlinux.com>
  • 9. Android Programming Andrea Righi <andrea@betterlinux.com>
  • 10. 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 Andrea Righi <andrea@betterlinux.com>
  • 11. 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 Andrea Righi <andrea@betterlinux.com>
  • 12. 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) Andrea Righi <andrea@betterlinux.com>
  • 13. 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 Andrea Righi <andrea@betterlinux.com>
  • 14. 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. Andrea Righi <andrea@betterlinux.com>
  • 15. 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 Andrea Righi <andrea@betterlinux.com>
  • 16. 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 Andrea Righi <andrea@betterlinux.com>
  • 17. 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> Andrea Righi <andrea@betterlinux.com>
  • 18. Android Power Management Andrea Righi <andrea@betterlinux.com>
  • 19. Battery life ● The three most important considerations for mobile applications are: ● battery life ● battery life ● and battery life ● After all, if the battery is dead, no one can use your application... Andrea Righi <andrea@betterlinux.com>
  • 20. 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 Andrea Righi <andrea@betterlinux.com>
  • 21. 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 Andrea Righi <andrea@betterlinux.com>
  • 22. Battery consumption Andrea Righi <andrea@betterlinux.com>
  • 23. CPU states ● Running ● Idle ● Deep sleep ● Suspend ● Powered off Andrea Righi <andrea@betterlinux.com>
  • 24. Background activity ● Example, an application that periodically checks emails: ● The device wakes up ● Pulls up the radio stack ● Does a DNS request ● Does a network connection ● Pulling down some data ● Parsing data on the fly (cpu) ● Takes a few seconds to the device to settle down and fall to sleep mode again Andrea Righi <andrea@betterlinux.com>
  • 25. Battery cost example ● Cost during a given hour ● Full idle: – 5mAh ● Network stack + CPU: – 350 mAh ● Background app (i.e., network update) – 6 times / h x 8 sec x 350 mAh => 4.67mAh ● Even a simple innocent background app can drain the battery life quickly Andrea Righi <andrea@betterlinux.com>
  • 26. Wake locks ● 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 Andrea Righi <andrea@betterlinux.com>
  • 27. Wake locks ● 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 ● ... Andrea Righi <andrea@betterlinux.com>
  • 28. 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(); Andrea Righi <andrea@betterlinux.com>
  • 29. Early suspend ● Suspend / resume kernel hooks called when user-visible sleep states change ● User-space framework writes the state to /sys/power/request_state Andrea Righi <andrea@betterlinux.com>
  • 30. 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); Andrea Righi <andrea@betterlinux.com>
  • 31. Android alarm ● Tell the kernel when it should wake-up ● hrtimer: when the system is running ● RTC: when the system is suspended Andrea Righi <andrea@betterlinux.com>
  • 32. 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); Andrea Righi <andrea@betterlinux.com>
  • 33. 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 Andrea Righi <andrea@betterlinux.com>
  • 34. Q/A ● You're very welcome! Andrea Righi <andrea@betterlinux.com>