Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cross-app communication and plugin architecture in Android

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


March 08, 2016

More Decks by AppFoundry

Other Decks in Technology


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

    Host App Plugin Discovery • Plugin Communication
  2. Ecosystem-based marketing • Don’t create all your own plugins •

    Open up an API to extend your app • Indirectly promoting your app
  3. 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)
  4. User Plugin Discovery • Hardcode references in core app •

    Link to a search term on Play Store • Download a JSON • Use a WebView • …
  5. BroadcastReceiver Host app Plugin app BroadcastReceiver BroadcastReceiver Yea, I’m a

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

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

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

    App replaces App deletes PACKAGE_ADDED
  10. Package Broadcasts Host app ListView Android System App installs App

    replaces App deletes PACKAGE_ADDED
  11. 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);
  12. Remote Service Binding • Preferred way • Remote services found

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

    int • long • char • … • String • Charsequence • List (ArrayList) • Map (HashMap) • Parcelable
  14. 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)
  15. RemoteViews • Native • Homescreen widgets • Lockscreen widgets •

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

    more work • Need to version your view building
  17. 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