• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MobAppDev (Fall 2013): Android Bound Services
 

MobAppDev (Fall 2013): Android Bound Services

on

  • 1,288 views

 

Statistics

Views

Total Views
1,288
Views on SlideShare
753
Embed Views
535

Actions

Likes
0
Downloads
11
Comments
0

47 Embeds 535

http://vkedco.blogspot.com 224
http://www.vkedco.blogspot.com 80
http://vkedco.blogspot.in 55
http://www.vkedco.blogspot.in 19
http://reader.aol.com 17
http://vkedco.blogspot.com.br 11
http://www.vkedco.blogspot.ru 10
http://vkedco.blogspot.com.tr 8
http://vkedco.blogspot.ru 7
http://vkedco.blogspot.com.au 7
http://www.vkedco.blogspot.kr 5
http://vkedco.blogspot.kr 5
http://vkedco.blogspot.co.il 5
http://www.vkedco.blogspot.fr 4
http://vkedco.blogspot.pt 4
http://www.vkedco.blogspot.co.uk 4
http://www.vkedco.blogspot.com.tr 4
http://vkedco.blogspot.cz 4
http://vkedco.blogspot.mx 3
http://vkedco.blogspot.sg 3
http://vkedco.blogspot.ca 3
http://vkedco.blogspot.sk 3
http://www.vkedco.blogspot.com.es 3
http://vkedco.blogspot.ie 3
http://www.vkedco.blogspot.nl 3
http://vkedco.blogspot.it 3
http://vkedco.blogspot.dk 3
http://vkedco.blogspot.co.uk 3
http://vkedco.blogspot.ro 3
http://vkedco.blogspot.co.at 3
http://vkedco.blogspot.de 3
http://www.vkedco.blogspot.ro 2
http://vkedco.blogspot.fr 2
http://vkedco.blogspot.tw 2
http://www.vkedco.blogspot.ch 2
http://vkedco.blogspot.com.es 2
http://www.vkedco.blogspot.de 2
http://vkedco.blogspot.ae 2
http://www.vkedco.blogspot.jp 1
http://vkedco.blogspot.gr 1
http://www.vkedco.blogspot.hu 1
http://vkedco.blogspot.nl 1
http://www.blogger.com 1
http://www.vkedco.blogspot.cz 1
http://vkedco.blogspot.com.ar 1
http://vkedco.blogspot.be 1
http://www.vkedco.blogspot.sg 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MobAppDev (Fall 2013): Android Bound Services MobAppDev (Fall 2013): Android Bound Services Presentation Transcript

    • Android MobAppDev Bound Services Vladimir Kulyukin www.vkedco.blogspot.com
    • Outline ● ● ● ● Android Binder Binder Terminology AIDL Sample Binder Service
    • Android Binder
    • Inter-Process Communication (IPC) ● ● ● ● Binder is an Inter-Process Communication (IPC) framework for developing OOP services for the Android OS IPC is a framework for sharing data among multiple processes It is an OOP framework for OS kernel development It is used by many native Android applications and services
    • Inter-Process Communication (IPC) ● ● ● IPC is used for Remote Procedure Calls (RPC), data sharing, memory sharing IPC encourages modularity, security, stability Each process on Android has a unique ID and runs in its sandboxed space
    • Binder Usage Many Android applications and services use and depend on Binder ● ActivityManagerService does life-cycle callbacks (e.g., onDestroy()) via Binder ● Android OS depends on the Binder framework ●
    • IPC Mechanisms Files ● Sockets ● Semaphores ● Shared Memory ● Intents ● Content Providers ● Android Binder ●
    • Binder Advantages Binder has a built-in reference counting mechanism ● Binder has a service termination mechanism ● When a Binder service does not have any client references, the service's owner is notified ●
    • Binder Advantages Android has a native binder interface implemented in libbinder ● Android Open Source project has a Java IBinder interface and a wrapper around libbinder ● There is no POSIX standard for Binder ●
    • Binder Terms Driver – driver that supports communication among processes ● Protocol – communication protocol for Binder Driver ● Interface – interface that each Binder object must implement ● Object – an object that implements some Binder Interface ●
    • Binder Terms Token – unique 32-bit integer ID for a Binder object ● Service – implementation of a specific Binder object ● Client – a user of some Binder Service ● Transaction – an operation invoked on a remote Binder object on the Binder protocol ●
    • Binder Terms ● ● ● ● ● Parcel – a unit of data Marshalling – process of conversion of data structures into parcels Unmarshalling – process of conversion of parcels into data structures Proxy – an implementation of some AIDL interface that marshals and unmarshals data on the client Stub – an implementation of some AIDL interface that marshals and unmarshals data on the server
    • Binder Discovery Clients get handles to services through the ServiceManager ● Services must be registered with ServiceManager ● Unregistered services cannot be discovered ● List of running services can be obtained with adb shell service list ●
    • AIDL
    • AIDL ● ● ● ● AIDL stands for Android Interface Definition Language AIDL is the language for Binder interfaces Each service interface is defined a .aidl file Android SDK has the aidl build tool that compiles .aidl files and places the generated code in the gen/ directory
    • Some Supported Data Types ● ● ● ● ● ● ● ● ● boolean, byte, char, int, long, float boolean[], byte[], char[], int[], long[], float[] CharSequence String Serializable Map android.os.Bundle List android.os.Parcelable
    • Parameters ● ● ● ● AIDL methods can return void or a value Non-primitive parameters must have directional tags: in, out, inout Static files are not supported The following exceptions are supported: NullException, IllegalStateException, IllegalArgumentException, BadParcelableException, SecurityException
    • Sample Binder Service
    • Problem Develop an Binder service that computes the sums of the first n Catalan and Fibonacci numbers. source code is in BoundSumService repo
    • Development Steps ● ● ● ● ● Develop a common library, BindSumLib, that will be used by the service (BindSumService) and the client (BindSumClient) Develop the service (BindSumService) and include BindSumLib as a library Install the service on Android Develop the client (BindSumClient) and include BindSumLib as a library Install the client on Android
    • BindSumLib
    • Interface package org.vkedco.mobappdev.bindsumlib; import org.vkedco.mobappdev.bindsumlib.SumRequest; import org.vkedco.mobappdev.bindsumlib.SumResponse; interface IBindSumService { long fibonacciSum(in long n); // sum of the first n fibonacci numbers long catalanSum(in long n); // sum of the first n catalan numbers SumResponse sum(in SumRequest req); } source code is in IBindSumService.aidl
    • SumRequest.aidl package org.vkedco.mobappdev.bindsumlib; parcelable SumRequest;
    • SumResponse.aidl package org.vkedco.mobappdev.bindsumlib; parcelable SumRequest; SumResponse;
    • AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> package org.vkedco.mobappdev.bindsumlib; <manifest xmlns:android="http://schemas.android.com/apk/res/andro id" parcelable SumRequest; package="org.vkedco.mobappdev.bindsumlib" android:versionCode="1" android:versionName="1.0" > </manifest>
    • BindSumService
    • Stub & Service ● ● IBindSumServiceImpl extends IBinderService.Stub and implements all methods in IBindSumService.aidl BindSumService extends Service and implements all Service callbacks: onCreate(), onBind(), onUnbind(), onDestroy()
    • AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.vkedco.mobappdev.bindsumservice" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <service android:name=".BindSumService"> <intent-filter> <action android:name="org.vkedco.mobappdev.bindsumlib.IBindSumService" /> </intent-filter> </service> </application> </manifest>
    • BindSumClient
    • GUI