Open up write API to external apps #317

Merged
merged 10 commits into from Jan 22, 2017

Projects

None yet

1 participant

@ianhanniballake
Collaborator

Allow third party apps to directly write source information updates and artwork into Muzei's ContentProvider from outside of their MuzeiArtSource. This means the com.google.android.apps.muzei.WRITE_PROVIDER permission is no longer a signature permission and third party apps can add it to their manifest and that the MuzeiProvider is completely hardened to only allow valid API usage.

Two new helper methods were created to facilitate this:

  • MuzeiContract.Artwork.createArtwork() which returns a Builder you can use the publish() artwork. Unlike the previous API which had Muzei loading a URI, this API loads URIs on the source side and also supports directly publishing a Bitmap or from any InputStream.
  • MuzeiContract.Sources.updateSource() which returns a Builder you can use to send() updated source information

This does not yet fully replace the MuzeiArtSource structure - each artwork is still associated with a MuzeiArtSource. However, this does allow developers to move away from using scheduleUpdate (as it is alarm based and cannot take into account network connectivity) and instead schedule jobs and write artwork directly in their JobService.

Example workflow that works with this structure:

  • In onEnabled(), schedule a repeated job to reload artwork
  • In onUpdate() with UPDATE_REASON_USER_NEXT, immediately load new artwork
  • In onDisabled(), cancel your repeated job

Note that while these APIs do support writing to multiple ContentProviders via their contentAuthorities() methods, the correct set of content authorities are not yet passed to the MuzeiArtSource, effectively meaning that these APIs only support updating Muzei itself.

ianhanniballake added some commits Dec 17, 2016
@ianhanniballake ianhanniballake Build the cache file name with the token if the imageUri is null
To allow deduplication of images without an imageUri, use the token as a backup unique attribute for artwork.
33d8599
@ianhanniballake ianhanniballake Move Meta Font Type constants to MuzeiContract
Tie Meta Font types to the META_FONT column in MuzeiContract
bba49c9
@ianhanniballake ianhanniballake Add static createArtwork() API to directly write artwork
Build a new fluent API that allows Muzei extension developers to write
artwork directly to Muzei's ContentProvider.

Note that this API does network requests on the extension side (blaming
the extension for data usage, rather than Muzei) immediately, rather than
doing it on the Muzei side at some unspecified time. This also allows
developers to use Bitmaps or an InputStream.
74d6909
@ianhanniballake ianhanniballake Add static updateSource() API to directly write source information
Builds a new fluent API that allows Muzei extension developers to update the source information directly in Muzei's ContentProvider.
88349ef
@ianhanniballake ianhanniballake Build the cache file name with the token if the imageUri is null
To allow deduplication of images without an imageUri, use the token as a backup unique attribute for artwork.
92108b4
@ianhanniballake ianhanniballake Move Meta Font Type constants to MuzeiContract
Tie Meta Font types to the META_FONT column in MuzeiContract
3236c8d
@ianhanniballake ianhanniballake Add static createArtwork() API to directly write artwork
Build a new fluent API that allows Muzei extension developers to write
artwork directly to Muzei's ContentProvider.

Note that this API does network requests on the extension side (blaming
the extension for data usage, rather than Muzei) immediately, rather than
doing it on the Muzei side at some unspecified time. This also allows
developers to use Bitmaps or an InputStream.
23df9d9
@ianhanniballake @ianhanniballake ianhanniballake Add static updateSource() API to directly write source information
Builds a new fluent API that allows Muzei extension developers to update the source information directly in Muzei's ContentProvider.
0d58ff5
@ianhanniballake ianhanniballake Allow third party apps to directly insert artwork and update their so…
…urce info

Make the WRITE_PROVIDER permission available to third party apps (rather than a signature permission) to allow apps to use the new createArtwork() and updateSource() methods directly.

Hardens the MuzeiProvider to prevent unsupported operations by third party apps:
- Only Muzei can delete artwork or sources
- Apps can only insert artwork associated with one of their MuzeiArtSources
- Only Muzei can insert sources
- Apps can only update their own source(s)
6134824
@ianhanniballake ianhanniballake Merge remote-tracking branch 'origin/api' into api 8287c7e
@ianhanniballake ianhanniballake merged commit 81d099c into romannurik:master Jan 22, 2017
@ianhanniballake ianhanniballake deleted the ianhanniballake:api branch Jan 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment