autocrypt status, and enable/disable on crypto status icon click

This commit is contained in:
Vincent Breitmoser 2017-06-22 15:41:49 +02:00
parent d8f7b8308b
commit ae519a071b
9 changed files with 175 additions and 239 deletions

View file

@ -27,10 +27,6 @@ public class ComposeCryptoStatus {
private RecipientAutocryptStatus recipientAutocryptStatus;
boolean isCryptoStatusRecipientDependent() {
return cryptoProviderState == CryptoProviderState.OK;
}
public Long getSigningKeyId() {
return signingKeyId;
}
@ -60,28 +56,22 @@ public class ComposeCryptoStatus {
}
switch (cryptoMode) {
case PRIVATE:
if (recipientAutocryptStatus == RecipientAutocryptStatus.NO_RECIPIENTS) {
return CryptoStatusDisplayType.PRIVATE_EMPTY;
} else if (recipientAutocryptStatus == RecipientAutocryptStatus.RECOMMENDED_UNCONFIRMED) {
return CryptoStatusDisplayType.PRIVATE_TRUSTED;
} else if (recipientAutocryptStatus == RecipientAutocryptStatus.AVAILABLE_UNCONFIRMED) {
return CryptoStatusDisplayType.PRIVATE_UNTRUSTED;
case CHOICE_ENABLED:
if (recipientAutocryptStatus.canEncrypt() && recipientAutocryptStatus.isConfirmed()) {
return CryptoStatusDisplayType.CHOICE_ENABLED_TRUSTED;
} else if (recipientAutocryptStatus.canEncrypt()) {
return CryptoStatusDisplayType.CHOICE_ENABLED_UNTRUSTED;
}
return CryptoStatusDisplayType.PRIVATE_NOKEY;
case OPPORTUNISTIC:
throw new IllegalStateException("crypto enabled while unavailable!");
case NO_CHOICE:
if (recipientAutocryptStatus == RecipientAutocryptStatus.NO_RECIPIENTS) {
return CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY;
} else if (recipientAutocryptStatus == RecipientAutocryptStatus.RECOMMENDED_UNCONFIRMED) {
return CryptoStatusDisplayType.OPPORTUNISTIC_TRUSTED;
} else if (recipientAutocryptStatus == RecipientAutocryptStatus.AVAILABLE_UNCONFIRMED) {
return CryptoStatusDisplayType.OPPORTUNISTIC_UNTRUSTED;
return CryptoStatusDisplayType.NO_CHOICE_EMPTY;
} else if (recipientAutocryptStatus.canEncrypt()) {
return CryptoStatusDisplayType.NO_CHOICE_AVAILABLE;
}
return CryptoStatusDisplayType.OPPORTUNISTIC_NOKEY;
return CryptoStatusDisplayType.NO_CHOICE_UNAVAILABLE;
case SIGN_ONLY:
return CryptoStatusDisplayType.SIGN_ONLY;
case DISABLE:
return CryptoStatusDisplayType.DISABLED;
default:
throw new AssertionError("all CryptoModes must be handled!");
}
@ -108,15 +98,15 @@ public class ComposeCryptoStatus {
}
public boolean shouldUsePgpMessageBuilder() {
return cryptoProviderState != CryptoProviderState.UNCONFIGURED && cryptoMode != CryptoMode.DISABLE;
return cryptoProviderState != CryptoProviderState.UNCONFIGURED;
}
public boolean isEncryptionEnabled() {
return cryptoMode == CryptoMode.PRIVATE || cryptoMode == CryptoMode.OPPORTUNISTIC;
return cryptoMode == CryptoMode.CHOICE_ENABLED;
}
public boolean isEncryptionOpportunistic() {
return cryptoMode == CryptoMode.OPPORTUNISTIC;
return cryptoMode == CryptoMode.NO_CHOICE;
}
boolean isSignOnly() {
@ -124,21 +114,21 @@ public class ComposeCryptoStatus {
}
public boolean isSigningEnabled() {
return cryptoMode != CryptoMode.DISABLE;
return cryptoMode == CryptoMode.SIGN_ONLY || cryptoMode == CryptoMode.CHOICE_ENABLED;
}
public boolean isPgpInlineModeEnabled() {
return enablePgpInline;
}
public boolean isCryptoDisabled() {
return cryptoMode == CryptoMode.DISABLE;
}
public boolean isProviderStateOk() {
return cryptoProviderState == CryptoProviderState.OK;
}
public boolean canEncrypt() {
return recipientAutocryptStatus != null && recipientAutocryptStatus.canEncrypt();
}
public String[] getRecipientAddresses() {
return recipientAddresses;
}

View file

@ -21,18 +21,11 @@ import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.view.RecipientSelectView;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import com.fsck.k9.view.RecipientSelectView.TokenListener;
import com.fsck.k9.view.ToolableViewAnimator;
public class RecipientMvpView implements OnFocusChangeListener, OnClickListener {
private static final int VIEW_INDEX_HIDDEN = -1;
private static final int VIEW_INDEX_CRYPTO_STATUS_DISABLED = 0;
private static final int VIEW_INDEX_CRYPTO_STATUS_ERROR = 1;
private static final int VIEW_INDEX_CRYPTO_STATUS_NO_RECIPIENTS = 2;
private static final int VIEW_INDEX_CRYPTO_STATUS_ERROR_NO_KEY = 3;
private static final int VIEW_INDEX_CRYPTO_STATUS_DISABLED_NO_KEY = 4;
private static final int VIEW_INDEX_CRYPTO_STATUS_UNTRUSTED = 5;
private static final int VIEW_INDEX_CRYPTO_STATUS_TRUSTED = 6;
private static final int VIEW_INDEX_CRYPTO_STATUS_SIGN_ONLY = 0;
private static final int VIEW_INDEX_CRYPTO_SPECIAL_PGP_INLINE = 0;
private static final int VIEW_INDEX_CRYPTO_SPECIAL_SIGN_ONLY = 1;
@ -49,7 +42,7 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
private final RecipientSelectView toView;
private final RecipientSelectView ccView;
private final RecipientSelectView bccView;
private final ViewAnimator cryptoStatusView;
private final ToolableViewAnimator cryptoStatusView;
private final ViewAnimator recipientExpanderContainer;
private final ViewAnimator cryptoSpecialModeIndicator;
private RecipientPresenter presenter;
@ -66,7 +59,7 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
bccWrapper = activity.findViewById(R.id.bcc_wrapper);
bccDivider = activity.findViewById(R.id.bcc_divider);
recipientExpanderContainer = (ViewAnimator) activity.findViewById(R.id.recipient_expander_container);
cryptoStatusView = (ViewAnimator) activity.findViewById(R.id.crypto_status);
cryptoStatusView = (ToolableViewAnimator) activity.findViewById(R.id.crypto_status);
cryptoStatusView.setOnClickListener(this);
cryptoSpecialModeIndicator = (ViewAnimator) activity.findViewById(R.id.crypto_special_mode);
cryptoSpecialModeIndicator.setOnClickListener(this);
@ -297,14 +290,14 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
}
public void showCryptoStatus(CryptoStatusDisplayType cryptoStatusDisplayType) {
boolean shouldBeHidden = cryptoStatusDisplayType.childToDisplay == VIEW_INDEX_HIDDEN;
boolean shouldBeHidden = cryptoStatusDisplayType.childIdToDisplay == VIEW_INDEX_HIDDEN;
if (shouldBeHidden) {
cryptoStatusView.setVisibility(View.GONE);
return;
}
cryptoStatusView.setVisibility(View.VISIBLE);
cryptoStatusView.setDisplayedChild(cryptoStatusDisplayType.childToDisplay);
cryptoStatusView.setDisplayedChildId(cryptoStatusDisplayType.childIdToDisplay);
}
public void showContactPicker(int requestCode) {
@ -417,23 +410,20 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
public enum CryptoStatusDisplayType {
UNCONFIGURED(VIEW_INDEX_HIDDEN),
UNINITIALIZED(VIEW_INDEX_HIDDEN),
DISABLED(VIEW_INDEX_CRYPTO_STATUS_DISABLED),
SIGN_ONLY(VIEW_INDEX_CRYPTO_STATUS_SIGN_ONLY),
OPPORTUNISTIC_EMPTY(VIEW_INDEX_CRYPTO_STATUS_NO_RECIPIENTS),
OPPORTUNISTIC_NOKEY(VIEW_INDEX_CRYPTO_STATUS_DISABLED_NO_KEY),
OPPORTUNISTIC_UNTRUSTED(VIEW_INDEX_CRYPTO_STATUS_UNTRUSTED),
OPPORTUNISTIC_TRUSTED(VIEW_INDEX_CRYPTO_STATUS_TRUSTED),
PRIVATE_EMPTY(VIEW_INDEX_CRYPTO_STATUS_NO_RECIPIENTS),
PRIVATE_NOKEY(VIEW_INDEX_CRYPTO_STATUS_ERROR_NO_KEY),
PRIVATE_UNTRUSTED(VIEW_INDEX_CRYPTO_STATUS_UNTRUSTED),
PRIVATE_TRUSTED(VIEW_INDEX_CRYPTO_STATUS_TRUSTED),
ERROR(VIEW_INDEX_CRYPTO_STATUS_ERROR);
SIGN_ONLY(R.id.crypto_status_disabled),
NO_CHOICE_EMPTY(R.id.crypto_status_unknown),
NO_CHOICE_UNAVAILABLE(R.id.crypto_status_unknown),
NO_CHOICE_AVAILABLE(R.id.crypto_status_disabled),
NO_CHOICE_AVAILABLE_TRUSTED(R.id.crypto_status_trusted),
CHOICE_ENABLED_UNTRUSTED(R.id.crypto_status_enabled),
CHOICE_ENABLED_TRUSTED(R.id.crypto_status_trusted),
ERROR(R.id.crypto_status_error);
final int childToDisplay;
final int childIdToDisplay;
CryptoStatusDisplayType(int childToDisplay) {
this.childToDisplay = childToDisplay;
CryptoStatusDisplayType(int childIdToDisplay) {
this.childIdToDisplay = childIdToDisplay;
}
}

View file

@ -85,7 +85,7 @@ public class RecipientPresenter implements PermissionPingCallback {
// persistent state, saved during onSaveInstanceState
private RecipientType lastFocusedType = RecipientType.TO;
// TODO initialize cryptoMode to other values under some circumstances, e.g. if we reply to an encrypted e-mail
private CryptoMode currentCryptoMode = CryptoMode.OPPORTUNISTIC;
private CryptoMode currentCryptoMode = CryptoMode.NO_CHOICE;
private boolean cryptoEnablePgpInline = false;
@ -364,48 +364,62 @@ public class RecipientPresenter implements PermissionPingCallback {
pendingUserInteractionIntent = null;
}
new AsyncTask<Void,Void,ComposeCryptoStatus>() {
Long accountCryptoKey = account.getCryptoKey();
if (accountCryptoKey == Account.NO_OPENPGP_KEY) {
accountCryptoKey = null;
}
final ComposeCryptoStatus composeCryptoStatus = new ComposeCryptoStatusBuilder()
.setCryptoProviderState(cryptoProviderState)
.setCryptoMode(currentCryptoMode)
.setEnablePgpInline(cryptoEnablePgpInline)
.setRecipients(getAllRecipients())
.setSigningKeyId(accountCryptoKey)
.setSelfEncryptId(accountCryptoKey)
.build();
final String[] recipientAddresses = composeCryptoStatus.getRecipientAddresses();
new AsyncTask<Void,Void,RecipientAutocryptStatus>() {
@Override
protected ComposeCryptoStatus doInBackground(Void... voids) {
Long accountCryptoKey = account.getCryptoKey();
if (accountCryptoKey == Account.NO_OPENPGP_KEY) {
accountCryptoKey = null;
}
ComposeCryptoStatus composeCryptoStatus = new ComposeCryptoStatusBuilder()
.setCryptoProviderState(cryptoProviderState)
.setCryptoMode(currentCryptoMode)
.setEnablePgpInline(cryptoEnablePgpInline)
.setRecipients(getAllRecipients())
.setSigningKeyId(accountCryptoKey)
.setSelfEncryptId(accountCryptoKey)
.build();
if (composeCryptoStatus.isCryptoStatusRecipientDependent()) {
AutocryptStatusInteractor autocryptStatusInteractor = AutocryptStatusInteractor.getInstance();
RecipientAutocryptStatus recipientAutocryptStatus =
autocryptStatusInteractor.retrieveCryptoProviderRecipientStatus(
getOpenPgpApi(), composeCryptoStatus.getRecipientAddresses());
composeCryptoStatus = composeCryptoStatus.withRecipientAutocryptStatus(recipientAutocryptStatus);
}
return composeCryptoStatus;
protected RecipientAutocryptStatus doInBackground(Void... voids) {
AutocryptStatusInteractor autocryptStatusInteractor = AutocryptStatusInteractor.getInstance();
return autocryptStatusInteractor.retrieveCryptoProviderRecipientStatus(
getOpenPgpApi(), recipientAddresses);
}
@Override
protected void onPostExecute(ComposeCryptoStatus composeCryptoStatus) {
cachedCryptoStatus = composeCryptoStatus;
CryptoStatusDisplayType cryptoStatusDisplayType = composeCryptoStatus.getCryptoStatusDisplayType();
if (cryptoStatusDisplayType == CryptoStatusDisplayType.ERROR) {
recipientMvpView.showErrorOpenPgpRetrieveStatus();
protected void onPostExecute(RecipientAutocryptStatus recipientAutocryptStatus) {
if (recipientAutocryptStatus != null) {
if (!recipientAutocryptStatus.canEncrypt() && composeCryptoStatus.isEncryptionEnabled()) {
currentCryptoMode = CryptoMode.NO_CHOICE;
asyncUpdateCryptoStatus();
return;
}
cachedCryptoStatus = composeCryptoStatus.withRecipientAutocryptStatus(recipientAutocryptStatus);
} else {
cachedCryptoStatus = composeCryptoStatus;
}
recipientMvpView.showCryptoStatus(cryptoStatusDisplayType);
recipientMvpView.showCryptoSpecialMode(composeCryptoStatus.getCryptoSpecialModeDisplayType());
redrawCachedCryptoStatusIcon();
}
}.execute();
}
private void redrawCachedCryptoStatusIcon() {
if (cachedCryptoStatus == null) {
throw new IllegalStateException("must have cached crypto status to redraw it!");
}
CryptoStatusDisplayType cryptoStatusDisplayType = cachedCryptoStatus.getCryptoStatusDisplayType();
if (cryptoStatusDisplayType == CryptoStatusDisplayType.ERROR) {
recipientMvpView.showErrorOpenPgpRetrieveStatus();
}
recipientMvpView.showCryptoStatus(cryptoStatusDisplayType);
recipientMvpView.showCryptoSpecialMode(cachedCryptoStatus.getCryptoSpecialModeDisplayType());
}
@Nullable
public ComposeCryptoStatus getCurrentCachedCryptoStatus() {
return cachedCryptoStatus;
@ -582,10 +596,10 @@ public class RecipientPresenter implements PermissionPingCallback {
case OK:
if (currentCryptoMode == CryptoMode.SIGN_ONLY) {
recipientMvpView.showErrorIsSignOnly();
} else if (currentCryptoMode == CryptoMode.OPPORTUNISTIC) {
onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
} else if (currentCryptoMode == CryptoMode.NO_CHOICE) {
onCryptoModeChanged(CryptoMode.CHOICE_ENABLED);
} else {
onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
onCryptoModeChanged(CryptoMode.NO_CHOICE);
}
return;
@ -781,13 +795,13 @@ public class RecipientPresenter implements PermissionPingCallback {
recipientMvpView.showOpenPgpSignOnlyDialog(true);
}
} else {
onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
onCryptoModeChanged(CryptoMode.NO_CHOICE);
}
}
public void onCryptoPgpSignOnlyDisabled() {
onCryptoPgpInlineChanged(false);
onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
onCryptoModeChanged(CryptoMode.NO_CHOICE);
}
private boolean checkAndIncrementPgpInlineDialogCounter() {
@ -828,7 +842,7 @@ public class RecipientPresenter implements PermissionPingCallback {
public boolean shouldSaveRemotely() {
// TODO more appropriate logic?
return cryptoProviderState == CryptoProviderState.UNCONFIGURED || currentCryptoMode == CryptoMode.DISABLE;
return cryptoProviderState == CryptoProviderState.UNCONFIGURED;
}
public enum CryptoProviderState {
@ -840,10 +854,10 @@ public class RecipientPresenter implements PermissionPingCallback {
}
public enum CryptoMode {
DISABLE,
SIGN_ONLY,
OPPORTUNISTIC,
PRIVATE,
NO_CHOICE,
CHOICE_DISABLED,
CHOICE_ENABLED,
}
public interface RecipientsChangedListener {

View file

@ -71,14 +71,30 @@ public class AutocryptStatusInteractor {
}
public enum RecipientAutocryptStatus {
NO_RECIPIENTS,
UNAVAILABLE,
DISCOURAGE_UNCONFIRMED,
DISCOURAGE_CONFIRMED,
AVAILABLE_UNCONFIRMED,
AVAILABLE_CONFIRMED,
RECOMMENDED_UNCONFIRMED,
RECOMMENDED_CONFIRMED,
ERROR
NO_RECIPIENTS (false, false),
UNAVAILABLE (false, false),
DISCOURAGE_UNCONFIRMED (true, false),
DISCOURAGE_CONFIRMED (true, true),
AVAILABLE_UNCONFIRMED (true, false),
AVAILABLE_CONFIRMED (true, true),
RECOMMENDED_UNCONFIRMED (true, true),
RECOMMENDED_CONFIRMED (true, false),
ERROR (false, false);
private final boolean canEncrypt;
private final boolean isConfirmed;
RecipientAutocryptStatus(boolean canEncrypt, boolean isConfirmed) {
this.canEncrypt = canEncrypt;
this.isConfirmed = isConfirmed;
}
public boolean canEncrypt() {
return canEncrypt;
}
public boolean isConfirmed() {
return isConfirmed;
}
}
}

View file

@ -71,9 +71,6 @@ public class PgpMessageBuilder extends MessageBuilder {
if (cryptoStatus == null) {
throw new IllegalStateException("PgpMessageBuilder must have cryptoStatus set before building!");
}
if (cryptoStatus.isCryptoDisabled()) {
throw new AssertionError("PgpMessageBuilder must not be used if crypto is disabled!");
}
try {
if (!cryptoStatus.isProviderStateOk()) {

View file

@ -98,4 +98,22 @@ public class ToolableViewAnimator extends ViewAnimator {
setInAnimation(savedInAnim);
setOutAnimation(savedOutAnim);
}
public void setDisplayedChildId(int id) {
if (getDisplayedChildId() == id) {
return;
}
for (int i = 0, count = getChildCount(); i < count; i++) {
if (getChildAt(i).getId() == id) {
setDisplayedChild(i);
return;
}
}
String name = getResources().getResourceEntryName(id);
throw new IllegalArgumentException("No view with ID " + name);
}
public int getDisplayedChildId() {
return getChildAt(getDisplayedChild()).getId();
}
}

View file

@ -53,7 +53,7 @@
android:layout_gravity="center_vertical"
android:id="@+id/crypto_special_mode"
android:visibility="gone"
tools:visibility="visible"
tools:visibility="gone"
android:inAnimation="@anim/fade_in"
android:outAnimation="@anim/fade_out"
custom:previewInitialChild="2">
@ -110,12 +110,22 @@
tools:visibility="visible"
android:inAnimation="@anim/fade_in"
android:outAnimation="@anim/fade_out"
custom:previewInitialChild="7">
custom:previewInitialChild="0">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/crypto_status_unknown"
android:src="@drawable/status_lock_error"
android:tint="?attr/openpgp_grey"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/crypto_status_disabled"
android:src="@drawable/status_lock_disabled"
android:tint="?attr/openpgp_dark_grey"
/>
@ -124,109 +134,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/status_lock_error"
android:tint="?attr/openpgp_red"
android:id="@+id/crypto_status_enabled"
android:src="@drawable/status_lock"
android:tint="?attr/openpgp_green"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_dots"
android:tint="?attr/openpgp_grey"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_lock"
android:tint="?attr/openpgp_grey"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_dots"
android:tint="?attr/openpgp_grey"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_lock_error_dots_1"
android:tint="?attr/openpgp_red"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_dots"
android:tint="?attr/openpgp_grey"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_lock_none_dots_1"
android:tint="?attr/openpgp_red"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_lock_disabled"
android:tint="?attr/openpgp_grey"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_dots"
android:tint="?attr/openpgp_grey"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/status_lock_dots_2"
android:tint="?attr/openpgp_orange"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:id="@+id/crypto_status_trusted"
>
<ImageView
android:layout_width="wrap_content"
@ -250,8 +167,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/status_lock_opportunistic"
android:tint="?attr/openpgp_grey"
android:id="@+id/crypto_status_error"
android:src="@drawable/status_lock_error"
android:tint="?attr/openpgp_red"
/>
</com.fsck.k9.view.ToolableViewAnimator>

View file

@ -137,7 +137,7 @@ public class RecipientPresenterTest {
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.NO_CHOICE_EMPTY, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -146,11 +146,11 @@ public class RecipientPresenterTest {
public void getCurrentCryptoStatus_withOpportunisticEmpty() throws Exception {
setupCryptoProvider(noUserIdsResultIntent);
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
recipientPresenter.onCryptoModeChanged(CryptoMode.NO_CHOICE);
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.NO_CHOICE_EMPTY, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -162,11 +162,11 @@ public class RecipientPresenterTest {
resultIntent.putExtra(OpenPgpApi.RESULT_KEYS_CONFIRMED, false);
setupCryptoProvider(resultIntent);
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
recipientPresenter.onCryptoModeChanged(CryptoMode.NO_CHOICE);
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_UNTRUSTED, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.NO_CHOICE_AVAILABLE, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -179,11 +179,11 @@ public class RecipientPresenterTest {
"dummy error msg"));
setupCryptoProvider(resultIntent);
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
recipientPresenter.onCryptoModeChanged(CryptoMode.NO_CHOICE);
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_NOKEY, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.NO_CHOICE_UNAVAILABLE, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -196,11 +196,11 @@ public class RecipientPresenterTest {
"dummy error msg"));
setupCryptoProvider(resultIntent);
recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE);
recipientPresenter.onCryptoModeChanged(CryptoMode.CHOICE_ENABLED);
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.PRIVATE_NOKEY, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.CHOICE_ENABLED_UNAVAILABLE, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -212,11 +212,11 @@ public class RecipientPresenterTest {
resultIntent.putExtra(OpenPgpApi.RESULT_KEYS_CONFIRMED, true);
setupCryptoProvider(resultIntent);
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
recipientPresenter.onCryptoModeChanged(CryptoMode.NO_CHOICE);
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_TRUSTED, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.NO_CHOICE_AVAILABLE_TRUSTED, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -238,11 +238,11 @@ public class RecipientPresenterTest {
public void getCurrentCryptoStatus_withModePrivate() throws Exception {
setupCryptoProvider(noUserIdsResultIntent);
recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE);
recipientPresenter.onCryptoModeChanged(CryptoMode.CHOICE_ENABLED);
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.PRIVATE_EMPTY, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.CHOICE_ENABLED_EMPTY, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.shouldUsePgpMessageBuilder());
}
@ -269,7 +269,7 @@ public class RecipientPresenterTest {
Robolectric.getBackgroundThreadScheduler().runOneTask();
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
assertEquals(CryptoStatusDisplayType.NO_CHOICE_EMPTY, status.getCryptoStatusDisplayType());
assertTrue(status.isProviderStateOk());
assertTrue(status.isPgpInlineModeEnabled());
}

View file

@ -72,13 +72,6 @@ public class PgpMessageBuilderTest {
private PgpMessageBuilder pgpMessageBuilder = createDefaultPgpMessageBuilder(openPgpApi);
@Test(expected = AssertionError.class)
public void build__withDisabledCrypto__shouldError() throws MessagingException {
pgpMessageBuilder.setCryptoStatus(cryptoStatusBuilder.setCryptoMode(CryptoMode.DISABLE).build());
pgpMessageBuilder.buildAsync(mock(Callback.class));
}
@Test
public void build__withCryptoProviderNotOk__shouldThrow() throws MessagingException {
cryptoStatusBuilder.setCryptoMode(CryptoMode.SIGN_ONLY);
@ -238,7 +231,7 @@ public class PgpMessageBuilderTest {
@Test
public void buildEncrypt__withoutRecipients__shouldThrow() throws MessagingException {
cryptoStatusBuilder
.setCryptoMode(CryptoMode.OPPORTUNISTIC)
.setCryptoMode(CryptoMode.NO_CHOICE)
.setRecipients(new ArrayList<Recipient>());
pgpMessageBuilder.setCryptoStatus(cryptoStatusBuilder.build());
@ -257,7 +250,7 @@ public class PgpMessageBuilderTest {
@Test
public void buildEncrypt__shouldSucceed() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
.setCryptoMode(CryptoMode.PRIVATE)
.setCryptoMode(CryptoMode.CHOICE_ENABLED)
.setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key")))
.build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
@ -308,7 +301,7 @@ public class PgpMessageBuilderTest {
@Test
public void buildEncrypt__withInlineEnabled__shouldSucceed() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
.setCryptoMode(CryptoMode.PRIVATE)
.setCryptoMode(CryptoMode.CHOICE_ENABLED)
.setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key")))
.setEnablePgpInline(true)
.build();
@ -395,7 +388,7 @@ public class PgpMessageBuilderTest {
@Test
public void buildEncryptWithAttach__withInlineEnabled__shouldThrow() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
.setCryptoMode(CryptoMode.OPPORTUNISTIC)
.setCryptoMode(CryptoMode.NO_CHOICE)
.setEnablePgpInline(true)
.build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
@ -413,7 +406,7 @@ public class PgpMessageBuilderTest {
public void buildOpportunisticEncrypt__withNoKeysAndNoSignOnly__shouldNotBeSigned() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
.setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key")))
.setCryptoMode(CryptoMode.OPPORTUNISTIC)
.setCryptoMode(CryptoMode.NO_CHOICE)
.build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);