Android Architecture and Binder. Dhinakaran Pandiyan Saketh Paranjape

Similar documents
BINDER THE ANDROID IPC FRAMEWORK. Antoine 'xdbob' Damhet. July 15, 2016

Android Services & Local IPC: Overview of Programming Bound Services

In a Bind? Android s Binder in depth. Jonathan Levin

Android System Development Day-4. Team Emertxe

Slides on cross- domain call and Remote Procedure Call (RPC)

Services Broadcast Receivers Permissions

Lecture 3 Android Internals

Android Fundamentals - Part 1

CS378 -Mobile Computing. Services and Broadcast Receivers

Android Services & Local IPC: The Command Processor Pattern (Part 1)

CopperDroid: Automatic Reconstruction of Android Malware Behaviors

Services. Background operating component without a visual interface Running in the background indefinitely

Practical Exercise Inter-Process Communication

Services. service: A background task used by an app.

ANDROID SERVICES, BROADCAST RECEIVER, APPLICATION RESOURCES AND PROCESS

EMBEDDED SYSTEMS PROGRAMMING Android Services

Services. Marco Ronchetti Università degli Studi di Trento

Signal Example 1. Signal Example 2

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

Processes and Threads

Software Practice 3 Today s lecture Today s Task

Extensions to Barrelfish Asynchronous C

DeepDroid: Dynamically Enforcing Enterprise Policy on Android Devices

Android Binder Security Note On >Passing Binder Through Another Binder<

Android Services & Local IPC: The Activator Pattern (Part 2)

Security Philosophy. Humans have difficulty understanding risk

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

Services are software components designed specifically to perform long background operations.

Implementing a Download Background Service

Communication. Distributed Systems Santa Clara University 2016

Mobile Programming Practice Background processing AsynTask Service Broadcast receiver Lab #5

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

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

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

Thrift specification - Remote Procedure Call

CPS 310 midterm exam #2, 4/10/2017

Inter-Process Communication

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

Network and Distributed System Security Symposium (NDSS) San Diego, USA, Februrary 9, 2015

Interprocess Communication. Originally multiple approaches Today more standard some differences between distributions still exist

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

Inter-Process Communication

Last Class: RPCs. Today:

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Inter-Process Communication

Distributed Systems Principles and Paradigms. Distributed Object-Based Systems. Remote distributed objects. Remote distributed objects

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Lecture 8: Other IPC Mechanisms. CSC 469H1F Fall 2006 Angela Demke Brown

Chapter 3: Processes. Operating System Concepts 8th Edition

C 1. Recap: Finger Table. CSE 486/586 Distributed Systems Remote Procedure Call. Chord: Node Joins and Leaves. Recall? Socket API

Topics. Lecture 8: Other IPC Mechanisms. Socket IPC. Unix Communication

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

CHAPTER 3 - PROCESS CONCEPT

Termite WiFi Direct API

CLIENT-SIDE PROGRAMMING

Chapter 10 DISTRIBUTED OBJECT-BASED SYSTEMS

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

Processes COMPSCI 386

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book!

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

HLD For SMP node affinity

Chapter 3: Processes

CommonAPITests. Generated by Doxygen Tue May :09:25

Threads Chapter 5 1 Chapter 5

ANDROID NATIVE APP: INTRODUCTION TO ANDROID. Roberto Beraldi

Chapter 3: Client-Server Paradigm and Middleware

arxiv: v1 [cs.cr] 23 Apr 2016

Applying User-level Drivers on

ECE 650 Systems Programming & Engineering. Spring 2018

Scippa: System-Centric IPC Provenance on Android

An Implementation of the Solaris Doors API for Linux

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

STUDY OF SOCKET PROGRAMMING

Lecture 1 - Introduction to Android

Another difference is that the kernel includes only the suspend to memory mechanism, and not the suspend to hard disk, which is used on PCs.

MODELS OF DISTRIBUTED SYSTEMS

CHAPTER - 4 REMOTE COMMUNICATION

Motivation of VPN! Overview! VPN addressing and routing! Two basic techniques for VPN! ! How to guarantee privacy of network traffic?!

Interprocess Communication

Large Systems: Design + Implementation: Communication Coordination Replication. Image (c) Facebook

Android. Broadcasts Services Notifications

Operating Systems 2010/2011

Services. Marco Ronchetti Università degli Studi di Trento

RPC IMPLEMENTATION: BASIC STEPS. Instructor: Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

RPC and RMI. 2501ICT Nathan

CS 43: Computer Networks. 07: Concurrency and Non-blocking I/O Sep 17, 2018

A Report on RMI and RPC Submitted by Sudharshan Reddy B

FastFlow: targeting distributed systems Massimo Torquati

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Start of Lecture on January 20, Chapter 3: Processes

Distributed Programming and Remote Procedure Calls (RPC): Apache Thrift. George Porter CSE 124 February 19, 2015

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

IPv4 and ipv6 INTEROPERABILITY

CPSC 8220 FINAL EXAM, SPRING 2016

Middleware. Adapted from Alonso, Casati, Kuno, Machiraju Web Services Springer 2004

Transcription:

Android Architecture and Binder Dhinakaran Pandiyan Saketh Paranjape

Android Software stack

Anatomy of an Android application Activity UI component typically corresponding of one screen Service Background process without UI (E.g mp3 player). Content Manager Enables applications to share data (E.g Contacts shared b/w all applications) Broadcast Receiver Responds to external events, can wake up your process (E.g SMS, Phone ring, Low battery)

Anatomy of an Android Application

IPC is ubiquitous throughout the Android platform Example: An mp3 player application It executes as 2 separate process mp3 player UI mp3 player backend [Activity] [Service]

IPC mechanism in android In GNU/Linux Pipes Shared Memory Message Queue In Android Binder

Why Binder over conventional IPC Binder has additional features that sockets don't have E.g binder allows passing file descriptors across processes. Pipes cannot perform RPC. Object reference counting, Object mapping. Binder has elaborate data referencing policies, it is not a simplistic kernel driver.

Binder and Open Binder Developed under the name OpenBinder by Palm Inc. Android Binder is the customized reimplementation of OpenBinder.

Binder A kernel driver to facilitate inter-process communication Lightweight RPC (Remote Procedure Communication) mechanism Per-process thread pool for processing requests Synchronous communication b/w processes

IPC internals from Bottom Up IPC over Binder kernel driver IPC over the middleware IPC over the Application layer

IPC over Binder kernel driver Binder Driver supports the file operations open, mmap, release, poll and the system call ioctl The first thing an application must do is open the Binder kernel module("/dev/binder"). This associates a file descriptor with that thread The kernel module uses the descriptor to identify the initiators and recipients of Binder IPCs.

All interactions with the driver will happen through a small set of ioctl() commands. BINDER_WRITE_READ BINDER_SET_MAX_THREADS BINDER_SET_CONTEXT_MGR BINDER_THREAD_EXIT BINDER_VERSION The key command is BINDER_WRITE_READ, which is the basis for all IPC operations. ioctl(fd, BINDER_WRITE_READ, &bwt); To initiate an IPC transaction, ioctl call with BINDER_READ_WRITE command is invoked

The data to be passed to the ioctl() call is of the type struct binder_write_read struct binder_write_read { ssize_t write_size; /*bytes to write*/ ssize_t write_consumed; /*bytes consumed*/ const void* write_buffer; ssize_t read_size; /*bytes to be read*/ void* read_buffer; /*bytes consumed*/ }; The write buffer contains an enum bctransaction followed by a binder_transaction_data.

In this structure target is the handle of the object that should receive the transaction The code refers to the Method ID. struct binder_transaction_data { union { size_t handle; /* target descriptor of command transaction */ void *ptr; /* target descriptor of return transaction */ }target; void *cookie; /* target object cookie */ unsigned int code; /* transaction command */ /* General information about the transaction. */ unsigned int flags; pid_t sender_pid; uid_t sender_euid; size_t data_size; /* number of bytes of data */ size_t offsets_size; /* number of bytes of offsets */... };

How does a user process receive the handle to a target process?

Binder Driver IPC Binder performs mapping of objects between two processes. A pool of threads is associated with each service to process incoming IPC

Service Manager Service_manager provides registry service to other processes It must be started before any other service gets running It first opens /dev/binder driver It then calls BINDER_SET_CONTEXT_MGR ioctl to let binder kernel driver know it acts as a manager service_manager runs first, it will register itself with a handle 0 The other process must use this handle to talk with service_manager

Using 0 as the handle, service provider registers a service with the service manager The binder will generate a handle (assume 10) for the service Service manager will store the name and handle Using 0 as the handle, the client tries to get a particular service Service manager on finding that particular service will also return the handle '10' of the server, so that the client can communicate with the server directly

IPC over middleware Middleware C++ framework over the binder kernel driver A high level interface responsible for marshalling and unmarshalling Access the kernel driver for the application

Native IPC framework Native Binder framework

IPC over Application Layer public interface IBinder boolean transact(int code, Parcel data, Parcel reply, int flags) public class Binder implements IBinder ontransact(int code, Parcel data, Parcel reply, int flags)

Bound Service Return an IBinder for the client to use Implement onbind() and other methods for RPC Create a.aidl file which generates interface file in java mbinder = new IRemoteService.Stub() public IBinder onbind(intent intent) { // Return the interface return mbinder; }

Client Calls bindservice() to bind to the service Implements onserviceconnected() callback public void onserviceconnected(componentname classname, IBinder service) { miremoteservice = RemoteService.Stub.asInterface(service); }

What to do with IPC? Passing Objects over IPC send parcels transact() and ontransact() Calling an IPC Method Use IBinder object at the client to call methods implemented by the server miremoteservice.getservice()

Parcel

IPC overview across Layers layers

Other Android specific features DVM: A JVM for Android o Compact byte code o Register based implementation o Native Libraries bypass DVM Power Management o Battery Power Android tries to put device to sleep o A mechanism to say that your app wants device to stay on i.e., don t sleep o acquire(long timeout) o void release()

Project plan Analyze binder performance Trace Binder IPC data/control flow References: http://www.cubrid.org/blog/dev-platform/binder-communication-mechanism-of-androidprocesses/ http://www.nds.rub.de/media/attachments/files/2012/03/binder.pdf http://developer.android.com/guide/ http://app-solut.com/ http://mindtherobot.com http://www.slideshare.net/jserv/android-ipc-mechanism by Jim Huang Analysis of the Android Architecture -Stefan Br ahler http://elinux.org/android_binder http://www.angryredplanet.com/~hackbod/openbinder/docs/html/index.html Service Manager Run [blogimg.chinaunix.net/blog/upfile2/081203105044.pdf]