SlideShare a Scribd company logo
Outline
               Building Blocks
              Under the Hood
                     Get Dirty
                        Q&A




Introduction to Android Window System

                     Chia-I Wu
                   olv@0xlab.org



                     May 15, 2009




      Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                       Building Blocks
                      Under the Hood
                             Get Dirty
                                Q&A




Building Blocks
   Overview
   Interested Components

Under the Hood
   Random Topics

Get Dirty
   Development
   Code

Q&A



              Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Overview
                         Under the Hood
                                            Interested Components
                                Get Dirty
                                   Q&A


Outline

   Building Blocks
      Overview
      Interested Components

   Under the Hood
      Random Topics

   Get Dirty
      Development
      Code

   Q&A


                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                       Building Blocks
                                         Overview
                      Under the Hood
                                         Interested Components
                             Get Dirty
                                Q&A


System Architecture




              Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                       Building Blocks
                                         Overview
                      Under the Hood
                                         Interested Components
                             Get Dirty
                                Q&A


System Architecture




              Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                       Building Blocks
                                         Overview
                      Under the Hood
                                         Interested Components
                             Get Dirty
                                Q&A


System Architecture




              Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                           Building Blocks
                                             Overview
                          Under the Hood
                                             Interested Components
                                 Get Dirty
                                    Q&A


Building Blocks



   There are more, but we focus on
       SurfaceManager
       WindowManager
       ActivityManager




                  Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Overview
                         Under the Hood
                                            Interested Components
                                Get Dirty
                                   Q&A


SurfaceManager




      frameworks/base/libs/surfaceflinger/
      a.k.a SurfaceFlinger
      Allocate surfaces. Backed by ashmem/pmem/?
      Composite surfaces




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                         Building Blocks
                                           Overview
                        Under the Hood
                                           Interested Components
                               Get Dirty
                                  Q&A


WindowManager


     frameworks/base/services/java/
     com/android/server/WindowManagerService.java
     About 9000 SLOC in one file. Poorly documented, bad
     namings, ...
     (Ask SurfaceManager to) create/layout surfaces on behalf of
     the clients
     Dispatch input events to clients
     Transition animation
     WindowManagerPolicy


                Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Overview
                         Under the Hood
                                            Interested Components
                                Get Dirty
                                   Q&A


ActivityManager



      frameworks/base/services/java/
      com/android/server/am/
      Manage lifecycles of activities
      Manage stacking of activities
      Dispatch intents
      Spawn processes




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Overview
                         Under the Hood
                                            Interested Components
                                Get Dirty
                                   Q&A


Confusions



      An activity has one or more windows (e.g. dialogs)
      A window has one or more surfaces (e.g. surface views)
      However, in window manager, a window is called a session
      A surface is called a window
      And an activity becomes roughly a token




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Overview
                         Under the Hood
                                            Interested Components
                                Get Dirty
                                   Q&A


Special Keys




      HOME key
      BACK key




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                         Under the Hood     Random Topics
                                Get Dirty
                                   Q&A


Outline

   Building Blocks
      Overview
      Interested Components

   Under the Hood
      Random Topics

   Get Dirty
      Development
      Code

   Q&A


                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                         Under the Hood     Random Topics
                                Get Dirty
                                   Q&A


Process View




      SurfaceManager, WindowManager, and SurfaceManager are
      threads of a single process (system server)
      Every application is usually a process of itself




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                             Building Blocks
                            Under the Hood     Random Topics
                                   Get Dirty
                                      Q&A


Zygote




         Is a process started on system initialization
         Preloads java classes and resources
         Forks system server
         Listens silently on /dev/socket/zygote




                    Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                             Building Blocks
                            Under the Hood     Random Topics
                                   Get Dirty
                                      Q&A


Binder




         Early in the lifetime of an application process, thread(s) are
         created and blocked on /dev/binder
         Binder is used mainly for RPC
         Fragile




                    Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Outline

   Building Blocks
      Overview
      Interested Components

   Under the Hood
      Random Topics

   Get Dirty
      Development
      Code

   Q&A


                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                         Building Blocks
                                           Development
                        Under the Hood
                                           Code
                               Get Dirty
                                  Q&A


