add screen to display when no crypto provider is configured

This commit is contained in:
Vincent Breitmoser 2017-02-01 23:01:41 +01:00
parent 8ee9b2c591
commit e2186058bc
7 changed files with 83 additions and 8 deletions

View file

@ -159,5 +159,6 @@ public final class CryptoResultAnnotation {
OPENPGP_ENCRYPTED_BUT_INCOMPLETE, OPENPGP_ENCRYPTED_BUT_INCOMPLETE,
SIGNED_BUT_UNSUPPORTED, SIGNED_BUT_UNSUPPORTED,
ENCRYPTED_BUT_UNSUPPORTED, ENCRYPTED_BUT_UNSUPPORTED,
OPENPGP_ENCRYPTED_NO_PROVIDER,
} }
} }

View file

@ -12,6 +12,7 @@ import com.fsck.k9.crypto.MessageDecryptVerifier;
import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Part; import com.fsck.k9.mail.Part;
import com.fsck.k9.mailstore.CryptoResultAnnotation; import com.fsck.k9.mailstore.CryptoResultAnnotation;
import com.fsck.k9.mailstore.CryptoResultAnnotation.CryptoError;
public class MessageCryptoSplitter { public class MessageCryptoSplitter {
@ -19,20 +20,21 @@ public class MessageCryptoSplitter {
@Nullable @Nullable
public static CryptoMessageParts split(@NonNull Message message, @Nullable MessageCryptoAnnotations annotations) { public static CryptoMessageParts split(@NonNull Message message, @Nullable MessageCryptoAnnotations annotations) {
if (annotations == null) { ArrayList<Part> extraParts = new ArrayList<>();
Part primaryPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, extraParts);
if (primaryPart == null) {
return null; return null;
} }
ArrayList<Part> extraParts = new ArrayList<>(); if (annotations == null) {
Part primaryPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, extraParts); CryptoResultAnnotation rootPartAnnotation =
CryptoResultAnnotation.createErrorAnnotation(CryptoError.OPENPGP_ENCRYPTED_NO_PROVIDER, null);
if (!annotations.has(primaryPart)) { return new CryptoMessageParts(primaryPart, rootPartAnnotation, extraParts);
return null;
} }
CryptoResultAnnotation rootPartAnnotation = annotations.get(primaryPart); CryptoResultAnnotation rootPartAnnotation = annotations.get(primaryPart);
Part rootPart; Part rootPart;
if (rootPartAnnotation.hasReplacementData()) { if (rootPartAnnotation != null && rootPartAnnotation.hasReplacementData()) {
rootPart = rootPartAnnotation.getReplacementData(); rootPart = rootPartAnnotation.getReplacementData();
} else { } else {
rootPart = primaryPart; rootPart = primaryPart;
@ -43,11 +45,12 @@ public class MessageCryptoSplitter {
public static class CryptoMessageParts { public static class CryptoMessageParts {
public final Part contentPart; public final Part contentPart;
@Nullable
public final CryptoResultAnnotation contentCryptoAnnotation; public final CryptoResultAnnotation contentCryptoAnnotation;
public final List<Part> extraParts; public final List<Part> extraParts;
CryptoMessageParts(Part contentPart, CryptoResultAnnotation contentCryptoAnnotation, List<Part> extraParts) { CryptoMessageParts(Part contentPart, @Nullable CryptoResultAnnotation contentCryptoAnnotation, List<Part> extraParts) {
this.contentPart = contentPart; this.contentPart = contentPart;
this.contentCryptoAnnotation = contentCryptoAnnotation; this.contentCryptoAnnotation = contentCryptoAnnotation;
this.extraParts = Collections.unmodifiableList(extraParts); this.extraParts = Collections.unmodifiableList(extraParts);

View file

@ -116,6 +116,11 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
break; break;
} }
case ENCRYPTED_NO_PROVIDER: {
messageView.showNoCryptoProviderConfigured(messageViewInfo);
break;
}
case INCOMPLETE_SIGNED: case INCOMPLETE_SIGNED:
case UNSUPPORTED_SIGNED: case UNSUPPORTED_SIGNED:
default: { default: {

View file

@ -189,6 +189,21 @@ public class MessageTopView extends LinearLayout {
displayViewOnLoadFinished(false); displayViewOnLoadFinished(false);
} }
public void showNoCryptoProviderConfigured(MessageViewInfo messageViewInfo) {
resetAndPrepareMessageView(messageViewInfo);
View view = mInflater.inflate(R.layout.message_content_crypto_no_provider, containerView, false);
view.findViewById(R.id.crypto_settings).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO
}
});
containerView.addView(view);
displayViewOnLoadFinished(false);
}
private void setCryptoProviderIcon(Drawable openPgpApiProviderIcon, View view) { private void setCryptoProviderIcon(Drawable openPgpApiProviderIcon, View view) {
ImageView cryptoProviderIcon = (ImageView) view.findViewById(R.id.crypto_error_icon); ImageView cryptoProviderIcon = (ImageView) view.findViewById(R.id.crypto_error_icon);
if (openPgpApiProviderIcon != null) { if (openPgpApiProviderIcon != null) {

View file

@ -136,6 +136,12 @@ public enum MessageCryptoDisplayStatus {
R.string.crypto_msg_signed_unencrypted, R.string.crypto_msg_sign_incomplete R.string.crypto_msg_signed_unencrypted, R.string.crypto_msg_sign_incomplete
), ),
ENCRYPTED_NO_PROVIDER (
R.attr.openpgp_red,
R.drawable.status_lock_error,
R.string.crypto_msg_unsupported_encrypted
),
UNSUPPORTED_ENCRYPTED ( UNSUPPORTED_ENCRYPTED (
R.attr.openpgp_red, R.attr.openpgp_red,
R.drawable.status_lock_error, R.drawable.status_lock_error,
@ -214,6 +220,9 @@ public enum MessageCryptoDisplayStatus {
case OPENPGP_ENCRYPTED_API_ERROR: case OPENPGP_ENCRYPTED_API_ERROR:
return ENCRYPTED_ERROR; return ENCRYPTED_ERROR;
case OPENPGP_ENCRYPTED_NO_PROVIDER:
return ENCRYPTED_NO_PROVIDER;
} }
throw new IllegalStateException("Unhandled case!"); throw new IllegalStateException("Unhandled case!");
} }

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:id="@+id/crypto_error_title"
android:textAppearance="?android:textAppearanceMedium"
android:text="@string/crypto_no_provider_title"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="@string/crypto_no_provider_message"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/crypto_settings"
android:text="@string/crypto_no_provider_button"
/>
</LinearLayout>

View file

@ -1163,6 +1163,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="crypto_msg_encrypted_error">Message is encrypted, but there was a decryption error.</string> <string name="crypto_msg_encrypted_error">Message is encrypted, but there was a decryption error.</string>
<string name="crypto_msg_signed_error">Message is signed, but the signature could not be verified.</string> <string name="crypto_msg_signed_error">Message is signed, but the signature could not be verified.</string>
<string name="crypto_msg_encrypted_no_provider">Message is encrypted, but no crypto app is configured.</string>
<string name="crypto_msg_unsupported_encrypted">Message is encrypted, but in an unsupported format.</string> <string name="crypto_msg_unsupported_encrypted">Message is encrypted, but in an unsupported format.</string>
<string name="crypto_msg_unsupported_signed">Message is signed, but in an unsupported format.</string> <string name="crypto_msg_unsupported_signed">Message is signed, but in an unsupported format.</string>
<string name="crypto_msg_incomplete_encrypted">Message is encrypted, but must be fully downloaded for decryption.</string> <string name="crypto_msg_incomplete_encrypted">Message is encrypted, but must be fully downloaded for decryption.</string>
@ -1217,5 +1218,8 @@ Please submit bug reports, contribute new features and ask questions at
<string name="apg_deprecated_ok">Got it!</string> <string name="apg_deprecated_ok">Got it!</string>
<string name="apg">APG</string> <string name="apg">APG</string>
<string name="no_crypto_provider_see_global">No OpenPGP app configured, see global settings!</string> <string name="no_crypto_provider_see_global">No OpenPGP app configured, see global settings!</string>
<string name="crypto_no_provider_title">This email is encrypted</string>
<string name="crypto_no_provider_message">This email has been encrypted with OpenPGP.\nTo read it, you need to install and configure a compatible OpenPGP App.</string>
<string name="crypto_no_provider_button">Choose OpenPGP App</string>
</resources> </resources>