Redo handling of user interaction pending intent

This commit is contained in:
Vincent Breitmoser 2018-03-28 12:20:20 +02:00
parent ee16a83ec8
commit fedf35815f
4 changed files with 43 additions and 30 deletions

View file

@ -42,6 +42,7 @@ public class ComposeCryptoStatus {
return CryptoStatusDisplayType.UNINITIALIZED;
case LOST_CONNECTION:
case ERROR:
case UI_REQUIRED:
return CryptoStatusDisplayType.ERROR;
case OK:
// provider status is ok -> return value is based on cryptoMode

View file

@ -42,11 +42,12 @@ import com.fsck.k9.message.ComposePgpEnableByDefaultDecider;
import com.fsck.k9.message.ComposePgpInlineDecider;
import com.fsck.k9.message.MessageBuilder;
import com.fsck.k9.message.PgpMessageBuilder;
import org.openintents.openpgp.OpenPgpApiManager;
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderError;
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpApiManagerCallback;
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderState;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import org.openintents.openpgp.OpenPgpApiManager;
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpApiManagerCallback;
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderError;
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderState;
import org.openintents.openpgp.util.OpenPgpApi;
import timber.log.Timber;
@ -380,7 +381,7 @@ public class RecipientPresenter {
public void asyncUpdateCryptoStatus() {
cachedCryptoStatus = null;
final OpenPgpProviderState openPgpProviderState = openPgpApiManager.getOpenPgpProviderState();
OpenPgpProviderState openPgpProviderState = openPgpApiManager.getOpenPgpProviderState();
Long accountCryptoKey = account.getOpenPgpKey();
if (accountCryptoKey == Account.NO_OPENPGP_KEY) {
@ -396,17 +397,22 @@ public class RecipientPresenter {
.setOpenPgpKeyId(accountCryptoKey)
.build();
if (openPgpProviderState != OpenPgpProviderState.OK) {
cachedCryptoStatus = composeCryptoStatus;
redrawCachedCryptoStatusIcon();
return;
}
final String[] recipientAddresses = composeCryptoStatus.getRecipientAddresses();
new AsyncTask<Void,Void,RecipientAutocryptStatus>() {
@Override
protected RecipientAutocryptStatus doInBackground(Void... voids) {
if (openPgpProviderState != OpenPgpProviderState.OK) {
OpenPgpApi openPgpApi = openPgpApiManager.getOpenPgpApi();
if (openPgpApi == null) {
return null;
}
return autocryptStatusInteractor.retrieveCryptoProviderRecipientStatus(
openPgpApiManager.getOpenPgpApi(), recipientAddresses);
return autocryptStatusInteractor.retrieveCryptoProviderRecipientStatus(openPgpApi, recipientAddresses);
}
@Override
@ -647,6 +653,12 @@ public class RecipientPresenter {
onCryptoModeChanged(CryptoMode.NO_CHOICE);
return;
case UI_REQUIRED:
// TODO show openpgp settings
PendingIntent pendingIntent = openPgpApiManager.getUserInteractionPendingIntent();
recipientMvpView.launchUserInteractionPendingIntent(pendingIntent, OPENPGP_USER_INTERACTION);
break;
case LOST_CONNECTION:
case UNINITIALIZED:
case ERROR:
@ -813,13 +825,12 @@ public class RecipientPresenter {
}
private final OpenPgpApiManagerCallback openPgpCallback = new OpenPgpApiManagerCallback() {
@Override
public void launchUserInteractionPendingIntent(PendingIntent pendingIntent) {
recipientMvpView.launchUserInteractionPendingIntent(pendingIntent, 0);
}
@Override
public void onOpenPgpProviderStatusChanged() {
if (openPgpApiManager.getOpenPgpProviderState() == OpenPgpProviderState.UI_REQUIRED) {
recipientMvpView.showErrorOpenPgpUserInteractionRequired();
}
asyncUpdateCryptoStatus();
}
@ -829,9 +840,6 @@ public class RecipientPresenter {
case VersionIncompatible:
recipientMvpView.showErrorOpenPgpIncompatible();
break;
case UserInteractionRequired:
recipientMvpView.showErrorOpenPgpUserInteractionRequired();
break;
case ConnectionFailed:
default:
recipientMvpView.showErrorOpenPgpConnection();

View file

@ -1177,7 +1177,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="crypto_mode_private">Encrypt</string>
<string name="error_crypto_provider_incompatible">Crypto provider uses incompatible version. Please check your settings!</string>
<string name="error_crypto_provider_connect">Cannot connect to crypto provider, check your settings or click crypto icon to retry!</string>
<string name="error_crypto_provider_ui_required">Crypto provider access denied, click crypto icon to retry!</string>
<string name="error_crypto_provider_ui_required">Failed to initialize end-to-end encryption, please check your settings</string>
<string name="error_crypto_inline_attach">PGP/INLINE mode does not support attachments!</string>
<string name="enable_inline_pgp">Enable PGP/INLINE</string>
<string name="disable_inline_pgp">Disable PGP/INLINE</string>

View file

@ -23,7 +23,7 @@ public class OpenPgpApiManager implements LifecycleObserver {
private OpenPgpServiceConnection openPgpServiceConnection;
private OpenPgpApi openPgpApi;
private PendingIntent pendingUserInteractionIntent;
private PendingIntent userInteractionPendingIntent;
private OpenPgpApiManagerCallback callback;
private OpenPgpProviderState openPgpProviderState = OpenPgpProviderState.UNCONFIGURED;
@ -85,25 +85,25 @@ public class OpenPgpApiManager implements LifecycleObserver {
boolean isOkStateButLostConnection = openPgpProviderState == OpenPgpProviderState.OK &&
(openPgpServiceConnection == null || !openPgpServiceConnection.isBound());
if (isOkStateButLostConnection) {
userInteractionPendingIntent = null;
setOpenPgpProviderState(OpenPgpProviderState.LOST_CONNECTION);
pendingUserInteractionIntent = null;
return;
}
if (openPgpServiceConnection == null) {
userInteractionPendingIntent = null;
setOpenPgpProviderState(OpenPgpProviderState.UNCONFIGURED);
return;
}
if (!openPgpServiceConnection.isBound()) {
pendingUserInteractionIntent = null;
userInteractionPendingIntent = null;
openPgpServiceConnection.bindToService();
return;
}
if (pendingUserInteractionIntent != null) {
callback.launchUserInteractionPendingIntent(pendingUserInteractionIntent);
pendingUserInteractionIntent = null;
if (userInteractionPendingIntent != null) {
setOpenPgpProviderState(OpenPgpProviderState.UI_REQUIRED);
return;
}
@ -117,9 +117,14 @@ public class OpenPgpApiManager implements LifecycleObserver {
}
public void onUserInteractionResult() {
userInteractionPendingIntent = null;
refreshConnection();
}
public PendingIntent getUserInteractionPendingIntent() {
return userInteractionPendingIntent;
}
private void onPgpPermissionCheckResult(Intent result) {
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
switch (resultCode) {
@ -128,9 +133,8 @@ public class OpenPgpApiManager implements LifecycleObserver {
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
pendingUserInteractionIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
setOpenPgpProviderState(OpenPgpProviderState.ERROR);
callback.onOpenPgpProviderError(OpenPgpProviderError.UserInteractionRequired);
userInteractionPendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
setOpenPgpProviderState(OpenPgpProviderState.UI_REQUIRED);
break;
case OpenPgpApi.RESULT_CODE_ERROR:
@ -176,7 +180,7 @@ public class OpenPgpApiManager implements LifecycleObserver {
public OpenPgpApi getOpenPgpApi() {
if (openPgpServiceConnection == null || !openPgpServiceConnection.isBound()) {
Timber.e("obtained openpgpapi object, but service is not bound! inconsistent state?");
Timber.e("Obtained OpenPgpApi object, but service is not bound! Inconsistent state?");
}
return openPgpApi;
}
@ -189,16 +193,16 @@ public class OpenPgpApiManager implements LifecycleObserver {
UNCONFIGURED,
UNINITIALIZED,
LOST_CONNECTION,
UI_REQUIRED,
ERROR,
OK
}
public enum OpenPgpProviderError {
ConnectionFailed, VersionIncompatible, UserInteractionRequired
ConnectionFailed, VersionIncompatible
}
public interface OpenPgpApiManagerCallback {
void launchUserInteractionPendingIntent(PendingIntent pendingIntent);
void onOpenPgpProviderStatusChanged();
void onOpenPgpProviderError(OpenPgpProviderError error);
}