add detail button for insecure state in crypto info dialog

This commit is contained in:
Vincent Breitmoser 2017-04-29 15:18:59 +02:00
parent 524b074116
commit 4315621ad4
5 changed files with 49 additions and 16 deletions

View file

@ -130,6 +130,10 @@ public final class CryptoResultAnnotation {
return openPgpPendingIntent; return openPgpPendingIntent;
} }
public boolean hasOpenPgpInsecureWarningPendingIntent() {
return openPgpInsecureWarningPendingIntent != null;
}
@Nullable @Nullable
public PendingIntent getOpenPgpInsecureWarningPendingIntent() { public PendingIntent getOpenPgpInsecureWarningPendingIntent() {
return openPgpInsecureWarningPendingIntent; return openPgpInsecureWarningPendingIntent;
@ -171,7 +175,6 @@ public final class CryptoResultAnnotation {
return encapsulatedResult; return encapsulatedResult;
} }
public enum CryptoError { public enum CryptoError {
OPENPGP_OK, OPENPGP_OK,
OPENPGP_UI_CANCELED, OPENPGP_UI_CANCELED,

View file

@ -28,6 +28,7 @@ import com.fsck.k9.view.ThemeUtils;
public class CryptoInfoDialog extends DialogFragment { public class CryptoInfoDialog extends DialogFragment {
public static final String ARG_DISPLAY_STATUS = "display_status"; public static final String ARG_DISPLAY_STATUS = "display_status";
public static final String ARG_HAS_SECURITY_WARNING = "has_security_warning";
public static final int ICON_ANIM_DELAY = 400; public static final int ICON_ANIM_DELAY = 400;
public static final int ICON_ANIM_DURATION = 350; public static final int ICON_ANIM_DURATION = 350;
@ -46,11 +47,12 @@ public class CryptoInfoDialog extends DialogFragment {
private TextView bottomText; private TextView bottomText;
public static CryptoInfoDialog newInstance(MessageCryptoDisplayStatus displayStatus) { public static CryptoInfoDialog newInstance(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning) {
CryptoInfoDialog frag = new CryptoInfoDialog(); CryptoInfoDialog frag = new CryptoInfoDialog();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ARG_DISPLAY_STATUS, displayStatus.toString()); args.putString(ARG_DISPLAY_STATUS, displayStatus.toString());
args.putBoolean(ARG_HAS_SECURITY_WARNING, hasSecurityWarning);
frag.setArguments(args); frag.setArguments(args);
return frag; return frag;
@ -85,7 +87,19 @@ public class CryptoInfoDialog extends DialogFragment {
dismiss(); dismiss();
} }
}); });
if (displayStatus.hasAssociatedKey()) { boolean hasSecurityWarning = getArguments().getBoolean(ARG_HAS_SECURITY_WARNING);
if (hasSecurityWarning) {
b.setNeutralButton(R.string.crypto_info_view_security_warning, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Fragment frag = getTargetFragment();
if (! (frag instanceof OnClickShowCryptoKeyListener)) {
throw new AssertionError("Displaying activity must implement OnClickShowCryptoKeyListener!");
}
((OnClickShowCryptoKeyListener) frag).onClickShowSecurityWarning();
}
});
} else if (displayStatus.hasAssociatedKey()) {
b.setNeutralButton(R.string.crypto_info_view_key, new OnClickListener() { b.setNeutralButton(R.string.crypto_info_view_key, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
@ -190,5 +204,6 @@ public class CryptoInfoDialog extends DialogFragment {
public interface OnClickShowCryptoKeyListener { public interface OnClickShowCryptoKeyListener {
void onClickShowCryptoKey(); void onClickShowCryptoKey();
void onClickShowSecurityWarning();
} }
} }

View file

@ -24,6 +24,7 @@ import timber.log.Timber;
public class MessageCryptoPresenter implements OnCryptoClickListener { public class MessageCryptoPresenter implements OnCryptoClickListener {
public static final int REQUEST_CODE_UNKNOWN_KEY = 123; public static final int REQUEST_CODE_UNKNOWN_KEY = 123;
public static final int REQUEST_CODE_SECURITY_WARNING = 124;
// injected state // injected state
@ -161,7 +162,7 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
return; return;
} }
Drawable providerIcon = getOpenPgpApiProviderIcon(messageView.getContext()); Drawable providerIcon = getOpenPgpApiProviderIcon(messageView.getContext());
boolean showDetailButton = cryptoResultAnnotation.getOpenPgpInsecureWarningPendingIntent() != null; boolean showDetailButton = cryptoResultAnnotation.hasOpenPgpInsecureWarningPendingIntent();
messageView.showMessageCryptoWarning(messageViewInfo, providerIcon, warningStringRes, showDetailButton); messageView.showMessageCryptoWarning(messageViewInfo, providerIcon, warningStringRes, showDetailButton);
} }
@ -187,19 +188,27 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
@SuppressWarnings("UnusedParameters") // for consistency with Activity.onActivityResult @SuppressWarnings("UnusedParameters") // for consistency with Activity.onActivityResult
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != REQUEST_CODE_UNKNOWN_KEY) { if (requestCode == REQUEST_CODE_UNKNOWN_KEY) {
if (resultCode != Activity.RESULT_OK) {
return;
}
messageCryptoMvpView.restartMessageCryptoProcessing();
} else if (requestCode == REQUEST_CODE_SECURITY_WARNING) {
if (overrideCryptoWarning || resultCode != Activity.RESULT_OK) {
return;
}
overrideCryptoWarning = true;
messageCryptoMvpView.redisplayMessage();
} else {
throw new IllegalStateException("got an activity result that wasn't meant for us. this is a bug!"); throw new IllegalStateException("got an activity result that wasn't meant for us. this is a bug!");
} }
if (resultCode != Activity.RESULT_OK) {
return;
}
messageCryptoMvpView.restartMessageCryptoProcessing();
} }
private void displayCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus) { private void displayCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus) {
messageCryptoMvpView.showCryptoInfoDialog(displayStatus); messageCryptoMvpView.showCryptoInfoDialog(
displayStatus, cryptoResultAnnotation.hasOpenPgpInsecureWarningPendingIntent());
} }
private void launchPendingIntent(CryptoResultAnnotation cryptoResultAnnotation) { private void launchPendingIntent(CryptoResultAnnotation cryptoResultAnnotation) {
@ -240,7 +249,7 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
PendingIntent pendingIntent = cryptoResultAnnotation.getOpenPgpInsecureWarningPendingIntent(); PendingIntent pendingIntent = cryptoResultAnnotation.getOpenPgpInsecureWarningPendingIntent();
if (pendingIntent != null) { if (pendingIntent != null) {
messageCryptoMvpView.startPendingIntentForCryptoPresenter( messageCryptoMvpView.startPendingIntentForCryptoPresenter(
pendingIntent.getIntentSender(), null, null, 0, 0, 0); pendingIntent.getIntentSender(), REQUEST_CODE_SECURITY_WARNING, null, 0, 0, 0);
} }
} catch (IntentSender.SendIntentException e) { } catch (IntentSender.SendIntentException e) {
Timber.e(e, "SendIntentException"); Timber.e(e, "SendIntentException");
@ -279,7 +288,7 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
void startPendingIntentForCryptoPresenter(IntentSender si, Integer requestCode, Intent fillIntent, void startPendingIntentForCryptoPresenter(IntentSender si, Integer requestCode, Intent fillIntent,
int flagsMask, int flagValues, int extraFlags) throws IntentSender.SendIntentException; int flagsMask, int flagValues, int extraFlags) throws IntentSender.SendIntentException;
void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus); void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning);
void showCryptoConfigDialog(); void showCryptoConfigDialog();
} }
} }