Build System




      build/core/core/build-system.html
      .   build/envsetup.sh
      showcommands
      export ANDROID JAVA HOME if non-standard




                Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                             Building Blocks
                                               Development
                            Under the Hood
                                               Code
                                   Get Dirty
                                      Q&A


adb



      ADBHOST for transport over TCP/IP
      kill-server
      remount
      pull/push
      logcat
      shell




                    Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                           Building Blocks
                                             Development
                          Under the Hood
                                             Code
                                 Get Dirty
                                    Q&A


hierarchyviewer




       Display view hierarchy
       Display view
       Invalidate/Relayout




                  Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                         Building Blocks
                                           Development
                        Under the Hood
                                           Code
                               Get Dirty
                                  Q&A


Graphics: Memory Management




     SurfaceFlinger has a SurfaceHeapManager
     Every client has a MemoryDealer, as returned by
     SurfaceHeapManager
     Every surface of a client also has dealer(s), from client or GPU




                Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.




      A dealer consists of a heap and an allocator
      A heap represents a sharable big chunk of memory
      An allocator is an algorithm
      Small chunks of memory from the heap are returned




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.


  Real flow
      A client asks for a new surface, createSurface




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.


  Real flow
      A client asks for a new surface, createSurface
      createSurface calls createNormalSurfaceLocked




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.


  Real flow
      A client asks for a new surface, createSurface
      createSurface calls createNormalSurfaceLocked
      A layer is created and setBuffers is called to allocate buffers




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.


  Real flow
      A client asks for a new surface, createSurface
      createSurface calls createNormalSurfaceLocked
      A layer is created and setBuffers is called to allocate buffers
      Two dealers are created from client, one for front buffer and
      one for back buffer




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.


  Real flow
      A client asks for a new surface, createSurface
      createSurface calls createNormalSurfaceLocked
      A layer is created and setBuffers is called to allocate buffers
      Two dealers are created from client, one for front buffer and
      one for back buffer
      Two LayerBitmaps are created, initialized with the two dealers




                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                                            Development
                         Under the Hood
                                            Code
                                Get Dirty
                                   Q&A


Graphics: Memory Management cont.


  Real flow
      A client asks for a new surface, createSurface
      createSurface calls createNormalSurfaceLocked
      A layer is created and setBuffers is called to allocate buffers
      Two dealers are created from client, one for front buffer and
      one for back buffer
      Two LayerBitmaps are created, initialized with the two dealers
      Heaps of dealers along with info about the layer are returned



                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                         Building Blocks
                                           Development
                        Under the Hood
                                           Code
                               Get Dirty
                                  Q&A


Hello World




      http://people.debian.org.tw/˜olv/surfaceflinger/demo.tar.gz




                Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                        Building Blocks
                                          Development
                       Under the Hood
                                          Code
                              Get Dirty
                                 Q&A


Many Buffers




     Surface is double buffered
     EGLDisplaySurface is double buffered
     Same technique; Different code pathes, different purposes




               Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                         Building Blocks
                                           Development
                        Under the Hood
                                           Code
                               Get Dirty
                                  Q&A


Double Buffering




      Sofware v.s. Hardware
      Memory copy
      Page flipping




                Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                           Building Blocks
                                             Development
                          Under the Hood
                                             Code
                                 Get Dirty
                                    Q&A


Dirty Region




      Associate buffers with dirty regions
      Copy back




                  Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                   Building Blocks
                                     Development
                  Under the Hood
                                     Code
                         Get Dirty
                            Q&A


Frame 0




          Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                   Building Blocks
                                     Development
                  Under the Hood
                                     Code
                         Get Dirty
                            Q&A


Frame 1




          Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                   Building Blocks
                                     Development
                  Under the Hood
                                     Code
                         Get Dirty
                            Q&A


