Headless Android Strikes Back!
ABS2014
04/29/2014
Gary Bisson
Embedded Software Engineer
ABOUT THE PRESENTER
• Embedded Software Engineer at Adeneo Embedded
(Bellevue, WA)
BSP Adaptation
Driver Development
System Integration
• Linux/Android enthusiast
SESSION OVERVIEW
1. Introduction
2. Headless Architecture
3. Headless Applications
4. Demonstration
5. Conclusion
Introduction
Headless Android Introduction
WHY ARE WE HERE?
• Android without UI?
• Use cases?
• Set the expectations of such system
Warning
Not about Embedded Linux vs. Headless Android...
5
Headless Android Introduction
WHAT'S THE INTEREST?
• Same OS/application across product line
• Standardized development environment
• Android API & tools:
SDK/NDK
ADB/Fastboot
systrace
6
Headless Android Introduction
WHAT'S DIFFERENT NOW?
• Update:
What has changed since first introduced?
Tips & tricks from past experience
• Come to the dark side of Android...
7
Headless Architecture
Headless Android Headless Architecture
ANDROID ARCHITECTURE
9
Headless Android Headless Architecture
CYBORGSTACK SOLUTION
• The full-blown stack without:
SurfaceFlinger
WindowManager
WallpaperService
InputMethodManager
SystemUI
• Some tricks: fake values from SF Client
10
Headless Android Headless Architecture
CYBORGSTACK SOLUTION
• Integration into source tree:
From Cyborgstack's GitHub:
♦ headless branch
Change for generic-eng target
Directly into AOSP internals
11
Headless Android Headless Architecture
GOING FURTHER
Some went further:
• Remove stock apps
Browser
HTMLViewer
...
• Remove unnecessary preloaded-classes
View
Graphics
...
• Remove few other System Services
12
Headless Android Headless Architecture
SOME FIGURES
• Vanilla Gingerbread generic-eng build:
system size: 64MB
Free memory: 122/256MB
• Cyborgstack Headless build:
system size: 64MB
Free memory: 172/256MB
• Enhanced Headless build:
system size: 47M
Free memory: 202/256MB
13
Headless Android Headless Architecture
SUMMARY
As stated by Cyborgstack:
• Very much a proof of concept
• Not easily portable
Change of frameworks, system...
• Good starting point
• Gingerbread now getting old
14
Headless Android Headless Architecture
AOSP INTEGRATION
• ro.config.headless property
• Alongside Jelly Bean 4.1 release
• Hasn't really evolved since though
15
Headless Android Headless Architecture
NEW ARCHITECTURE
• SurfaceControl: tells user the device is Headless
• WallpaperService: not started
• SystemUI: not started
• DisplayManager: returns HeadlessDisplayAdapter
• PhoneWindowManager: skips action to user
• ActivityManager: skips Home app + activity creation
16
Headless Android Headless Architecture
WHAT'S DIFFERENT
Advantages:
• Same tree for both headless and regular builds
• Easy to tweak:
SystemProperties.get("ro.config.headless", "0")
Drawbacks:
• Not as thorough as it could be
• System Server crashes... needs modifications
17
Headless Android Headless Architecture
WHAT I'VE TRIED
Quick fixes:
• Patch SurfaceControl not to throw an exception
• Patch SurfaceFlinger not to start bootanim
• Remove SystemUI + some stock apps
• config.disable_noncore
• config.disable_systemui
18
Headless Android Headless Architecture
GOING FURTHER
Same work needs to be done:
• Remove WindowManager
• Remove other UI-specific app/libraries
• Reduce preload libraries
• ...
19
Headless Android Headless Architecture
SOME FIGURES
• Vanilla KitKat aosp_arm-eng build:
system size: 303MB
Free memory: 284/512MB
• Generic armv7-a-neon mini build:
system size: 128MB
Free memory: 356/512MB
• Generic "Headless" mini build:
system size: 128MB
Free memory: 356/512MB
• Optimized "Headless" mini build:
system size: 124MB
Free memory: 394/512MB
20
Headless Applications
Headless Android Headless Applications
NO ACTIVITY SO WHAT?
• App components:
Service
ContentProvider
BroadcastReceiver
• Android Framework
22
Headless Android Headless Applications
NO ACTIVITY SO WHAT?
Activities
Services
Broadcast
Receivers
Content
Providers
System
Services
23
Headless Android Headless Applications
HOW TO?
• AndroidManifest.xml trick
• am commands
• persistent for System apps only
• BOOT_COMPLETED Intent otherwise
• System Services:
onSensorChanged()
onKeyDown()
Custom System Service!
24
Headless Android Headless Applications
DEBUGGING
• By default, debugging only works for Activity-based
application
• Need to start the application manually with am
• Either attach manually or specify it in code:
android.os.Debug.waitForDebugger()
25
Headless Android Headless Applications
USE CASES
• Barcode scanner
• Home automation remote
Button vs. Touchscreen
LED vs. Display
IP stays the same
26
Demonstration
Headless Android Demonstration
HARDWARE SELECTION
• Android emulators
Gingerbread 2.3.7_r1
Kit Kat 4.4_r1
• Low-end ARM device:
Atmel sam9g20-ek (64M of RAM)
No graphics
28
Conclusion
Headless Android Conclusion
CONCLUSION
• Good intentions
• Industry demand
• Activity limitation
• Source code: https://github.com/gibsson/headless-android
30
Headless Android Conclusion
QUESTIONS?
31
Headless Android Conclusion
REFERENCES
• Karim Yaghmour: Embedded Android
O'Reilly Shop
• Opersys/Cyborgstack: Headless Android
ABS2012 - Headless Android
Opersys Headless Blog Post
• Headless Android Blogspot (Casey Anderson):
Gingerbread Patches
32

