Slide 1

Slide 1 text

Android Plugin Architecture

Slide 2

Slide 2 text

Cross-app communication

Slide 3

Slide 3 text

Cross-app communication • Intent and BroadcastReceiver • ContentResolver and ContentProvider • Services
 …

Slide 4

Slide 4 text

Android Plugin Architecture

Slide 5

Slide 5 text

Android Plugin Architecture • Why? • User Plugin Discovery • Host App Plugin Discovery • Plugin Communication

Slide 6

Slide 6 text

App Examples

Slide 7

Slide 7 text

DashClock Widget

Slide 8

Slide 8 text

DashClock Widget

Slide 9

Slide 9 text

Muzei Live Wallpaper

Slide 10

Slide 10 text

Muzei Live Wallpaper

Slide 11

Slide 11 text

Why?

Slide 12

Slide 12 text

Ecosystem-based marketing • Don’t create all your own plugins • Open up an API to extend your app • Indirectly promoting your app

Slide 13

Slide 13 text

Business Model • Free app with basic functionality • Paid plugins

Slide 14

Slide 14 text

Permission Mitigation • Standard Android is all or nothing • People might not install your permission rich app • Provide core app with less permissions • User can choose permissions by installing plugins (Before Android 6)

Slide 15

Slide 15 text

User Plugin Discovery

Slide 16

Slide 16 text

User Plugin Discovery • Hardcode references in core app • Link to a search term on Play Store • Download a JSON • Use a WebView • …

Slide 17

Slide 17 text

App Plugin Discovery

Slide 18

Slide 18 text

BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Are there any plugins? Plugin app BroadcastReceiver

Slide 19

Slide 19 text

BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Yea, I’m a plugin! Plugin app BroadcastReceiver Yea, I’m a plugin!

Slide 20

Slide 20 text

BroadcastReceiver • Not recommended • It wakes up every plugin app • Not sure when every plugin app responded

Slide 21

Slide 21 text

PackageManager • Every plugin implements a custom intent action • PackageManager queries for every component using that custom action • Easily get metadata of that component

Slide 22

Slide 22 text

Package Broadcasts • Android system sends package broadcasts • Host app checks if we are interested
 in that package change • Host app can update a live list of plugins

Slide 23

Slide 23 text

Package Broadcasts Host app BroadcastReceiver ListView Android System App installs App replaces App deletes

Slide 24

Slide 24 text

Package Broadcasts Host app BroadcastReceiver ListView Android System App installs App replaces App deletes PACKAGE_ADDED
 PACKAGE_REPLACED PACKAGE_REMOVED

Slide 25

Slide 25 text

Package Broadcasts Host app ListView Android System App installs App replaces App deletes PACKAGE_ADDED
 PACKAGE_REPLACED PACKAGE_REMOVED Update

Slide 26

Slide 26 text

Plugin Communication

Slide 27

Slide 27 text

MetaData Great for getting static data • Plugin name • Plugin icon • Plugin api level

Slide 28

Slide 28 text

Coding Example MetaData Using resources from other app PackageManager manager = getPackageManager(); Resources pluginResources = manager.getResourcesForApplication("com.example.pluginapp"); int drawableResID = pluginResources.getIdentifier("app_icon", "drawable", "com.example.pluginapp"); Drawable drawable = pluginResources.getDrawable(drawableResID);

Slide 29

Slide 29 text

BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Provide me data

Slide 30

Slide 30 text

BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Here’s my data

Slide 31

Slide 31 text

Remote Service Binding • Preferred way • Remote services found with PackageManager • Communication protocol using AIDL • Callback with Messenger for delayed responses

Slide 32

Slide 32 text

Remote Service Binding - AIDL • All primitive types • int • long • char • … • String • Charsequence • List (ArrayList) • Map (HashMap) • Parcelable

Slide 33

Slide 33 text

Remote Service Binding Host app Plugin app AIDL Compile Stub Stub Build

Slide 34

Slide 34 text

Remote Service Binding Host app Plugin app Stub Stub Impl Impl Build

Slide 35

Slide 35 text

Remote Service Binding Host app Plugin app Stub Stub Impl Impl Bind Run

Slide 36

Slide 36 text

Remote Service Binding Host app Plugin app Stub Stub Impl Impl IPC Run

Slide 37

Slide 37 text

GUI Plugins

Slide 38

Slide 38 text

WebViews • Plugin provides data • Static URI using MetaData • Dynamic URI using IPC • Host has a WebView that loads the data • Easy • Not native • Security issues (javascript)

Slide 39

Slide 39 text

RemoteViews • Native • Homescreen widgets • Lockscreen widgets • Notifications • Only basic View Widgets • Parcelable!

Slide 40

Slide 40 text

Roll Your Own Parcelable • More flexible • A lot more work • Need to version your view building

Slide 41

Slide 41 text

Some extra tips

Slide 42

Slide 42 text

Some Extra Tips • Think about your versioning • Abstract to a library for distribution • Input validation in host • Make sure it’s secure • Don’t leak data
 →using signature level permissions

Slide 43

Slide 43 text

Questions? Siebe Sysmans Consultant at AppFoundry [email protected] @ThisIsSiebe