tls-psk: show error message for unspecialized io exception

This commit is contained in:
Vincent Breitmoser
2017-06-12 16:28:22 +02:00
parent fa3a82ded2
commit af1d028520
4 changed files with 35 additions and 4 deletions

View File

@@ -78,7 +78,8 @@ public class KeyTransferInteractor {
private static final int CONNECTION_RECEIVE_OK = 4;
private static final int CONNECTION_LOST = 5;
private static final int CONNECTION_ERROR_CONNECT = 6;
private static final int CONNECTION_ERROR_LISTEN = 7;
private static final int CONNECTION_ERROR_WHILE_CONNECTED = 7;
private static final int CONNECTION_ERROR_LISTEN = 8;
private static final String QRCODE_URI_FORMAT = "PGP+TRANSFER://%s@%s:%s";
private static final int TIMEOUT_RECEIVING = 2000;
@@ -174,7 +175,8 @@ public class KeyTransferInteractor {
Log.d(Constants.TAG, "ssl handshake error!", e);
invokeListener(CONNECTION_ERROR_CONNECT, null);
} catch (IOException e) {
Log.e(Constants.TAG, "error!", e);
Log.e(Constants.TAG, "communication error!", e);
invokeListener(CONNECTION_ERROR_WHILE_CONNECTED, e.getLocalizedMessage());
}
} finally {
closeQuietly(socket);
@@ -338,6 +340,9 @@ public class KeyTransferInteractor {
case CONNECTION_LOST:
callback.onConnectionLost();
break;
case CONNECTION_ERROR_WHILE_CONNECTED:
callback.onConnectionError(arg);
break;
case CONNECTION_ERROR_CONNECT:
callback.onConnectionErrorConnect();
break;
@@ -392,6 +397,7 @@ public class KeyTransferInteractor {
void onConnectionErrorConnect();
void onConnectionErrorListen();
void onConnectionError(String arg);
}
/**
@@ -413,9 +419,11 @@ public class KeyTransferInteractor {
}
String sAddr = addr.getHostAddress();
boolean isIPv4 = sAddr.indexOf(':') < 0;
if (isIPv4 && useIPv4) {
if (useIPv4) {
if (isIPv4) {
return sAddr;
} else if (!isIPv4) {
}
} else {
int delimIndex = sAddr.indexOf('%'); // drop ip6 zone suffix
if (delimIndex >= 0) {
sAddr = sAddr.substring(0, delimIndex);

View File

@@ -276,6 +276,16 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
view.showErrorListenFailed();
}
@Override
public void onConnectionError(String errorMessage) {
view.showErrorConnectionError(errorMessage);
connectionClear();
if (wasConnected) {
view.showViewDisconnected();
secretKeyAdapter.setAllDisabled(true);
}
}
private void connectionStartConnect(String qrCodeContent) {
connectionClear();
@@ -367,6 +377,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
void showErrorBadKey();
void showErrorConnectionFailed();
void showErrorListenFailed();
void showErrorConnectionError(String errorMessage);
void showResultNotification(ImportKeyResult result);
void setSecretKeyAdapter(Adapter adapter);

View File

@@ -255,6 +255,16 @@ public class TransferFragment extends Fragment implements TransferMvpView {
Notify.create(getActivity(), R.string.transfer_error_listen, Style.ERROR).show();
}
@Override
public void showErrorConnectionError(String errorMessage) {
if (errorMessage != null) {
String text = getString(R.string.transfer_error_generic_msg, errorMessage);
Notify.create(getActivity(), text, Style.ERROR).show();
} else {
Notify.create(getActivity(), R.string.transfer_error_generic, Style.ERROR).show();
}
}
@Override
public void showResultNotification(ImportKeyResult result) {
result.createNotify(getActivity()).show();