SlideShare una empresa de Scribd logo
1 de 63
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 1
Android Binder:
Getting Started
by
Zafar Shahid
Oct. 14 2018
Silicon Valley Code Camp
Paypal San Jose CA
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 2
Who are we
IPC: The heart of Android
Design Patterns
Proxy, Bridge, Mediator
Binder IPC Internals
Case Study (Graphics)
Conclusion
Agenda
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 3
iBridge interview preparation group
https://www.meetup.com/iBridge-Interview-Preparation-Group/
Meetup for latest trends in technology
White boarding opportunity
Share knowledge and learn from peers
Challenge yourself
Who are we
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 4
IPC: The heart of Android
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 5
Activity
Manager
Window
Manager
Alarm
Manager
Activity
Kernel
IPC (Inter-Process Communication)
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 6
Why IPC?
o Why
o Sandboxed process
o Isolation
o Security
o Reliability
o IPC In GNU/Linux
o Signal
o Pipe
o Socket
o Semaphore
o Message queue
o Shared memory
o IPC In Android
o Binder: lightweight RPC
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 7
•Developed under the name OpenBinder by Palm Inc. under the
leadership of Dianne Hackborn
•Android Binder is the customized re-implementation of
OpenBinder, which provides bindings to functions and data
from one execution environment to another
Binder History
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 8
8
Problem statement
• Applications and Services may run in
separate processes but must communicate
and share data
• IPC can introduce significant processing
overhead and security holes.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 9
Binder: Android's Solution
• Driver to facilitate inter-process communication
• High performance through shared memory
• Per-process thread pool for processing requests
• Reference counting, and mapping of object
references across processes
• Synchronous calls between processes
“In the Android platform, the binder is used for
nearly everything that happens across processes
in the core platform. " – Dianne Hackborn
https://lkml.org/lkml/2009/6/25/3
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 10
caller
callee
In the same process
Method invocation
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 11
caller
callee
callee
caller
interface
interface
interface
How?
Inter-process method invocation
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 12
caller
callee
Binder in kernel
callee
caller
Proxy
Binder Thread
Stub
interface
interface
interface
Inter-process method invocation
Design Patterns
• Proxy Pattern
• Mediator Pattern
• Bridge Pattern
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 14
14
Proxy Pattern in Android
•Binder decomposes the method call and all its corresponding
data to a level that Linux can understand.
• Transmitting it from the local process and address space to
the remote process and address space.
• Reassembling and reenacting the call there.
caller
callee
Binder in kernel
callee
caller
Proxy
Binder Thread
Stub
interface
interface
interface
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 1515
Mediator Pattern
•With the mediator pattern, communication
between objects is encapsulated with
a mediator object.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 1616
Bridge Pattern
•decouple an abstraction from its implementation
so that the two can vary independently
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 17
Proxy Design Pattern
A Proxy is basically a representative between
the Client and the Component.
It gives the Client a simple interface to the
Component.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 18
Some Proxy Pattern Usage
Protection Proxy: Controls access to
Component based on the access rights
of Clients.
Cache Proxy: Saves results temporarily
so when Client requests same expensive
operation again, the saved results are
returned without making call to
Component.
Virtual Proxy: Expensive objects are
created on demand.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 19
Firewall Proxy
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 20
Cache Proxy
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 21
Mediator Pattern
Common problem: Multiple objects of
same or different classes must
communicate/interact. Multiple
dependencies complicate objects, lead to
“spaghetti code.”
Solution: Define an object that
encapsulates how a set of objects
interact and interconnect. Make that
object the hub of communications,
responsible for controlling and
coordinating the interactions of clients –
the colleague objects.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 22
Law of Demeter
“… the methods of a class should
not depend in any way on the
structure of any class, except the
immediate (top-level) structure of
their own class. Further, each
method should send messages to
objects belonging to a very limited
set of classes only.”
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 23
Analogies/Metaphors
Air traffic control
Stock market
eBay
Linux File permissions
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 24
Linux
file
permissions
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 25
Air Traffic Control Tower Mediator
Air Traffic Control Tower: (Mediator)
• Control tower at a controlled airport :
• Pilot communicating with the Traffic control.
• Some constraints on take off and landing are enforced
by the tower
• Tower does not control the whole flight. It exists only
to enforce constraints in terminal area.
Air Traffic Controller
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 26
Motivation – Mozilla ver 1.4.1
GKGFX rendering library
From an abandoned code base
Lines are dependency relationships
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 27
Mutual Dependencies - Mozilla 1.4.1
Object Oriented Design
encourages distribution of
behavior among objects.
Such distribution can result
in an object structure with
many connections between
objects.
In the worst case, every
object ends up knowing
about every other.
www.castle-
cadenza.demon.co.uk/mediat.htm
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 28
Quote from Mozilla Developer
“Even though some of us used to work on Mozilla, we have
to admit that the Mozilla code is a gigantic, bloated mess,
not to mention slow, and with an internal API so
flamboyantly baroque that frankly we can't even
comprehend where to begin”
http://news.com.com/2100-1023-980492.html
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 29
Static Structure
ConcreteMediator
Mediator Colleague
ConcreteColleague1 ConcreteColleague2
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 30
Advantages
• Limits subclassing – localizes behavior that would otherwise be
distributed among several objects.
• Decouples colleagues – As the number of connections is limited
by redirecting to a common object.
• Promotes high level of reusability – It proliferates the
interconnections to help eventually reduce it.
• Due to loose coupling, both mediator and colleague classes can
be reused independent of each other.
• Changing the system behavior means subclassing the Mediator.
Danger
• Mediator can become monolithic, violating proscription
against “God” or manager classes and making it hard to
maintain.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 3131
Bridge patterns in
linking Java and C++
•Mediator pattern
Bridge Pattern in Android
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 32
Binder in Action
Process BProcess A
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 33
Binder Internals
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 34
•Binder framework
•Binder Object
–an instance of a class that implements the Binder interface.
–One Binder object can implement multiple Binders
•Binder Protocol
•IBinder Interface
–is a well-defined set of methods, properties and events that a
Binder can implement.
•Binder Token
–A numeric value that uniquely identifies a Binder
• Marshalling
• Parcels
• Binder driver
Binder Terminology
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 35
• IPC
•Identifying
•Calls
•Notification
•Security
Facilities
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 36
•Special Binder node with known Binder address
•Client does not know the address of remote Binder
–only Binder interface knows its own address
•Binder submits a name and its Binder token to SM
–Client retrieves Binder address with service name from SM
Service Manager (SM)
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 37
Get Service list from SM
•$ adb shell service list
Found 71 services:
0 stub_isms: [com.android.internal.telephony.ISms]
1 stub_phone: [com.android.internal.telephony.ITelephony]
2 stub_iphonesubinfo:
[com.android.internal.telephony.IPhoneSubInfo]
..
5 stub_telephony.registry:
[com.android.internal.telephony.ITelephonyRegistry]
...
7 stub_activity: [android.app.IActivityManager]
...
9 phone: [com.android.internal.telephony.ITelephony]
…
56 activity: [android.app.IActivityManager]
...
64 SurfaceFlinger: [android.ui.ISurfaceComposer]
...
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 38
Service Registration and Discovery
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 39
Implementation Layers of Binder
Implemented in C
Implemented in C++
Implemented in Java
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 40
API Layer
• AIDL (Android Interface Definition Languag
– Ease the implementation of
Android remote services
– Defines an interface with method
of remote services
• AIDL parser generates Java class
- Proxy class for Client
- Stub class for Service
• Java API Wrapper
- Introduce facilities to the binder
– Wraps the middleware layer
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 41
41
AIDL (Android Interface Definition Language)
• Jave like syntax
• Data Types
–Java Primitives
–Containers
•String, List, Map, CharSequence
•List<>
•Multidimensional Array
–Parcelable
–Interface Reference
• Direction - in, out, inout
• oneway
–android.os.IBinder.FLAG_ONEWAY
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 42
42
AIDL Compiler
Full-fledged Java(-only) Support
Stub and Proxy Generator
// Interface
interface IRemoteService {
void ping();
}
public class RemoteService extends Service {
public IBinder onBind(Intent intent) { return mBinder; }
private final IRemoteService.Stub mBinder =
new IRemoteService.Stub() {
public void ping() { // Nothing }
};
}
IRemoteService mService =
IRemoteService.Stub.asInterface(service);
Server
Client
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 43
• Problem: Kernel is in C language and does not
understand classes and other complex objects.
•Solution: Marshalling and Parcels.
• Simple inter process messaging system
• In an object oriented view, the transaction data is
called parcel.
• The procedure of building a parcel is called
marshalling an object.
• The procedure of rebuilding a object from a parcel
is called unmarshalling an object.
Parcels and Marshalling
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 44
”flatten” ”unflatten”
transmit
Delivering arguments of method
android.os.Parcel
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 45
Representation of Parcel
• Parcel is NOT for general-purpose serialization
–This class (and the corresponding Parcelable API for
placing arbitrary objects into a Parcel) is designed as
a high-performance IPC transport.
–Not appropriate to place any Parcel data into
persistent storage
• Functions for writing/reading primitive data types:
–writeByte(byte) / readByte()
–writeDouble(double) / readDouble()
–writeFloat(float) / readFloat()
–writeInt(int) / readInt()
–writeLong(long) / readLong()
–writeString(String) / readString()
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 46
Middleware Layer
• Implements the user space facilities
of the Binder framework in C++
• Implements structures and methods
to spawn and manage new threads
• Provides interaction with the Binder
kernel driver
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 47
Kernel Driver Layer
• Binder Driver supports the file operations:
- open, mmap, release, poll
• ioctl arguments
– Command
– Data buffer
• Command
– BINDER_WRITE_READ
– BINDER_SET_MAX_THREADS
– BINDER_SET_CONTEXT_MGR
– BINDER_THREAD_EXIT
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 48
/dev/binder$ adb cat /sys/devices/virtual/misc/binder/uevent
MAJOR=10
MINOR=47
DEVNAME=binder
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 49
socket binder
internal status associated to FD associated to PID
(FD can be shared among
threads in the same
process)
read & write
operation
stream I/O done at once by
ioctl
network
transparency
Yes No
expected local only
Binder vs UNIX socket
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 50
50
Binder Performance
• Good
• Compact method index
• Native binary marshalling
• Support of ashmem shortcut
• Bad
• Dalvik Parcel overhead
• ioctl() path is not optimal
• Interface name overhead
• Limitations
• Not for streaming data
• Only local
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 51
51
Binder Security
•Binder’s Security Features
–Securely Determined Client Identity
–Binder.getCallingUid(), Binder.getCallingPid()
–Similar to Unix Domain Socket
getsockopt(..., SO_PEERCRED, ...)
–Interface Reference Security
•Client cannot guess Interface Reference
•Service Manager
–Directory Service for System Services
•Serveice should check client permission
Context.checkPermission(permission, pid, uid)
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 52
Remote Procedure Call
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 53
BINDER_WRITE_READ
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 54
•Target Method
–handle : Remote Interface
–ptr & cookie : Local Interface
•– code : Method ID
•Parcel - Input/Output Parameters
–data.ptr.buffer
–data_size
•Object Reference Management
–data.ptr.offsets
–offsets_size
•Security
–sender_pid
–sender_euid
•No Transaction GUID
–Transparent Recursion
Binder Transaction
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 55
Object Reference Management
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 56
Binder use case: Android Graphics
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 57
Binder IPC is used for communicating between Graphics client and service.
Ref: http://www.cnblogs.com/xl19862005/archive/2011/11/17/2215363.html
Use
Case
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 58
Surface
Source: frameworks/base/core/java/android/view/Surface.java
/* Handle on to a raw buffer that is being
managed by the screen compositor */
public class Surface implements Parcelable
{
public Surface() {
mCanvas = new CompatibleCanvas();
}
private class CompatibleCanvas
extends Canvas { /* ... */ }
}
Surface instances can be written to and restored from a Parcel.
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 59
”flatten” ”unflatten”
transmit
Delivering arguments of method
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 60
• Can combine 2D/3D surfaces and surfaces from multiple applications
• Surfaces passed as buffers via Binder IPC calls
• Can use OpenGL ES and 2D hardware acceleraton.
Android SurfaceFlinger
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 61
Everything is
around Binder
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 62
Camera + SurfaceFlinger + Binder
Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 63
Questions?
References:
• Android IPC Mechanism by Jim Huang
• Inter-process communication of Android, Tetsuyuki Kobayashi
• http://blog.goggb.com/?post=1580
• Android Binder – Android Interprocess Communication, Thorsten
Schreiber
• Design Patterns in the Android Framework, Prof. Sheng-De Wang
• Deep Dive into Android IPC/Binder Framework at Android Builders
Summit 2013, by Aleksandar Gargenta, Marakana Inc.

Más contenido relacionado

La actualidad más candente

Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys 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
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverNanik Tolaram
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in androidHaifeng Li
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh KhetanRajesh Khetan
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Opersys inc.
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 
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.
 

La actualidad más candente (20)

Android Internals
Android InternalsAndroid Internals
Android Internals
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
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
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device Driver
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in android
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh Khetan
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
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
 

Similar a Android Binder: Deep Dive

Android application security testing
Android application security testingAndroid application security testing
Android application security testingMykhailo Antonishyn
 
From reactive toproactive mobile security
From reactive toproactive mobile securityFrom reactive toproactive mobile security
From reactive toproactive mobile securityMobileSoft
 
Getting started with Android pentesting
Getting started with Android pentestingGetting started with Android pentesting
Getting started with Android pentestingMinali Arora
 
Getting started with android
Getting started with androidGetting started with android
Getting started with androidVandana Verma
 
Hierarchy Viewer Internals
Hierarchy Viewer InternalsHierarchy Viewer Internals
Hierarchy Viewer InternalsKyungmin Lee
 
DELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroid
DELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroidDELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroid
DELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroidMahmoud Hammad
 
BoscoChat (A free Wi-Fi Chat Room in Android)
BoscoChat (A free Wi-Fi Chat Room in Android)BoscoChat (A free Wi-Fi Chat Room in Android)
BoscoChat (A free Wi-Fi Chat Room in Android)Samaresh Debbarma
 
The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
The Golden Ticket: Docker and High Security Microservices by Aaron GrattafioriThe Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
The Golden Ticket: Docker and High Security Microservices by Aaron GrattafioriDocker, Inc.
 
Refreshing Domain Driven Design
Refreshing Domain Driven DesignRefreshing Domain Driven Design
Refreshing Domain Driven DesignAndré Borgonovo
 
DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...
DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...
DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...Docker, Inc.
 
Null Mumbai Meet_Android Reverse Engineering by Samrat Das
Null Mumbai Meet_Android Reverse Engineering by Samrat DasNull Mumbai Meet_Android Reverse Engineering by Samrat Das
Null Mumbai Meet_Android Reverse Engineering by Samrat Dasnullowaspmumbai
 
DockerCon - The missing piece : when Docker networking unleashes software arc...
DockerCon - The missing piece : when Docker networking unleashes software arc...DockerCon - The missing piece : when Docker networking unleashes software arc...
DockerCon - The missing piece : when Docker networking unleashes software arc...Laurent Grangeau
 
The missing piece : when Docker networking and services finally unleashes so...
 The missing piece : when Docker networking and services finally unleashes so... The missing piece : when Docker networking and services finally unleashes so...
The missing piece : when Docker networking and services finally unleashes so...Adrien Blind
 
Final_Presentation_FlowDroid
Final_Presentation_FlowDroidFinal_Presentation_FlowDroid
Final_Presentation_FlowDroidKruti Sharma
 
Please, Please, PLEASE Defend Your Mobile Apps!
Please, Please, PLEASE Defend Your Mobile Apps!Please, Please, PLEASE Defend Your Mobile Apps!
Please, Please, PLEASE Defend Your Mobile Apps!Jerod Brennen
 
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsWebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsSecuRing
 
Thick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash CourseThick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash CourseNetSPI
 
Toward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareToward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareZongXian Shen
 
Mobile application security
Mobile application securityMobile application security
Mobile application securityShubhneet Goel
 

Similar a Android Binder: Deep Dive (20)

Android application security testing
Android application security testingAndroid application security testing
Android application security testing
 
From reactive toproactive mobile security
From reactive toproactive mobile securityFrom reactive toproactive mobile security
From reactive toproactive mobile security
 
Getting started with Android pentesting
Getting started with Android pentestingGetting started with Android pentesting
Getting started with Android pentesting
 
Getting started with android
Getting started with androidGetting started with android
Getting started with android
 
Hierarchy Viewer Internals
Hierarchy Viewer InternalsHierarchy Viewer Internals
Hierarchy Viewer Internals
 
DELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroid
DELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroidDELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroid
DELDroid: Determination & Enforcement of Least Privilege Architecture in AnDroid
 
BoscoChat (A free Wi-Fi Chat Room in Android)
BoscoChat (A free Wi-Fi Chat Room in Android)BoscoChat (A free Wi-Fi Chat Room in Android)
BoscoChat (A free Wi-Fi Chat Room in Android)
 
The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
The Golden Ticket: Docker and High Security Microservices by Aaron GrattafioriThe Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
 
Refreshing Domain Driven Design
Refreshing Domain Driven DesignRefreshing Domain Driven Design
Refreshing Domain Driven Design
 
DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...
DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...
DockerCon EU 2015: The Missing Piece: when Docker networking unleashing soft ...
 
Null Mumbai Meet_Android Reverse Engineering by Samrat Das
Null Mumbai Meet_Android Reverse Engineering by Samrat DasNull Mumbai Meet_Android Reverse Engineering by Samrat Das
Null Mumbai Meet_Android Reverse Engineering by Samrat Das
 
DockerCon - The missing piece : when Docker networking unleashes software arc...
DockerCon - The missing piece : when Docker networking unleashes software arc...DockerCon - The missing piece : when Docker networking unleashes software arc...
DockerCon - The missing piece : when Docker networking unleashes software arc...
 
The missing piece : when Docker networking and services finally unleashes so...
 The missing piece : when Docker networking and services finally unleashes so... The missing piece : when Docker networking and services finally unleashes so...
The missing piece : when Docker networking and services finally unleashes so...
 
Final_Presentation_FlowDroid
Final_Presentation_FlowDroidFinal_Presentation_FlowDroid
Final_Presentation_FlowDroid
 
Please, Please, PLEASE Defend Your Mobile Apps!
Please, Please, PLEASE Defend Your Mobile Apps!Please, Please, PLEASE Defend Your Mobile Apps!
Please, Please, PLEASE Defend Your Mobile Apps!
 
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsWebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
 
Brief Tour about Android Security
Brief Tour about Android SecurityBrief Tour about Android Security
Brief Tour about Android Security
 
Thick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash CourseThick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash Course
 
Toward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareToward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malware
 
Mobile application security
Mobile application securityMobile application security
Mobile application security
 

Último

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 

Último (20)

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 

Android Binder: Deep Dive

  • 1. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 1 Android Binder: Getting Started by Zafar Shahid Oct. 14 2018 Silicon Valley Code Camp Paypal San Jose CA
  • 2. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 2 Who are we IPC: The heart of Android Design Patterns Proxy, Bridge, Mediator Binder IPC Internals Case Study (Graphics) Conclusion Agenda
  • 3. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 3 iBridge interview preparation group https://www.meetup.com/iBridge-Interview-Preparation-Group/ Meetup for latest trends in technology White boarding opportunity Share knowledge and learn from peers Challenge yourself Who are we
  • 4. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 4 IPC: The heart of Android
  • 5. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 5 Activity Manager Window Manager Alarm Manager Activity Kernel IPC (Inter-Process Communication)
  • 6. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 6 Why IPC? o Why o Sandboxed process o Isolation o Security o Reliability o IPC In GNU/Linux o Signal o Pipe o Socket o Semaphore o Message queue o Shared memory o IPC In Android o Binder: lightweight RPC
  • 7. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 7 •Developed under the name OpenBinder by Palm Inc. under the leadership of Dianne Hackborn •Android Binder is the customized re-implementation of OpenBinder, which provides bindings to functions and data from one execution environment to another Binder History
  • 8. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 8 8 Problem statement • Applications and Services may run in separate processes but must communicate and share data • IPC can introduce significant processing overhead and security holes.
  • 9. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 9 Binder: Android's Solution • Driver to facilitate inter-process communication • High performance through shared memory • Per-process thread pool for processing requests • Reference counting, and mapping of object references across processes • Synchronous calls between processes “In the Android platform, the binder is used for nearly everything that happens across processes in the core platform. " – Dianne Hackborn https://lkml.org/lkml/2009/6/25/3
  • 10. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 10 caller callee In the same process Method invocation
  • 11. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 11 caller callee callee caller interface interface interface How? Inter-process method invocation
  • 12. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 12 caller callee Binder in kernel callee caller Proxy Binder Thread Stub interface interface interface Inter-process method invocation
  • 13. Design Patterns • Proxy Pattern • Mediator Pattern • Bridge Pattern
  • 14. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 14 14 Proxy Pattern in Android •Binder decomposes the method call and all its corresponding data to a level that Linux can understand. • Transmitting it from the local process and address space to the remote process and address space. • Reassembling and reenacting the call there. caller callee Binder in kernel callee caller Proxy Binder Thread Stub interface interface interface
  • 15. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 1515 Mediator Pattern •With the mediator pattern, communication between objects is encapsulated with a mediator object.
  • 16. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 1616 Bridge Pattern •decouple an abstraction from its implementation so that the two can vary independently
  • 17. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 17 Proxy Design Pattern A Proxy is basically a representative between the Client and the Component. It gives the Client a simple interface to the Component.
  • 18. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 18 Some Proxy Pattern Usage Protection Proxy: Controls access to Component based on the access rights of Clients. Cache Proxy: Saves results temporarily so when Client requests same expensive operation again, the saved results are returned without making call to Component. Virtual Proxy: Expensive objects are created on demand.
  • 19. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 19 Firewall Proxy
  • 20. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 20 Cache Proxy
  • 21. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 21 Mediator Pattern Common problem: Multiple objects of same or different classes must communicate/interact. Multiple dependencies complicate objects, lead to “spaghetti code.” Solution: Define an object that encapsulates how a set of objects interact and interconnect. Make that object the hub of communications, responsible for controlling and coordinating the interactions of clients – the colleague objects.
  • 22. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 22 Law of Demeter “… the methods of a class should not depend in any way on the structure of any class, except the immediate (top-level) structure of their own class. Further, each method should send messages to objects belonging to a very limited set of classes only.”
  • 23. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 23 Analogies/Metaphors Air traffic control Stock market eBay Linux File permissions
  • 24. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 24 Linux file permissions
  • 25. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 25 Air Traffic Control Tower Mediator Air Traffic Control Tower: (Mediator) • Control tower at a controlled airport : • Pilot communicating with the Traffic control. • Some constraints on take off and landing are enforced by the tower • Tower does not control the whole flight. It exists only to enforce constraints in terminal area. Air Traffic Controller
  • 26. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 26 Motivation – Mozilla ver 1.4.1 GKGFX rendering library From an abandoned code base Lines are dependency relationships
  • 27. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 27 Mutual Dependencies - Mozilla 1.4.1 Object Oriented Design encourages distribution of behavior among objects. Such distribution can result in an object structure with many connections between objects. In the worst case, every object ends up knowing about every other. www.castle- cadenza.demon.co.uk/mediat.htm
  • 28. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 28 Quote from Mozilla Developer “Even though some of us used to work on Mozilla, we have to admit that the Mozilla code is a gigantic, bloated mess, not to mention slow, and with an internal API so flamboyantly baroque that frankly we can't even comprehend where to begin” http://news.com.com/2100-1023-980492.html
  • 29. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 29 Static Structure ConcreteMediator Mediator Colleague ConcreteColleague1 ConcreteColleague2
  • 30. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 30 Advantages • Limits subclassing – localizes behavior that would otherwise be distributed among several objects. • Decouples colleagues – As the number of connections is limited by redirecting to a common object. • Promotes high level of reusability – It proliferates the interconnections to help eventually reduce it. • Due to loose coupling, both mediator and colleague classes can be reused independent of each other. • Changing the system behavior means subclassing the Mediator. Danger • Mediator can become monolithic, violating proscription against “God” or manager classes and making it hard to maintain.
  • 31. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 3131 Bridge patterns in linking Java and C++ •Mediator pattern Bridge Pattern in Android
  • 32. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 32 Binder in Action Process BProcess A
  • 33. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 33 Binder Internals
  • 34. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 34 •Binder framework •Binder Object –an instance of a class that implements the Binder interface. –One Binder object can implement multiple Binders •Binder Protocol •IBinder Interface –is a well-defined set of methods, properties and events that a Binder can implement. •Binder Token –A numeric value that uniquely identifies a Binder • Marshalling • Parcels • Binder driver Binder Terminology
  • 35. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 35 • IPC •Identifying •Calls •Notification •Security Facilities
  • 36. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 36 •Special Binder node with known Binder address •Client does not know the address of remote Binder –only Binder interface knows its own address •Binder submits a name and its Binder token to SM –Client retrieves Binder address with service name from SM Service Manager (SM)
  • 37. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 37 Get Service list from SM •$ adb shell service list Found 71 services: 0 stub_isms: [com.android.internal.telephony.ISms] 1 stub_phone: [com.android.internal.telephony.ITelephony] 2 stub_iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo] .. 5 stub_telephony.registry: [com.android.internal.telephony.ITelephonyRegistry] ... 7 stub_activity: [android.app.IActivityManager] ... 9 phone: [com.android.internal.telephony.ITelephony] … 56 activity: [android.app.IActivityManager] ... 64 SurfaceFlinger: [android.ui.ISurfaceComposer] ...
  • 38. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 38 Service Registration and Discovery
  • 39. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 39 Implementation Layers of Binder Implemented in C Implemented in C++ Implemented in Java
  • 40. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 40 API Layer • AIDL (Android Interface Definition Languag – Ease the implementation of Android remote services – Defines an interface with method of remote services • AIDL parser generates Java class - Proxy class for Client - Stub class for Service • Java API Wrapper - Introduce facilities to the binder – Wraps the middleware layer
  • 41. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 41 41 AIDL (Android Interface Definition Language) • Jave like syntax • Data Types –Java Primitives –Containers •String, List, Map, CharSequence •List<> •Multidimensional Array –Parcelable –Interface Reference • Direction - in, out, inout • oneway –android.os.IBinder.FLAG_ONEWAY
  • 42. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 42 42 AIDL Compiler Full-fledged Java(-only) Support Stub and Proxy Generator // Interface interface IRemoteService { void ping(); } public class RemoteService extends Service { public IBinder onBind(Intent intent) { return mBinder; } private final IRemoteService.Stub mBinder = new IRemoteService.Stub() { public void ping() { // Nothing } }; } IRemoteService mService = IRemoteService.Stub.asInterface(service); Server Client
  • 43. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 43 • Problem: Kernel is in C language and does not understand classes and other complex objects. •Solution: Marshalling and Parcels. • Simple inter process messaging system • In an object oriented view, the transaction data is called parcel. • The procedure of building a parcel is called marshalling an object. • The procedure of rebuilding a object from a parcel is called unmarshalling an object. Parcels and Marshalling
  • 44. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 44 ”flatten” ”unflatten” transmit Delivering arguments of method android.os.Parcel
  • 45. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 45 Representation of Parcel • Parcel is NOT for general-purpose serialization –This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport. –Not appropriate to place any Parcel data into persistent storage • Functions for writing/reading primitive data types: –writeByte(byte) / readByte() –writeDouble(double) / readDouble() –writeFloat(float) / readFloat() –writeInt(int) / readInt() –writeLong(long) / readLong() –writeString(String) / readString()
  • 46. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 46 Middleware Layer • Implements the user space facilities of the Binder framework in C++ • Implements structures and methods to spawn and manage new threads • Provides interaction with the Binder kernel driver
  • 47. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 47 Kernel Driver Layer • Binder Driver supports the file operations: - open, mmap, release, poll • ioctl arguments – Command – Data buffer • Command – BINDER_WRITE_READ – BINDER_SET_MAX_THREADS – BINDER_SET_CONTEXT_MGR – BINDER_THREAD_EXIT
  • 48. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 48 /dev/binder$ adb cat /sys/devices/virtual/misc/binder/uevent MAJOR=10 MINOR=47 DEVNAME=binder
  • 49. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 49 socket binder internal status associated to FD associated to PID (FD can be shared among threads in the same process) read & write operation stream I/O done at once by ioctl network transparency Yes No expected local only Binder vs UNIX socket
  • 50. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 50 50 Binder Performance • Good • Compact method index • Native binary marshalling • Support of ashmem shortcut • Bad • Dalvik Parcel overhead • ioctl() path is not optimal • Interface name overhead • Limitations • Not for streaming data • Only local
  • 51. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 51 51 Binder Security •Binder’s Security Features –Securely Determined Client Identity –Binder.getCallingUid(), Binder.getCallingPid() –Similar to Unix Domain Socket getsockopt(..., SO_PEERCRED, ...) –Interface Reference Security •Client cannot guess Interface Reference •Service Manager –Directory Service for System Services •Serveice should check client permission Context.checkPermission(permission, pid, uid)
  • 52. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 52 Remote Procedure Call
  • 53. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 53 BINDER_WRITE_READ
  • 54. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 54 •Target Method –handle : Remote Interface –ptr & cookie : Local Interface •– code : Method ID •Parcel - Input/Output Parameters –data.ptr.buffer –data_size •Object Reference Management –data.ptr.offsets –offsets_size •Security –sender_pid –sender_euid •No Transaction GUID –Transparent Recursion Binder Transaction
  • 55. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 55 Object Reference Management
  • 56. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 56 Binder use case: Android Graphics
  • 57. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 57 Binder IPC is used for communicating between Graphics client and service. Ref: http://www.cnblogs.com/xl19862005/archive/2011/11/17/2215363.html Use Case
  • 58. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 58 Surface Source: frameworks/base/core/java/android/view/Surface.java /* Handle on to a raw buffer that is being managed by the screen compositor */ public class Surface implements Parcelable { public Surface() { mCanvas = new CompatibleCanvas(); } private class CompatibleCanvas extends Canvas { /* ... */ } } Surface instances can be written to and restored from a Parcel.
  • 59. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 59 ”flatten” ”unflatten” transmit Delivering arguments of method
  • 60. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 60 • Can combine 2D/3D surfaces and surfaces from multiple applications • Surfaces passed as buffers via Binder IPC calls • Can use OpenGL ES and 2D hardware acceleraton. Android SurfaceFlinger
  • 61. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 61 Everything is around Binder
  • 62. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 62 Camera + SurfaceFlinger + Binder
  • 63. Zafar Shahid, PhD Android Binder Deep Dive Track (1/3) 63 Questions? References: • Android IPC Mechanism by Jim Huang • Inter-process communication of Android, Tetsuyuki Kobayashi • http://blog.goggb.com/?post=1580 • Android Binder – Android Interprocess Communication, Thorsten Schreiber • Design Patterns in the Android Framework, Prof. Sheng-De Wang • Deep Dive into Android IPC/Binder Framework at Android Builders Summit 2013, by Aleksandar Gargenta, Marakana Inc.