From 132ede425b9c8e64c04c80be67ec89f0f8bc96b0 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 17 Feb 2015 20:17:34 +0100 Subject: [PATCH] Make it easier to check if a crypto provider is configured --- k9mail/src/main/java/com/fsck/k9/Account.java | 16 ++++++++++++---- .../com/fsck/k9/activity/MessageCompose.java | 6 +++--- .../fsck/k9/ui/crypto/MessageCryptoHelper.java | 6 +----- .../fsck/k9/ui/messageview/MessageTopView.java | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/Account.java b/k9mail/src/main/java/com/fsck/k9/Account.java index b75932e54..a2be9033a 100644 --- a/k9mail/src/main/java/com/fsck/k9/Account.java +++ b/k9mail/src/main/java/com/fsck/k9/Account.java @@ -466,7 +466,8 @@ public class Account implements BaseAccount, StoreConfig { mIsSignatureBeforeQuotedText = prefs.getBoolean(mUuid + ".signatureBeforeQuotedText", false); identities = loadIdentities(prefs); - mCryptoApp = prefs.getString(mUuid + ".cryptoApp", NO_OPENPGP_PROVIDER); + String cryptoApp = prefs.getString(mUuid + ".cryptoApp", NO_OPENPGP_PROVIDER); + setCryptoApp(cryptoApp); mAllowRemoteSearch = prefs.getBoolean(mUuid + ".allowRemoteSearch", false); mRemoteSearchFullText = prefs.getBoolean(mUuid + ".remoteSearchFullText", false); mRemoteSearchNumResults = prefs.getInt(mUuid + ".remoteSearchNumResults", DEFAULT_REMOTE_SEARCH_NUM_RESULTS); @@ -1615,7 +1616,11 @@ public class Account implements BaseAccount, StoreConfig { } public void setCryptoApp(String cryptoApp) { - mCryptoApp = cryptoApp; + if (cryptoApp == null || cryptoApp.equals("apg")) { + mCryptoApp = NO_OPENPGP_PROVIDER; + } else { + mCryptoApp = cryptoApp; + } } public boolean allowRemoteSearch() { @@ -1659,13 +1664,16 @@ public class Account implements BaseAccount, StoreConfig { } public synchronized String getOpenPgpProvider() { - // return null if set to "APG" or "None" - if (getCryptoApp().equals("apg") || getCryptoApp().equals("")) { + if (!isOpenPgpProviderConfigured()) { return null; } return getCryptoApp(); } + public synchronized boolean isOpenPgpProviderConfigured() { + return !NO_OPENPGP_PROVIDER.equals(getCryptoApp()); + } + public synchronized NotificationSetting getNotificationSetting() { return mNotificationSetting; } diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java index 35ee62aa0..d05ae7e0e 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java @@ -764,7 +764,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, initializeCrypto(); mOpenPgpProvider = mAccount.getOpenPgpProvider(); - if (mOpenPgpProvider != null) { + if (isCryptoProviderEnabled()) { mCryptoSignatureCheckbox = (CheckBox)findViewById(R.id.cb_crypto_signature); final OnCheckedChangeListener updateListener = new OnCheckedChangeListener() { @Override @@ -1682,7 +1682,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } private void performSend() { - if (mOpenPgpProvider != null) { + if (isCryptoProviderEnabled()) { // OpenPGP Provider API // If not already encrypted but user wants to encrypt... @@ -1894,7 +1894,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, */ @SuppressLint("InlinedApi") private void onAddAttachment2(final String mime_type) { - if (mAccount.getOpenPgpProvider() != null) { + if (isCryptoProviderEnabled()) { Toast.makeText(this, R.string.attachment_encryption_unsupported, Toast.LENGTH_LONG).show(); } Intent i = new Intent(Intent.ACTION_GET_CONTENT); diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java index 0f2468ba8..bb09a164d 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java @@ -76,7 +76,7 @@ public class MessageCryptoHelper { public void decryptOrVerifyMessagePartsIfNecessary(LocalMessage message) { this.message = message; - if (!isCryptoProviderConfigured()) { + if (!account.isOpenPgpProviderConfigured()) { returnResultToFragment(); return; } @@ -95,10 +95,6 @@ public class MessageCryptoHelper { } } - private boolean isCryptoProviderConfigured() { - return !TextUtils.isEmpty(account.getCryptoApp()); - } - private void decryptOrVerifyNextPart() { if (partsToDecryptOrVerify.isEmpty()) { returnResultToFragment(); diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageTopView.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageTopView.java index 70362c097..f0ca38065 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageTopView.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageTopView.java @@ -88,7 +88,7 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll for (MessageViewContainer container : messageViewInfo.containers) { MessageContainerView view = (MessageContainerView) mInflater.inflate(R.layout.message_container, null); - boolean displayPgpHeader = !Account.NO_OPENPGP_PROVIDER.equals(account.getOpenPgpProvider()); + boolean displayPgpHeader = account.isOpenPgpProviderConfigured(); view.displayMessageViewContainer(container, automaticallyLoadPictures, this, attachmentCallback, openPgpHeaderViewCallback, displayPgpHeader);