Headless Android Strikes Back!

  • 1.
    Headless Android StrikesBack! ABS2014 04/29/2014 Gary Bisson Embedded Software Engineer
  • 2.
    ABOUT THE PRESENTER •Embedded Software Engineer at Adeneo Embedded (Bellevue, WA) BSP Adaptation Driver Development System Integration • Linux/Android enthusiast
  • 3.
    SESSION OVERVIEW 1. Introduction 2.Headless Architecture 3. Headless Applications 4. Demonstration 5. Conclusion
  • 4.
  • 5.
    Headless Android Introduction WHYARE WE HERE? • Android without UI? • Use cases? • Set the expectations of such system Warning Not about Embedded Linux vs. Headless Android... 5
  • 6.
    Headless Android Introduction WHAT'STHE INTEREST? • Same OS/application across product line • Standardized development environment • Android API & tools: SDK/NDK ADB/Fastboot systrace 6
  • 7.
    Headless Android Introduction WHAT'SDIFFERENT NOW? • Update: What has changed since first introduced? Tips & tricks from past experience • Come to the dark side of Android... 7
  • 8.
  • 9.
    Headless Android HeadlessArchitecture ANDROID ARCHITECTURE 9
  • 10.
    Headless Android HeadlessArchitecture CYBORGSTACK SOLUTION • The full-blown stack without: SurfaceFlinger WindowManager WallpaperService InputMethodManager SystemUI • Some tricks: fake values from SF Client 10
  • 11.
    Headless Android HeadlessArchitecture CYBORGSTACK SOLUTION • Integration into source tree: From Cyborgstack's GitHub: ♦ headless branch Change for generic-eng target Directly into AOSP internals 11
  • 12.
    Headless Android HeadlessArchitecture GOING FURTHER Some went further: • Remove stock apps Browser HTMLViewer ... • Remove unnecessary preloaded-classes View Graphics ... • Remove few other System Services 12
  • 13.
    Headless Android HeadlessArchitecture SOME FIGURES • Vanilla Gingerbread generic-eng build: system size: 64MB Free memory: 122/256MB • Cyborgstack Headless build: system size: 64MB Free memory: 172/256MB • Enhanced Headless build: system size: 47M Free memory: 202/256MB 13
  • 14.
    Headless Android HeadlessArchitecture SUMMARY As stated by Cyborgstack: • Very much a proof of concept • Not easily portable Change of frameworks, system... • Good starting point • Gingerbread now getting old 14
  • 15.
    Headless Android HeadlessArchitecture AOSP INTEGRATION • ro.config.headless property • Alongside Jelly Bean 4.1 release • Hasn't really evolved since though 15
  • 16.
    Headless Android HeadlessArchitecture NEW ARCHITECTURE • SurfaceControl: tells user the device is Headless • WallpaperService: not started • SystemUI: not started • DisplayManager: returns HeadlessDisplayAdapter • PhoneWindowManager: skips action to user • ActivityManager: skips Home app + activity creation 16
  • 17.
    Headless Android HeadlessArchitecture WHAT'S DIFFERENT Advantages: • Same tree for both headless and regular builds • Easy to tweak: SystemProperties.get("ro.config.headless", "0") Drawbacks: • Not as thorough as it could be • System Server crashes... needs modifications 17
  • 18.
    Headless Android HeadlessArchitecture WHAT I'VE TRIED Quick fixes: • Patch SurfaceControl not to throw an exception • Patch SurfaceFlinger not to start bootanim • Remove SystemUI + some stock apps • config.disable_noncore • config.disable_systemui 18
  • 19.
    Headless Android HeadlessArchitecture GOING FURTHER Same work needs to be done: • Remove WindowManager • Remove other UI-specific app/libraries • Reduce preload libraries • ... 19
  • 20.
    Headless Android HeadlessArchitecture SOME FIGURES • Vanilla KitKat aosp_arm-eng build: system size: 303MB Free memory: 284/512MB • Generic armv7-a-neon mini build: system size: 128MB Free memory: 356/512MB • Generic "Headless" mini build: system size: 128MB Free memory: 356/512MB • Optimized "Headless" mini build: system size: 124MB Free memory: 394/512MB 20
  • 21.
  • 22.
    Headless Android HeadlessApplications NO ACTIVITY SO WHAT? • App components: Service ContentProvider BroadcastReceiver • Android Framework 22
  • 23.
    Headless Android HeadlessApplications NO ACTIVITY SO WHAT? Activities Services Broadcast Receivers Content Providers System Services 23
  • 24.
    Headless Android HeadlessApplications HOW TO? • AndroidManifest.xml trick • am commands • persistent for System apps only • BOOT_COMPLETED Intent otherwise • System Services: onSensorChanged() onKeyDown() Custom System Service! 24
  • 25.
    Headless Android HeadlessApplications DEBUGGING • By default, debugging only works for Activity-based application • Need to start the application manually with am • Either attach manually or specify it in code: android.os.Debug.waitForDebugger() 25
  • 26.
    Headless Android HeadlessApplications USE CASES • Barcode scanner • Home automation remote Button vs. Touchscreen LED vs. Display IP stays the same 26
  • 27.
  • 28.
    Headless Android Demonstration HARDWARESELECTION • Android emulators Gingerbread 2.3.7_r1 Kit Kat 4.4_r1 • Low-end ARM device: Atmel sam9g20-ek (64M of RAM) No graphics 28
  • 29.
  • 30.
    Headless Android Conclusion CONCLUSION •Good intentions • Industry demand • Activity limitation • Source code: https://github.com/gibsson/headless-android 30
  • 31.
  • 32.
    Headless Android Conclusion REFERENCES •Karim Yaghmour: Embedded Android O'Reilly Shop • Opersys/Cyborgstack: Headless Android ABS2012 - Headless Android Opersys Headless Blog Post • Headless Android Blogspot (Casey Anderson): Gingerbread Patches 32