Cross-app communication and plugin architecture in Android

103e1ebcacd620770cf32a36b9aba17e?s=47 AppFoundry
March 08, 2016

Cross-app communication and plugin architecture in Android

A presentation by Siebe Sysmans.
This presentation was given for Mobel (http://www.mobel.io) and IT students.
Code: https://github.com/appfoundry/AndroidPluginArchitecture

103e1ebcacd620770cf32a36b9aba17e?s=128

AppFoundry

March 08, 2016
Tweet

Transcript

  1. Android Plugin Architecture

  2. Cross-app communication

  3. Cross-app communication • Intent and BroadcastReceiver • ContentResolver and ContentProvider

    • Services
 …
  4. Android Plugin Architecture

  5. Android Plugin Architecture • Why? • User Plugin Discovery •

    Host App Plugin Discovery • Plugin Communication
  6. App Examples

  7. DashClock Widget

  8. DashClock Widget

  9. Muzei Live Wallpaper

  10. Muzei Live Wallpaper

  11. Why?

  12. Ecosystem-based marketing • Don’t create all your own plugins •

    Open up an API to extend your app • Indirectly promoting your app
  13. Business Model • Free app with basic functionality • Paid

    plugins
  14. 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)
  15. User Plugin Discovery

  16. User Plugin Discovery • Hardcode references in core app •

    Link to a search term on Play Store • Download a JSON • Use a WebView • …
  17. App Plugin Discovery

  18. BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Are there any

    plugins? Plugin app BroadcastReceiver
  19. BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Yea, I’m a

    plugin! Plugin app BroadcastReceiver Yea, I’m a plugin!
  20. BroadcastReceiver • Not recommended • It wakes up every plugin

    app • Not sure when every plugin app responded
  21. PackageManager • Every plugin implements a custom intent action •

    PackageManager queries for every component using that custom action • Easily get metadata of that component
  22. 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
  23. Package Broadcasts Host app BroadcastReceiver ListView Android System App installs

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

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

    replaces App deletes PACKAGE_ADDED
 PACKAGE_REPLACED PACKAGE_REMOVED Update
  26. Plugin Communication

  27. MetaData Great for getting static data • Plugin name •

    Plugin icon • Plugin api level
  28. 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);
  29. BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Provide me data

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

  31. Remote Service Binding • Preferred way • Remote services found

    with PackageManager • Communication protocol using AIDL • Callback with Messenger for delayed responses
  32. Remote Service Binding - AIDL • All primitive types •

    int • long • char • … • String • Charsequence • List (ArrayList) • Map (HashMap) • Parcelable
  33. Remote Service Binding Host app Plugin app AIDL Compile Stub

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

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

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

    Impl IPC Run
  37. GUI Plugins

  38. 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)
  39. RemoteViews • Native • Homescreen widgets • Lockscreen widgets •

    Notifications • Only basic View Widgets • Parcelable!
  40. Roll Your Own Parcelable • More flexible • A lot

    more work • Need to version your view building
  41. Some extra tips

  42. 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
  43. Questions? Siebe Sysmans Consultant at AppFoundry siebe.sysmans@appfoundry.be @ThisIsSiebe