service: slightly clearer code for backwards compatibility

This commit is contained in:
Vincent Breitmoser
2016-06-02 17:21:07 +02:00
parent cb11c0ec84
commit 594d1686c9
2 changed files with 10 additions and 19 deletions

View File

@@ -557,30 +557,21 @@ public class OpenPgpService extends Service {
if (signatureResult.getResult() == OpenPgpSignatureResult.RESULT_NO_SIGNATURE) { if (signatureResult.getResult() == OpenPgpSignatureResult.RESULT_NO_SIGNATURE) {
result.putExtra(OpenPgpApi.RESULT_SIGNATURE, (Parcelable[]) null); result.putExtra(OpenPgpApi.RESULT_SIGNATURE, (Parcelable[]) null);
} }
// OpenPgpDecryptionResult does not exist in API < 8
{
OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult();
// case RESULT_NOT_ENCRYPTED, but a signature, fallback to deprecated signatureOnly variable
if (decryptionResult.getResult() == OpenPgpDecryptionResult.RESULT_NOT_ENCRYPTED
&& signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE) {
// noinspection deprecation
signatureResult = signatureResult.withSignatureOnlyFlag();
}
// case RESULT_INSECURE, simply accept as a fallback like in previous API versions
// case RESULT_ENCRYPTED
// nothing to do!
}
} }
if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) >= 8) { boolean apiHasOpenPgpDecryptionResult = data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) >= 8;
if (apiHasOpenPgpDecryptionResult) {
OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult(); OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult();
if (decryptionResult != null) { if (decryptionResult != null) {
result.putExtra(OpenPgpApi.RESULT_DECRYPTION, decryptionResult); result.putExtra(OpenPgpApi.RESULT_DECRYPTION, decryptionResult);
} }
} else {
// this info was kept in OpenPgpSignatureResult, so put it there for compatibility
OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult();
boolean signatureOnly = decryptionResult.getResult() == OpenPgpDecryptionResult.RESULT_NOT_ENCRYPTED
&& signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE;
// noinspection deprecation, this is for backwards compatibility
signatureResult = signatureResult.withSignatureOnlyFlag(signatureOnly);
} }
OpenPgpMetadata metadata = pgpResult.getDecryptionMetadata(); OpenPgpMetadata metadata = pgpResult.getDecryptionMetadata();