Frame 2




          Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                          Building Blocks
                         Under the Hood
                                Get Dirty
                                   Q&A


Outline

   Building Blocks
      Overview
      Interested Components

   Under the Hood
      Random Topics

   Get Dirty
      Development
      Code

   Q&A


                 Chia-I Wu olv@0xlab.org    Introduction to Android Window System
Outline
                            Building Blocks
                           Under the Hood
                                  Get Dirty
                                     Q&A


Q&A




      Questions?




                   Chia-I Wu olv@0xlab.org    Introduction to Android Window System

More Related Content

PDF
Low Level View of Android System Architecture
PDF
Design and Concepts of Android Graphics
PDF
Project meeting: Android Graphics Architecture Overview
PDF
Understanding the Android System Server
PDF
Android IPC Mechanism
PPT
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
PPTX
Binder: Android IPC
PDF
The Android graphics path, in depth
Low Level View of Android System Architecture
Design and Concepts of Android Graphics
Project meeting: Android Graphics Architecture Overview
Understanding the Android System Server
Android IPC Mechanism
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
Binder: Android IPC
The Android graphics path, in depth

What's hot (20)

PDF
Android Binder IPC for Linux
PPTX
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
PPTX
Android Booting Sequence
PPTX
Overview of Android binder IPC implementation
PDF
Android Boot Time Optimization
PDF
Explore Android Internals
PDF
Android Storage - Vold
PDF
Android Internals
PDF
Embedded Android : System Development - Part IV (Android System Services)
ODP
Embedded Android : System Development - Part III
ODP
Q4.11: Porting Android to new Platforms
PPT
Learning AOSP - Android Booting Process
PDF
Android for Embedded Linux Developers
PDF
Android Treble: Blessing or Trouble?
PDF
Android's HIDL: Treble in the HAL
PDF
Embedded Android : System Development - Part I
PDF
Android Things : Building Embedded Devices
PPT
Learning AOSP - Android Linux Device Driver
PDF
Android Internals
PDF
Android OS Porting: Introduction
Android Binder IPC for Linux
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android Booting Sequence
Overview of Android binder IPC implementation
Android Boot Time Optimization
Explore Android Internals
Android Storage - Vold
Android Internals
Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part III
Q4.11: Porting Android to new Platforms
Learning AOSP - Android Booting Process
Android for Embedded Linux Developers
Android Treble: Blessing or Trouble?
Android's HIDL: Treble in the HAL
Embedded Android : System Development - Part I
Android Things : Building Embedded Devices
Learning AOSP - Android Linux Device Driver
Android Internals
Android OS Porting: Introduction
Ad

Similar to Introduction to Android Window System (20)

PDF
Improve Android System Component Performance
PDF
Develop Community-based Android Distribution and Upstreaming Experience
PDF
Build to Hack, Hack to Build
PPTX
Architecting modern Android apps
PPT
What is web2.0
PDF
[Wroclaw #7] Why So Serial?
PPT
Java course-in-mumbai
PDF
Neal Ford Emergent Design And Evolutionary Architecture
PDF
Neal Ford Emergent Design And Evolutionary Architecture
PDF
DefCon 2012 - Finding Firmware Vulnerabilities
PDF
DefCon 2012 - Firmware Vulnerability Hunting with FRAK
PPTX
Mocking vtcc3 - en
PDF
YURY_CHEMERKIN_DefCon_2013_Conference.pdf
PDF
2.1. Dissecting blackberry
PPTX
OWASP AppSec Cali 2018 - Enabling Product Security With Culture and Cloud (As...
PPTX
Dip(dependency inversion principle) presentation
PPTX
Google Developer Group(GDG) DevFest Event 2012 Android talk
DOCX
Bhavin_Resume
PDF
Neal Ford Emergent Design And Evolutionary Architecture
PPTX
2015 06-wso2 coneu-closingkeynote-asanka
Improve Android System Component Performance
Develop Community-based Android Distribution and Upstreaming Experience
Build to Hack, Hack to Build
Architecting modern Android apps
What is web2.0
[Wroclaw #7] Why So Serial?
Java course-in-mumbai
Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary Architecture
DefCon 2012 - Finding Firmware Vulnerabilities
DefCon 2012 - Firmware Vulnerability Hunting with FRAK
Mocking vtcc3 - en
YURY_CHEMERKIN_DefCon_2013_Conference.pdf
2.1. Dissecting blackberry
OWASP AppSec Cali 2018 - Enabling Product Security With Culture and Cloud (As...
Dip(dependency inversion principle) presentation
Google Developer Group(GDG) DevFest Event 2012 Android talk
Bhavin_Resume
Neal Ford Emergent Design And Evolutionary Architecture
2015 06-wso2 coneu-closingkeynote-asanka
Ad

More from National Cheng Kung University (20)

PDF
PyPy's approach to construct domain-specific language runtime
PDF
Making Linux do Hard Real-time
PDF
2016 年春季嵌入式作業系統課程說明
PDF
Interpreter, Compiler, JIT from scratch
PDF
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
PDF
Construct an Efficient and Secure Microkernel for IoT
PDF
The Internals of "Hello World" Program
PDF
How A Compiler Works: GNU Toolchain
PDF
Virtual Machine Constructions for Dummies
PDF
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
PDF
從線上售票看作業系統設計議題
PDF
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
PDF
Xvisor: embedded and lightweight hypervisor
PDF
Making Linux do Hard Real-time
PDF
Implement Runtime Environments for HSA using LLVM
PDF
Priority Inversion on Mars
PDF
Develop Your Own Operating Systems using Cheap ARM Boards
PDF
Lecture notice about Embedded Operating System Design and Implementation
PDF
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
PDF
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
PyPy's approach to construct domain-specific language runtime
Making Linux do Hard Real-time
2016 年春季嵌入式作業系統課程說明
Interpreter, Compiler, JIT from scratch
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
Construct an Efficient and Secure Microkernel for IoT
The Internals of "Hello World" Program
How A Compiler Works: GNU Toolchain
Virtual Machine Constructions for Dummies
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
從線上售票看作業系統設計議題
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
Xvisor: embedded and lightweight hypervisor
Making Linux do Hard Real-time
Implement Runtime Environments for HSA using LLVM
Priority Inversion on Mars
Develop Your Own Operating Systems using Cheap ARM Boards
Lecture notice about Embedded Operating System Design and Implementation
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Approach and Philosophy of On baking technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Monthly Chronicles - July 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Building Integrated photovoltaic BIPV_UPV.pdf

Introduction to Android Window System

  • 1. Outline Building Blocks Under the Hood Get Dirty Q&A Introduction to Android Window System Chia-I Wu olv@0xlab.org May 15, 2009 Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 2. Outline Building Blocks Under the Hood Get Dirty Q&A Building Blocks Overview Interested Components Under the Hood Random Topics Get Dirty Development Code Q&A Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 3. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A Outline Building Blocks Overview Interested Components Under the Hood Random Topics Get Dirty Development Code Q&A Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 4. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A System Architecture Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 5. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A System Architecture Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 6. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A System Architecture Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 7. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A Building Blocks There are more, but we focus on SurfaceManager WindowManager ActivityManager Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 8. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A SurfaceManager frameworks/base/libs/surfaceflinger/ a.k.a SurfaceFlinger Allocate surfaces. Backed by ashmem/pmem/? Composite surfaces Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 9. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A WindowManager frameworks/base/services/java/ com/android/server/WindowManagerService.java About 9000 SLOC in one file. Poorly documented, bad namings, ... (Ask SurfaceManager to) create/layout surfaces on behalf of the clients Dispatch input events to clients Transition animation WindowManagerPolicy Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 10. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A ActivityManager frameworks/base/services/java/ com/android/server/am/ Manage lifecycles of activities Manage stacking of activities Dispatch intents Spawn processes Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 11. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A Confusions An activity has one or more windows (e.g. dialogs) A window has one or more surfaces (e.g. surface views) However, in window manager, a window is called a session A surface is called a window And an activity becomes roughly a token Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 12. Outline Building Blocks Overview Under the Hood Interested Components Get Dirty Q&A Special Keys HOME key BACK key Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 13. Outline Building Blocks Under the Hood Random Topics Get Dirty Q&A Outline Building Blocks Overview Interested Components Under the Hood Random Topics Get Dirty Development Code Q&A Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 14. Outline Building Blocks Under the Hood Random Topics Get Dirty Q&A Process View SurfaceManager, WindowManager, and SurfaceManager are threads of a single process (system server) Every application is usually a process of itself Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 15. Outline Building Blocks Under the Hood Random Topics Get Dirty Q&A Zygote Is a process started on system initialization Preloads java classes and resources Forks system server Listens silently on /dev/socket/zygote Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 16. Outline Building Blocks Under the Hood Random Topics Get Dirty Q&A Binder Early in the lifetime of an application process, thread(s) are created and blocked on /dev/binder Binder is used mainly for RPC Fragile Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 17. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Outline Building Blocks Overview Interested Components Under the Hood Random Topics Get Dirty Development Code Q&A Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 18. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Build System build/core/core/build-system.html . build/envsetup.sh showcommands export ANDROID JAVA HOME if non-standard Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 19. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A adb ADBHOST for transport over TCP/IP kill-server remount pull/push logcat shell Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 20. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A hierarchyviewer Display view hierarchy Display view Invalidate/Relayout Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 21. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management SurfaceFlinger has a SurfaceHeapManager Every client has a MemoryDealer, as returned by SurfaceHeapManager Every surface of a client also has dealer(s), from client or GPU Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 22. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. A dealer consists of a heap and an allocator A heap represents a sharable big chunk of memory An allocator is an algorithm Small chunks of memory from the heap are returned Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 23. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. Real flow A client asks for a new surface, createSurface Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 24. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. Real flow A client asks for a new surface, createSurface createSurface calls createNormalSurfaceLocked Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 25. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. Real flow A client asks for a new surface, createSurface createSurface calls createNormalSurfaceLocked A layer is created and setBuffers is called to allocate buffers Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 26. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. Real flow A client asks for a new surface, createSurface createSurface calls createNormalSurfaceLocked A layer is created and setBuffers is called to allocate buffers Two dealers are created from client, one for front buffer and one for back buffer Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 27. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. Real flow A client asks for a new surface, createSurface createSurface calls createNormalSurfaceLocked A layer is created and setBuffers is called to allocate buffers Two dealers are created from client, one for front buffer and one for back buffer Two LayerBitmaps are created, initialized with the two dealers Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 28. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Graphics: Memory Management cont. Real flow A client asks for a new surface, createSurface createSurface calls createNormalSurfaceLocked A layer is created and setBuffers is called to allocate buffers Two dealers are created from client, one for front buffer and one for back buffer Two LayerBitmaps are created, initialized with the two dealers Heaps of dealers along with info about the layer are returned Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 29. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Hello World http://people.debian.org.tw/˜olv/surfaceflinger/demo.tar.gz Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 30. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Many Buffers Surface is double buffered EGLDisplaySurface is double buffered Same technique; Different code pathes, different purposes Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 31. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Double Buffering Sofware v.s. Hardware Memory copy Page flipping Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 32. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Dirty Region Associate buffers with dirty regions Copy back Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 33. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Frame 0 Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 34. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Frame 1 Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 35. Outline Building Blocks Development Under the Hood Code Get Dirty Q&A Frame 2 Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 36. Outline Building Blocks Under the Hood Get Dirty Q&A Outline Building Blocks Overview Interested Components Under the Hood Random Topics Get Dirty Development Code Q&A Chia-I Wu olv@0xlab.org Introduction to Android Window System
  • 37. Outline Building Blocks Under the Hood Get Dirty Q&A Q&A Questions? Chia-I Wu olv@0xlab.org Introduction to Android Window System