k9mail/k-9 — pull request #457 by dschuermann (2014-03-02 17:41:35+00:00)
Title: OpenPGP Provider API 2

Here we go again :)

To try this pull request, you need either a self-compiled [OpenKeychain](https://github.com/openpgp-keychain/openpgp-keychain) from the current git master or install Beta from Google Play:
1. Join [beta tester group on Google+](https://plus.google.com/communities/100667924987940385351)
2. Visit [this special Google Play link](https://play.google.com/apps/testing/org.sufficientlysecure.keychain)
3. Install the beta OpenKeychain (it mus be version "2.3.1 beta1", should be available soon)

Many shortcomings of the old API approach has been improved after discussion with @cketti and Guardianproject. This is the first version of an K9-Mail integration of this new API. I really really like to get this accepted as fast as possible, even when some features are still lacking. Due to the current design it should be easy to add them at a later point to K9-Mail and OpenKeychain.

Main improvements:
* An [API library](https://github.com/openpgp-keychain/openpgp-keychain/blob/master/OpenPGP-Keychain-API/libraries/keychain-api-library/) makes integration more easy
* New API uses streams over ParcelableFileDescriptors (thanks to Abel Luck for testing the possibilities)
* Very small [AIDL finterface](https://github.com/openpgp-keychain/openpgp-keychain/blob/master/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/IOpenPgpService.aidl)
* This has the advantage that feature changes to the API do not require to change the AIDL interface. Thus the API version checking is also implemented as an error code coming from this one method
* The whole API is much more Intent based. You [define intents like seen in the example-app's code](https://github.com/openpgp-keychain/openpgp-keychain/blob/master/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java#L213). Internally this Intent is send through the AIDL interface and then used on the other side.
* If user interaction is required, the Activities are NOT started from OpenKeychain's background service (thanks to cketti for all information about this). Instead I return PendingIntents, which are then executed by the client application. This has my advantages: 1) The Activity is put on the right android task stack. 2) If the client gets back an PendingIntent and no result, the client itself can decide when to execute this PendingIntent, so the client app can control when user interaction should be shown. The handling can be seen in the [example-app's code](https://github.com/openpgp-keychain/openpgp-keychain/blob/master/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java#L171).