View file

@ -689,8 +689,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
} }
@Override @Override
public void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus) { public void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning) {
CryptoInfoDialog dialog = CryptoInfoDialog.newInstance(displayStatus); CryptoInfoDialog dialog = CryptoInfoDialog.newInstance(displayStatus, hasSecurityWarning);
dialog.setTargetFragment(MessageViewFragment.this, 0); dialog.setTargetFragment(MessageViewFragment.this, 0);
dialog.show(getFragmentManager(), "crypto_info_dialog"); dialog.show(getFragmentManager(), "crypto_info_dialog");
} }
@ -707,6 +707,11 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
} }
}; };
@Override
public void onClickShowSecurityWarning() {
messageCryptoPresenter.onClickShowCryptoWarningDetails();
}
@Override @Override
public void onClickShowCryptoKey() { public void onClickShowCryptoKey() {
messageCryptoPresenter.onClickShowCryptoKey(); messageCryptoPresenter.onClickShowCryptoKey();

View file

@ -1194,6 +1194,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="crypto_info_ok">OK</string> <string name="crypto_info_ok">OK</string>
<string name="crypto_info_view_key">View Signer</string> <string name="crypto_info_view_key">View Signer</string>
<string name="crypto_info_view_security_warning">Details</string>
<string name="locked_attach_unlock">Unlock</string> <string name="locked_attach_unlock">Unlock</string>
<string name="locked_attach_unencrypted">This part was not encrypted, and may be insecure.</string> <string name="locked_attach_unencrypted">This part was not encrypted, and may be insecure.</string>
<string name="locked_attach_title">Unprotected Attachment</string> <string name="locked_attach_title">Unprotected Attachment</string>