add detail button for insecure state in crypto info dialog
This commit is contained in:
parent
524b074116
commit
4315621ad4
5 changed files with 49 additions and 16 deletions
|
@ -130,6 +130,10 @@ public final class CryptoResultAnnotation {
|
|||
return openPgpPendingIntent;
|
||||
}
|
||||
|
||||
public boolean hasOpenPgpInsecureWarningPendingIntent() {
|
||||
return openPgpInsecureWarningPendingIntent != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PendingIntent getOpenPgpInsecureWarningPendingIntent() {
|
||||
return openPgpInsecureWarningPendingIntent;
|
||||
|
@ -171,7 +175,6 @@ public final class CryptoResultAnnotation {
|
|||
return encapsulatedResult;
|
||||
}
|
||||
|
||||
|
||||
public enum CryptoError {
|
||||
OPENPGP_OK,
|
||||
OPENPGP_UI_CANCELED,
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.fsck.k9.view.ThemeUtils;
|
|||
|
||||
public class CryptoInfoDialog extends DialogFragment {
|
||||
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_DURATION = 350;
|
||||
|
||||
|
@ -46,11 +47,12 @@ public class CryptoInfoDialog extends DialogFragment {
|
|||
private TextView bottomText;
|
||||
|
||||
|
||||
public static CryptoInfoDialog newInstance(MessageCryptoDisplayStatus displayStatus) {
|
||||
public static CryptoInfoDialog newInstance(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning) {
|
||||
CryptoInfoDialog frag = new CryptoInfoDialog();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_DISPLAY_STATUS, displayStatus.toString());
|
||||
args.putBoolean(ARG_HAS_SECURITY_WARNING, hasSecurityWarning);
|
||||
frag.setArguments(args);
|
||||
|
||||
return frag;
|
||||
|
@ -85,7 +87,19 @@ public class CryptoInfoDialog extends DialogFragment {
|
|||
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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
|
@ -190,5 +204,6 @@ public class CryptoInfoDialog extends DialogFragment {
|
|||
|
||||
public interface OnClickShowCryptoKeyListener {
|
||||
void onClickShowCryptoKey();
|
||||
void onClickShowSecurityWarning();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import timber.log.Timber;
|
|||
|
||||
public class MessageCryptoPresenter implements OnCryptoClickListener {
|
||||
public static final int REQUEST_CODE_UNKNOWN_KEY = 123;
|
||||
public static final int REQUEST_CODE_SECURITY_WARNING = 124;
|
||||
|
||||
|
||||
// injected state
|
||||
|
@ -161,7 +162,7 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
|
|||
return;
|
||||
}
|
||||
Drawable providerIcon = getOpenPgpApiProviderIcon(messageView.getContext());
|
||||
boolean showDetailButton = cryptoResultAnnotation.getOpenPgpInsecureWarningPendingIntent() != null;
|
||||
boolean showDetailButton = cryptoResultAnnotation.hasOpenPgpInsecureWarningPendingIntent();
|
||||
messageView.showMessageCryptoWarning(messageViewInfo, providerIcon, warningStringRes, showDetailButton);
|
||||
}
|
||||
|
||||
|
@ -187,19 +188,27 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
|
|||
|
||||
@SuppressWarnings("UnusedParameters") // for consistency with Activity.onActivityResult
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode != REQUEST_CODE_UNKNOWN_KEY) {
|
||||
throw new IllegalStateException("got an activity result that wasn't meant for us. this is a bug!");
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
private void displayCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus) {
|
||||
messageCryptoMvpView.showCryptoInfoDialog(displayStatus);
|
||||
messageCryptoMvpView.showCryptoInfoDialog(
|
||||
displayStatus, cryptoResultAnnotation.hasOpenPgpInsecureWarningPendingIntent());
|
||||
}
|
||||
|
||||
private void launchPendingIntent(CryptoResultAnnotation cryptoResultAnnotation) {
|
||||
|
@ -240,7 +249,7 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
|
|||
PendingIntent pendingIntent = cryptoResultAnnotation.getOpenPgpInsecureWarningPendingIntent();
|
||||
if (pendingIntent != null) {
|
||||
messageCryptoMvpView.startPendingIntentForCryptoPresenter(
|
||||
pendingIntent.getIntentSender(), null, null, 0, 0, 0);
|
||||
pendingIntent.getIntentSender(), REQUEST_CODE_SECURITY_WARNING, null, 0, 0, 0);
|
||||
}
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
Timber.e(e, "SendIntentException");
|
||||
|
@ -279,7 +288,7 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
|
|||
void startPendingIntentForCryptoPresenter(IntentSender si, Integer requestCode, Intent fillIntent,
|
||||
int flagsMask, int flagValues, int extraFlags) throws IntentSender.SendIntentException;
|
||||
|
||||
void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus);
|
||||
void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning);
|
||||
void showCryptoConfigDialog();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -689,8 +689,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||
}
|
||||
|
||||
@Override
|
||||
public void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus) {
|
||||
CryptoInfoDialog dialog = CryptoInfoDialog.newInstance(displayStatus);
|
||||
public void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning) {
|
||||
CryptoInfoDialog dialog = CryptoInfoDialog.newInstance(displayStatus, hasSecurityWarning);
|
||||
dialog.setTargetFragment(MessageViewFragment.this, 0);
|
||||
dialog.show(getFragmentManager(), "crypto_info_dialog");
|
||||
}
|
||||
|
@ -707,6 +707,11 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onClickShowSecurityWarning() {
|
||||
messageCryptoPresenter.onClickShowCryptoWarningDetails();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickShowCryptoKey() {
|
||||
messageCryptoPresenter.onClickShowCryptoKey();
|
||||
|
|
|
@ -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_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_unencrypted">This part was not encrypted, and may be insecure.</string>
|
||||
<string name="locked_attach_title">Unprotected Attachment</string>
|
||||
|
|
Loading…
Reference in a new issue