load status from provider asynchronously
This commit is contained in:
parent
cfb7a53cd4
commit
0b4c1b2115
5 changed files with 114 additions and 70 deletions
|
@ -279,7 +279,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||||
ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
|
ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
|
||||||
recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView,
|
recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView,
|
||||||
account, composePgpInlineDecider, new ReplyToParser(), this);
|
account, composePgpInlineDecider, new ReplyToParser(), this);
|
||||||
recipientPresenter.updateCryptoStatus();
|
recipientPresenter.asyncUpdateCryptoStatus();
|
||||||
|
|
||||||
|
|
||||||
subjectView = (EditText) findViewById(R.id.subject);
|
subjectView = (EditText) findViewById(R.id.subject);
|
||||||
|
@ -630,8 +630,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||||
private MessageBuilder createMessageBuilder(boolean isDraft) {
|
private MessageBuilder createMessageBuilder(boolean isDraft) {
|
||||||
MessageBuilder builder;
|
MessageBuilder builder;
|
||||||
|
|
||||||
recipientPresenter.updateCryptoStatus();
|
ComposeCryptoStatus cryptoStatus = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
ComposeCryptoStatus cryptoStatus = recipientPresenter.getCurrentCryptoStatus();
|
if (cryptoStatus == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO encrypt drafts for storage
|
// TODO encrypt drafts for storage
|
||||||
if (!isDraft && cryptoStatus.shouldUsePgpMessageBuilder()) {
|
if (!isDraft && cryptoStatus.shouldUsePgpMessageBuilder()) {
|
||||||
SendErrorState maybeSendErrorState = cryptoStatus.getSendErrorStateOrNull();
|
SendErrorState maybeSendErrorState = cryptoStatus.getSendErrorStateOrNull();
|
||||||
|
@ -641,13 +644,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
PgpMessageBuilder pgpBuilder = PgpMessageBuilder.newInstance();
|
PgpMessageBuilder pgpBuilder = PgpMessageBuilder.newInstance();
|
||||||
recipientPresenter.builderSetProperties(pgpBuilder);
|
recipientPresenter.builderSetProperties(pgpBuilder, cryptoStatus);
|
||||||
builder = pgpBuilder;
|
builder = pgpBuilder;
|
||||||
} else {
|
} else {
|
||||||
builder = SimpleMessageBuilder.newInstance();
|
builder = SimpleMessageBuilder.newInstance();
|
||||||
}
|
|
||||||
|
|
||||||
recipientPresenter.builderSetProperties(builder);
|
recipientPresenter.builderSetProperties(builder);
|
||||||
|
}
|
||||||
|
|
||||||
builder.setSubject(Utility.stripNewLines(subjectView.getText().toString()))
|
builder.setSubject(Utility.stripNewLines(subjectView.getText().toString()))
|
||||||
.setSentDate(new Date())
|
.setSentDate(new Date())
|
||||||
|
@ -1484,8 +1486,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||||
message.setUid(relatedMessageReference.getUid());
|
message.setUid(relatedMessageReference.getUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO more appropriate logic here? not sure
|
boolean saveRemotely = recipientPresenter.shouldSaveRemotely();
|
||||||
boolean saveRemotely = !recipientPresenter.getCurrentCryptoStatus().shouldUsePgpMessageBuilder();
|
|
||||||
new SaveMessageTask(getApplicationContext(), account, contacts, internalMessageHandler,
|
new SaveMessageTask(getApplicationContext(), account, contacts, internalMessageHandler,
|
||||||
message, draftId, saveRemotely).execute();
|
message, draftId, saveRemotely).execute();
|
||||||
if (finishAfterDraftSaved) {
|
if (finishAfterDraftSaved) {
|
||||||
|
|
|
@ -116,8 +116,12 @@ public class AttachmentPresenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClickAddAttachment(RecipientPresenter recipientPresenter) {
|
public void onClickAddAttachment(RecipientPresenter recipientPresenter) {
|
||||||
AttachErrorState maybeAttachErrorState =
|
ComposeCryptoStatus currentCachedCryptoStatus = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
recipientPresenter.getCurrentCryptoStatus().getAttachErrorStateOrNull();
|
if (currentCachedCryptoStatus == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttachErrorState maybeAttachErrorState = currentCachedCryptoStatus.getAttachErrorStateOrNull();
|
||||||
if (maybeAttachErrorState != null) {
|
if (maybeAttachErrorState != null) {
|
||||||
recipientPresenter.showPgpAttachError(maybeAttachErrorState);
|
recipientPresenter.showPgpAttachError(maybeAttachErrorState);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -14,7 +14,9 @@ import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
@ -73,8 +75,9 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
private Boolean hasContactPicker;
|
private Boolean hasContactPicker;
|
||||||
private PendingIntent pendingUserInteractionIntent;
|
private PendingIntent pendingUserInteractionIntent;
|
||||||
private CryptoProviderState cryptoProviderState = CryptoProviderState.UNCONFIGURED;
|
private CryptoProviderState cryptoProviderState = CryptoProviderState.UNCONFIGURED;
|
||||||
private ComposeCryptoStatus cachedCryptoStatus;
|
|
||||||
private OpenPgpServiceConnection openPgpServiceConnection;
|
private OpenPgpServiceConnection openPgpServiceConnection;
|
||||||
|
@Nullable
|
||||||
|
private ComposeCryptoStatus cachedCryptoStatus;
|
||||||
|
|
||||||
|
|
||||||
// persistent state, saved during onSaveInstanceState
|
// persistent state, saved during onSaveInstanceState
|
||||||
|
@ -254,7 +257,7 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
menu.findItem(R.id.openpgp_inline_disable).setVisible(isCryptoConfigured && cryptoEnablePgpInline);
|
menu.findItem(R.id.openpgp_inline_disable).setVisible(isCryptoConfigured && cryptoEnablePgpInline);
|
||||||
|
|
||||||
boolean showSignOnly = isCryptoConfigured && K9.getOpenPgpSupportSignOnly();
|
boolean showSignOnly = isCryptoConfigured && K9.getOpenPgpSupportSignOnly();
|
||||||
boolean isSignOnly = cachedCryptoStatus.isSignOnly();
|
boolean isSignOnly = currentCryptoMode == CryptoMode.SIGN_ONLY;
|
||||||
menu.findItem(R.id.openpgp_sign_only).setVisible(showSignOnly && !isSignOnly);
|
menu.findItem(R.id.openpgp_sign_only).setVisible(showSignOnly && !isSignOnly);
|
||||||
menu.findItem(R.id.openpgp_sign_only_disable).setVisible(showSignOnly && isSignOnly);
|
menu.findItem(R.id.openpgp_sign_only_disable).setVisible(showSignOnly && isSignOnly);
|
||||||
|
|
||||||
|
@ -344,7 +347,7 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
recipientMvpView.setRecipientExpanderVisibility(notBothAreVisible);
|
recipientMvpView.setRecipientExpanderVisibility(notBothAreVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCryptoStatus() {
|
public void asyncUpdateCryptoStatus() {
|
||||||
cachedCryptoStatus = null;
|
cachedCryptoStatus = null;
|
||||||
|
|
||||||
boolean isOkStateButLostConnection = cryptoProviderState == CryptoProviderState.OK &&
|
boolean isOkStateButLostConnection = cryptoProviderState == CryptoProviderState.OK &&
|
||||||
|
@ -354,6 +357,9 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
pendingUserInteractionIntent = null;
|
pendingUserInteractionIntent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new AsyncTask<Void,Void,ComposeCryptoStatus>() {
|
||||||
|
@Override
|
||||||
|
protected ComposeCryptoStatus doInBackground(Void... voids) {
|
||||||
Long accountCryptoKey = account.getCryptoKey();
|
Long accountCryptoKey = account.getCryptoKey();
|
||||||
if (accountCryptoKey == Account.NO_OPENPGP_KEY) {
|
if (accountCryptoKey == Account.NO_OPENPGP_KEY) {
|
||||||
accountCryptoKey = null;
|
accountCryptoKey = null;
|
||||||
|
@ -370,21 +376,30 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
|
|
||||||
if (composeCryptoStatus.isCryptoStatusRecipientDependent()) {
|
if (composeCryptoStatus.isCryptoStatusRecipientDependent()) {
|
||||||
PgpMessageBuilder pgpMessageBuilder = PgpMessageBuilder.newInstance();
|
PgpMessageBuilder pgpMessageBuilder = PgpMessageBuilder.newInstance();
|
||||||
builderSetProperties(pgpMessageBuilder);
|
builderSetProperties(pgpMessageBuilder, composeCryptoStatus);
|
||||||
pgpMessageBuilder.setCryptoStatus(composeCryptoStatus);
|
|
||||||
|
|
||||||
|
// this calls out to the crypto provider, hence the need to do this in a background thread
|
||||||
CryptoProviderDryRunStatus cryptoProviderDryRunStatus =
|
CryptoProviderDryRunStatus cryptoProviderDryRunStatus =
|
||||||
pgpMessageBuilder.retrieveCryptoProviderRecipientStatus();
|
pgpMessageBuilder.retrieveCryptoProviderRecipientStatus();
|
||||||
|
|
||||||
composeCryptoStatus = composeCryptoStatus.withCryptoProviderRecipientStatus(cryptoProviderDryRunStatus);
|
composeCryptoStatus = composeCryptoStatus.withCryptoProviderRecipientStatus(
|
||||||
|
cryptoProviderDryRunStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return composeCryptoStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(ComposeCryptoStatus composeCryptoStatus) {
|
||||||
cachedCryptoStatus = composeCryptoStatus;
|
cachedCryptoStatus = composeCryptoStatus;
|
||||||
recipientMvpView.showCryptoStatus(composeCryptoStatus.getCryptoStatusDisplayType());
|
recipientMvpView.showCryptoStatus(composeCryptoStatus.getCryptoStatusDisplayType());
|
||||||
recipientMvpView.showCryptoSpecialMode(composeCryptoStatus.getCryptoSpecialModeDisplayType());
|
recipientMvpView.showCryptoSpecialMode(composeCryptoStatus.getCryptoSpecialModeDisplayType());
|
||||||
}
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
public ComposeCryptoStatus getCurrentCryptoStatus() {
|
@Nullable
|
||||||
|
public ComposeCryptoStatus getCurrentCachedCryptoStatus() {
|
||||||
return cachedCryptoStatus;
|
return cachedCryptoStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,58 +408,58 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
void onToTokenAdded() {
|
void onToTokenAdded() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onToTokenRemoved() {
|
void onToTokenRemoved() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onToTokenChanged() {
|
void onToTokenChanged() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCcTokenAdded() {
|
void onCcTokenAdded() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCcTokenRemoved() {
|
void onCcTokenRemoved() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCcTokenChanged() {
|
void onCcTokenChanged() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBccTokenAdded() {
|
void onBccTokenAdded() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBccTokenRemoved() {
|
void onBccTokenRemoved() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBccTokenChanged() {
|
void onBccTokenChanged() {
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
listener.onRecipientsChanged();
|
listener.onRecipientsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCryptoModeChanged(CryptoMode cryptoMode) {
|
public void onCryptoModeChanged(CryptoMode cryptoMode) {
|
||||||
currentCryptoMode = cryptoMode;
|
currentCryptoMode = cryptoMode;
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCryptoPgpInlineChanged(boolean enablePgpInline) {
|
public void onCryptoPgpInlineChanged(boolean enablePgpInline) {
|
||||||
cryptoEnablePgpInline = enablePgpInline;
|
cryptoEnablePgpInline = enablePgpInline;
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRecipientsFromAddresses(final RecipientType recipientType, final Address... addresses) {
|
private void addRecipientsFromAddresses(final RecipientType recipientType, final Address... addresses) {
|
||||||
|
@ -557,7 +572,7 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
Timber.e("click on crypto status while unconfigured - this should not really happen?!");
|
Timber.e("click on crypto status while unconfigured - this should not really happen?!");
|
||||||
return;
|
return;
|
||||||
case OK:
|
case OK:
|
||||||
if (cachedCryptoStatus.isSignOnly()) {
|
if (currentCryptoMode == CryptoMode.SIGN_ONLY) {
|
||||||
recipientMvpView.showErrorIsSignOnly();
|
recipientMvpView.showErrorIsSignOnly();
|
||||||
} else {
|
} else {
|
||||||
recipientMvpView.showCryptoDialog(currentCryptoMode);
|
recipientMvpView.showCryptoDialog(currentCryptoMode);
|
||||||
|
@ -679,7 +694,7 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
recipientMvpView.showErrorOpenPgpConnection();
|
recipientMvpView.showErrorOpenPgpConnection();
|
||||||
cryptoProviderState = CryptoProviderState.ERROR;
|
cryptoProviderState = CryptoProviderState.ERROR;
|
||||||
Timber.e(e, "error connecting to crypto provider!");
|
Timber.e(e, "error connecting to crypto provider!");
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -702,7 +717,7 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
cryptoProviderState = CryptoProviderState.ERROR;
|
cryptoProviderState = CryptoProviderState.ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateCryptoStatus();
|
asyncUpdateCryptoStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onActivityDestroy() {
|
public void onActivityDestroy() {
|
||||||
|
@ -719,17 +734,23 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
return new OpenPgpApi(context, openPgpServiceConnection.getService());
|
return new OpenPgpApi(context, openPgpServiceConnection.getService());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void builderSetProperties(MessageBuilder messageBuilder) {
|
public void builderSetProperties(MessageBuilder messageBuilder) {
|
||||||
|
if (messageBuilder instanceof PgpMessageBuilder) {
|
||||||
|
throw new IllegalArgumentException("PpgMessageBuilder must be called with ComposeCryptoStatus argument!");
|
||||||
|
}
|
||||||
|
|
||||||
messageBuilder.setTo(getToAddresses());
|
messageBuilder.setTo(getToAddresses());
|
||||||
messageBuilder.setCc(getCcAddresses());
|
messageBuilder.setCc(getCcAddresses());
|
||||||
messageBuilder.setBcc(getBccAddresses());
|
messageBuilder.setBcc(getBccAddresses());
|
||||||
|
|
||||||
if (messageBuilder instanceof PgpMessageBuilder) {
|
|
||||||
PgpMessageBuilder pgpMessageBuilder = (PgpMessageBuilder) messageBuilder;
|
|
||||||
pgpMessageBuilder.setOpenPgpApi(getOpenPgpApi());
|
|
||||||
pgpMessageBuilder.setCryptoStatus(getCurrentCryptoStatus());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void builderSetProperties(PgpMessageBuilder pgpMessageBuilder, ComposeCryptoStatus cryptoStatus) {
|
||||||
|
pgpMessageBuilder.setTo(getToAddresses());
|
||||||
|
pgpMessageBuilder.setCc(getCcAddresses());
|
||||||
|
pgpMessageBuilder.setBcc(getBccAddresses());
|
||||||
|
|
||||||
|
pgpMessageBuilder.setOpenPgpApi(getOpenPgpApi());
|
||||||
|
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMenuSetPgpInline(boolean enablePgpInline) {
|
public void onMenuSetPgpInline(boolean enablePgpInline) {
|
||||||
|
@ -795,6 +816,11 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
this.openPgpProvider = cryptoProvider;
|
this.openPgpProvider = cryptoProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldSaveRemotely() {
|
||||||
|
// TODO more appropriate logic?
|
||||||
|
return cryptoProviderState == CryptoProviderState.UNCONFIGURED || currentCryptoMode == CryptoMode.DISABLE;
|
||||||
|
}
|
||||||
|
|
||||||
public enum CryptoProviderState {
|
public enum CryptoProviderState {
|
||||||
UNCONFIGURED,
|
UNCONFIGURED,
|
||||||
UNINITIALIZED,
|
UNINITIALIZED,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.content.Intent;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.annotation.WorkerThread;
|
||||||
|
|
||||||
import com.fsck.k9.Globals;
|
import com.fsck.k9.Globals;
|
||||||
import com.fsck.k9.activity.compose.ComposeCryptoStatus;
|
import com.fsck.k9.activity.compose.ComposeCryptoStatus;
|
||||||
|
@ -327,6 +328,7 @@ public class PgpMessageBuilder extends MessageBuilder {
|
||||||
this.cryptoStatus = cryptoStatus;
|
this.cryptoStatus = cryptoStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
public CryptoProviderDryRunStatus retrieveCryptoProviderRecipientStatus() {
|
public CryptoProviderDryRunStatus retrieveCryptoProviderRecipientStatus() {
|
||||||
boolean shouldSign = cryptoStatus.isSigningEnabled();
|
boolean shouldSign = cryptoStatus.isSigningEnabled();
|
||||||
boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled();
|
boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled();
|
||||||
|
|
|
@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
@RunWith(K9RobolectricTestRunner.class)
|
@RunWith(K9RobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowOpenPgpAsyncTask.class})
|
@Config(shadows = {ShadowOpenPgpAsyncTask.class})
|
||||||
public class RecipientPresenterTest {
|
public class RecipientPresenterTest {
|
||||||
|
@ -77,7 +78,7 @@ public class RecipientPresenterTest {
|
||||||
|
|
||||||
recipientPresenter = new RecipientPresenter(
|
recipientPresenter = new RecipientPresenter(
|
||||||
context, loaderManager, recipientMvpView, account, composePgpInlineDecider, replyToParser, listener);
|
context, loaderManager, recipientMvpView, account, composePgpInlineDecider, replyToParser, listener);
|
||||||
recipientPresenter.updateCryptoStatus();
|
recipientPresenter.asyncUpdateCryptoStatus();
|
||||||
|
|
||||||
noUserIdsResultIntent = new Intent();
|
noUserIdsResultIntent = new Intent();
|
||||||
noUserIdsResultIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
noUserIdsResultIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||||
|
@ -120,7 +121,7 @@ public class RecipientPresenterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCurrentCryptoStatus_withoutCryptoProvider() throws Exception {
|
public void getCurrentCryptoStatus_withoutCryptoProvider() throws Exception {
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.UNCONFIGURED, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.UNCONFIGURED, status.getCryptoStatusDisplayType());
|
||||||
assertEquals(CryptoSpecialModeDisplayType.NONE, status.getCryptoSpecialModeDisplayType());
|
assertEquals(CryptoSpecialModeDisplayType.NONE, status.getCryptoSpecialModeDisplayType());
|
||||||
|
@ -133,7 +134,8 @@ public class RecipientPresenterTest {
|
||||||
public void getCurrentCryptoStatus_withCryptoProvider() throws Exception {
|
public void getCurrentCryptoStatus_withCryptoProvider() throws Exception {
|
||||||
setupCryptoProvider(noUserIdsResultIntent);
|
setupCryptoProvider(noUserIdsResultIntent);
|
||||||
|
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -145,7 +147,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(noUserIdsResultIntent);
|
setupCryptoProvider(noUserIdsResultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -160,7 +163,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(resultIntent);
|
setupCryptoProvider(resultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_UNTRUSTED, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_UNTRUSTED, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -176,7 +180,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(resultIntent);
|
setupCryptoProvider(resultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_NOKEY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_NOKEY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -192,7 +197,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(resultIntent);
|
setupCryptoProvider(resultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.PRIVATE_NOKEY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.PRIVATE_NOKEY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -207,7 +213,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(resultIntent);
|
setupCryptoProvider(resultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_TRUSTED, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_TRUSTED, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -219,7 +226,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(noUserIdsResultIntent);
|
setupCryptoProvider(noUserIdsResultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.DISABLE);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.DISABLE);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.DISABLED, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.DISABLED, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -231,7 +239,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(noUserIdsResultIntent);
|
setupCryptoProvider(noUserIdsResultIntent);
|
||||||
|
|
||||||
recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE);
|
recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.PRIVATE_EMPTY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.PRIVATE_EMPTY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -243,7 +252,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(noUserIdsResultIntent);
|
setupCryptoProvider(noUserIdsResultIntent);
|
||||||
|
|
||||||
recipientPresenter.onMenuSetSignOnly(true);
|
recipientPresenter.onMenuSetSignOnly(true);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.SIGN_ONLY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.SIGN_ONLY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -256,7 +266,8 @@ public class RecipientPresenterTest {
|
||||||
setupCryptoProvider(noUserIdsResultIntent);
|
setupCryptoProvider(noUserIdsResultIntent);
|
||||||
|
|
||||||
recipientPresenter.onMenuSetPgpInline(true);
|
recipientPresenter.onMenuSetPgpInline(true);
|
||||||
ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
|
ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus();
|
||||||
|
|
||||||
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
|
assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType());
|
||||||
assertTrue(status.isProviderStateOk());
|
assertTrue(status.isProviderStateOk());
|
||||||
|
@ -334,7 +345,7 @@ public class RecipientPresenterTest {
|
||||||
Robolectric.getBackgroundThreadScheduler().pause();
|
Robolectric.getBackgroundThreadScheduler().pause();
|
||||||
recipientPresenter.setOpenPgpServiceConnection(openPgpServiceConnection, CRYPTO_PROVIDER);
|
recipientPresenter.setOpenPgpServiceConnection(openPgpServiceConnection, CRYPTO_PROVIDER);
|
||||||
recipientPresenter.onSwitchAccount(account);
|
recipientPresenter.onSwitchAccount(account);
|
||||||
recipientPresenter.updateCryptoStatus();
|
recipientPresenter.asyncUpdateCryptoStatus();
|
||||||
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
Robolectric.getBackgroundThreadScheduler().runOneTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue