android aidl concept

20
Android AIDL Concept Charlie Tsai @ Android Study Group

Upload: charile-tsai

Post on 16-Apr-2017

368 views

Category:

Software


6 download

TRANSCRIPT

Page 1: Android AIDL Concept

Android AIDL ConceptCharlie Tsai @ Android Study Group

Page 2: Android AIDL Concept

Charlie Tsai @ Android Study [email protected]

Software Engineer

Page 3: Android AIDL Concept

Agenda

• Introduction of AIDL• Write your AIDL files• Implementation of AIDL

Page 4: Android AIDL Concept

Introduction of AIDL

Page 5: Android AIDL Concept

?AIDL?• Android Interface Definition Language• Main approach is IPC (Inter-Process

Communication)• Support types:

All primitive types, CharSequence & String, List & Map, Parcelable class

Page 6: Android AIDL Concept

IPC Issue

Memories of Process A

Process B of Process BX

Cannot Access(Memory protection

by Kernel)

Page 7: Android AIDL Concept

How AIDL solve IPC issue

Memories of Process A

Process B of Process B

Linux Kernel & Binder Driver

Access Access

Page 8: Android AIDL Concept

Write Your AIDL File• Write *.aidl for your AIDL interface• You can turn your Parcelable Class into

AIDL• Include if you use Other AIDL

class/interface• Note:

List will become ArrayList in another sideMap will become HashMap in another side(WHY?)

Page 9: Android AIDL Concept

AIDL Data StructureMyData.java

MyData.aidl

Page 10: Android AIDL Concept

AIDL InterfaceIMyAidlInterface.aidl

Page 11: Android AIDL Concept

How Parcelable Work

Page 12: Android AIDL Concept

Stringint

Data in memory(order is matter)

Page 13: Android AIDL Concept

Usages of AIDL

Page 14: Android AIDL Concept

Export Your ServiceAllow to be bound

by other App.

Page 15: Android AIDL Concept

Use Other’s ServiceCopy *.aidl file into your project

(Because you need to know this Interface)

Page 16: Android AIDL Concept

Generated File by AIDL

Page 17: Android AIDL Concept

• IInterface: Basic interface can be used for IPC• android.os.IBinder: Core class of IPC• Use YourInterface.asInterface(IBinder) to case

IBinder to YourInterface.• Use IBinder.queryLocalInterface() to know if this

IBinder is in local or remote.• If IBinder is in local, call function directly.• If IBinder is a remote object, use transact and

parcel to call function.

Let’s see the source code…

Page 18: Android AIDL Concept

Questions?

Page 19: Android AIDL Concept

固定聚會:每週三@果子咖啡 (近捷運南京復興站 )技術分享:每月底週六 14:30 - 17:30以及眾多不定期活動 (ex: Workshop)

Page 20: Android AIDL Concept

Thanks!