diff options
Diffstat (limited to '')
15 files changed, 434 insertions, 27 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java index ee0ee14a..6a9b5c13 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java @@ -2387,7 +2387,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void sendReadMarker(final Conversation conversation) { final Message markable = conversation.getLatestMarkableMessage(); - Logging.d("markRead", "XmppConnectionService.sendReadMarker (" + conversation.getName() + ")"); + //Logging.d("markRead", "XmppConnectionService.sendReadMarker (" + conversation.getName() + ")"); if (this.markRead(conversation)) { updateConversationUi(); } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferEntity.java index e1b40fa6..06e697db 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferEntity.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferEntity.java @@ -49,10 +49,16 @@ public class FileTransferEntity implements Transferable { * This initialization includes loading the file and associating this transferable to the message. * @param message the message in which the file to transfer is contained. */ - public FileTransferEntity(Message message) { + public FileTransferEntity(Message message, boolean initFile) { this.message = message; this.message.setTransferable(this); - this.file = FileBackend.getFile(message, false); + if (initFile) { + this.initFile(); + } + } + + protected final void initFile() { + this.file = FileBackend.getFile(this.message, false); } /** @@ -68,11 +74,11 @@ public class FileTransferEntity implements Transferable { /** * Returns the global transferable status. * - * @return {@value STATUS_FAILED} if #isFailed returns <code>true</code>, {@value STATUS_UPLOADING} otherwise + * @return {@value STATUS_FAILED} if #isFailed returns <code>true</code>, {@value STATUS_UNKNOWN} otherwise */ @Override public int getStatus() { - int status = (isFailed()) ? STATUS_FAILED : STATUS_UPLOADING; + int status = (isFailed()) ? STATUS_FAILED : STATUS_UNKNOWN; return status; } @@ -80,7 +86,6 @@ public class FileTransferEntity implements Transferable { * Returns the expected file size of the underlying file. * @return the expected file size or 0 if no file is associated. */ - @Override public long getFileSize() { return file == null ? 0 : file.getExpectedSize(); } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java index 2f9a819b..8d971bb2 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java @@ -9,7 +9,7 @@ import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.services.FileTransferService; -import de.thedevstack.conversationsplus.services.filetransfer.http.upload.HttpFileTransferEntity; +import de.thedevstack.conversationsplus.services.filetransfer.http.upload.HttpUploadFileTransferEntity; import de.thedevstack.conversationsplus.utils.MessageUtil; /** @@ -73,7 +73,7 @@ public class FileTransferManager implements FileTransferStatusListener { * @return <code>true</code> if the file transfer was successful, <code>false</code> otherwise */ public boolean transferFile(Message message, boolean delay) { - Logging.d(Config.LOGTAG, "send file message"); + Logging.d(Config.LOGTAG, "transfer file message"); boolean transferSuccessfullyStarted = false; for (WeightedTransferService wts : this.transferServices) { try { @@ -91,13 +91,13 @@ public class FileTransferManager implements FileTransferStatusListener { } /** - * Checks whether a message can be sent using this service or not. + * Checks whether a message can be sent or received using this service or not. * * @param message the message to be checked * @return <code>true</code> if the message can be processed, <code>false</code> otherwise */ public boolean accept(Message message) { - return message.needsUploading(); + return message.needsUploading() || MessageUtil.needsDownload(message); } @Override @@ -106,7 +106,7 @@ public class FileTransferManager implements FileTransferStatusListener { if (null == wts) { return; } - boolean delayed = (entity instanceof HttpFileTransferEntity) && ((HttpFileTransferEntity) entity).isDelayed(); + boolean delayed = (entity instanceof HttpUploadFileTransferEntity) && ((HttpUploadFileTransferEntity) entity).isDelayed(); if (failureReason.isRecoverable()) { wts.fileTransferService.transferFile(entity.getMessage(), delayed); } else { diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java index 83a250de..d61a5c6a 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java @@ -42,7 +42,7 @@ public class DeleteTokenReceived implements OnIqPacketReceived { String url = this.remoteFile.getPath(); String deleteToken = DeleteSlotPacketParser.parseDeleteToken(packet); Logging.d("filetransfer.http.delete", "Got delete token '" + deleteToken + "' for remote file '" + remoteFile.getPath() + "'"); - OkHttpClient client = HttpClient.getClient(true); + OkHttpClient client = HttpClient.getOkHttpClient(true); Request request = new Request.Builder() .url(url) .addHeader(HEADER_NAME_DELETE_TOKEN, deleteToken) diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java new file mode 100644 index 00000000..5885e2e1 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java @@ -0,0 +1,61 @@ +package de.thedevstack.conversationsplus.services.filetransfer.http.download; + +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.ConversationsPlusApplication; +import de.thedevstack.conversationsplus.ConversationsPlusPreferences; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.http.HttpHeadRetrievedListener; +import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManager; +import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; + +/** + * + */ +public class AutomaticFileDownload implements HttpHeadRetrievedListener { + private boolean notify; + + public AutomaticFileDownload(boolean notify) { + this.notify = notify; + } + + @Override + public void onFileSizeRetrieved(long size, Message message) { + if (!this.transferFile(message)) { + + } + if (this.notify) { + XmppConnectionServiceAccessor.xmppConnectionService.getNotificationService().push(message); + } + } + + /** + * Transfers a file for the corresponding message. + * + * @param message the message containing the file to transfer + * @return <code>true</code> if the file transfer was successful, <code>false</code> otherwise + */ + public boolean transferFile(Message message) { + if (this.accept(message)) { + Logging.d("http-download", "Starting automatic download"); + FileTransferManager ftm = FileTransferManager.getInstance(); + if (ftm.accept(message)) { + return ftm.transferFile(message); + } + } + return false; + } + + /** + * Checks whether a message can be sent using this service or not. + * + * @param message the message to be checked + * @return <code>true</code> if the message can be processed, <code>false</code> otherwise + */ + public boolean accept(Message message) { + long size = message.getFileParams().getSize(); + return ConversationsPlusApplication.hasStoragePermission() + && size > -1 + && size <= ConversationsPlusPreferences.autoAcceptFileSize() + && XmppConnectionServiceAccessor.xmppConnectionService.isDownloadAllowedInConnection(); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java new file mode 100644 index 00000000..fcd3904b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java @@ -0,0 +1,53 @@ +package de.thedevstack.conversationsplus.services.filetransfer.http.download; + +import android.os.PowerManager; + +import de.thedevstack.conversationsplus.entities.FileParams; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.http.ProgressListener; +import de.thedevstack.conversationsplus.services.filetransfer.FileTransferEntity; +import de.thedevstack.conversationsplus.utils.UiUpdateHelper; + +/** + * + */ +public class HttpDownloadFileTransferEntity extends FileTransferEntity implements ProgressListener { + public PowerManager.WakeLock wakeLock; + /** + * Initializes the FileTransferEntity based on the associated message. + * This initialization includes loading the file and associating this transferable to the message. + * + * @param message the message in which the file to transfer is contained. + */ + public HttpDownloadFileTransferEntity(Message message) { + super(message, false); + FileParams fileParams = message.getFileParams(); + this.initFile(); + this.getFile().setExpectedSize(fileParams.getSize()); + } + + /** + * Returns the global transferable status. + * + * @return {@value STATUS_FAILED} if #isFailed returns <code>true</code>, {@value STATUS_DOWNLOADING} otherwise + */ + @Override + public int getStatus() { + int status = (isFailed()) ? STATUS_FAILED : STATUS_DOWNLOADING; + return status; + } + + @Override + public void update(long bytesRead, long contentLength, boolean done) { + if (0 >= getFile().getExpectedSize()) { + getFile().setExpectedSize(contentLength); + getMessage().getFileParams().setSize(contentLength); + } + if (done) { + this.transferred(); + } else { + this.updateProgress(bytesRead); + } + UiUpdateHelper.updateConversationUi(); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java new file mode 100644 index 00000000..c7fcc430 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java @@ -0,0 +1,65 @@ +package de.thedevstack.conversationsplus.services.filetransfer.http.download; + +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.ConversationsPlusApplication; +import de.thedevstack.conversationsplus.entities.FileParams; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.enums.FileStatus; +import de.thedevstack.conversationsplus.http.HttpClient; +import de.thedevstack.conversationsplus.services.filetransfer.AbstractFileTransferService; +import de.thedevstack.conversationsplus.utils.MessageUtil; +import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; +import okhttp3.Call; + +/** + * + */ +public class HttpDownloadFileTransferService extends AbstractFileTransferService { + /** + * Transfers a file for the corresponding message. + * + * @param message the message containing the file to transfer + * @return <code>true</code> if the file transfer was successful, <code>false</code> otherwise + */ + @Override + public boolean transferFile(Message message) { + return this.transferFile(message, false); + } + + /** + * Transfers a file for the corresponding message. + * + * @param message the message containing the file to transfer + * @param delay whether the message is delayed or not + * @return <code>true</code> if the file transfer was successful, <code>false</code> otherwise + */ + @Override + public boolean transferFile(Message message, boolean delay) { + Logging.d("http-download", "Get file from remote host"); + final HttpDownloadFileTransferEntity entity = new HttpDownloadFileTransferEntity(message); + if (message.getFileParams().getFileStatus() == FileStatus.NEEDS_DOWNLOAD + && ConversationsPlusApplication.hasStoragePermission() + && XmppConnectionServiceAccessor.xmppConnectionService.isDownloadAllowedInConnection()) { + FileParams fileParams = message.getFileParams(); + MessageUtil.setAndSaveFileStatus(message, FileStatus.DOWNLOADING); + entity.wakeLock = ConversationsPlusApplication.createPartialWakeLock("http_download_" + entity.getMessage().getUuid()); + entity.wakeLock.acquire(); + Call call = HttpClient.openCancelableAndProgressListenedCall(fileParams.getUrl(), entity, false); + call.enqueue(new HttpFileDownloadCallback(entity)); + } + + return true; + } + + /** + * Checks whether a message can be sent using this service or not. + * + * @param message the message to be checked + * @return <code>true</code> if the message can be processed, <code>false</code> otherwise + */ + @Override + public boolean accept(Message message) { + return MessageUtil.needsDownload(message) + && message.hasFileAttached() && (null == message.getFileParams() || message.getFileParams().isRemoteAvailable()); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpFileDownloadCallback.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpFileDownloadCallback.java new file mode 100644 index 00000000..2c31754c --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpFileDownloadCallback.java @@ -0,0 +1,57 @@ +package de.thedevstack.conversationsplus.services.filetransfer.http.download; + +import java.io.IOException; +import java.io.OutputStream; + +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.entities.DownloadableFile; +import de.thedevstack.conversationsplus.enums.FileStatus; +import de.thedevstack.conversationsplus.persistance.FileBackend; +import de.thedevstack.conversationsplus.services.AbstractConnectionManager; +import de.thedevstack.conversationsplus.utils.MessageUtil; +import de.thedevstack.conversationsplus.utils.StreamUtil; +import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Response; + +/** + * + */ +public class HttpFileDownloadCallback implements Callback { + private HttpDownloadFileTransferEntity entity; + + public HttpFileDownloadCallback(HttpDownloadFileTransferEntity entity) { + this.entity = entity; + } + + + @Override + public void onFailure(Call call, IOException e) { + changeStatus(FileStatus.DOWNLOAD_FAILED); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()) { + Logging.d("http-download", "Receiving file from remote host"); + DownloadableFile file = this.entity.getFile(); + OutputStream os = AbstractConnectionManager.createOutputStream(file, true); + os.write(response.body().bytes()); + StreamUtil.close(os); + FileBackend.updateMediaScanner(file, XmppConnectionServiceAccessor.xmppConnectionService); + this.entity.transferred(); + changeStatus(FileStatus.DOWNLOADED); + } else { + Logging.e("http-download", "Failed to retrieve file from remote host. HTTP response: " + response.code() + ", " + response.body().string()); + changeStatus(FileStatus.DOWNLOAD_FAILED); + } + if (entity.wakeLock.isHeld()) { + entity.wakeLock.release(); + } + } + + private void changeStatus(FileStatus status) { + MessageUtil.setAndSaveFileStatus(this.entity.getMessage(), status); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java new file mode 100644 index 00000000..8d23d9c0 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java @@ -0,0 +1,112 @@ +package de.thedevstack.conversationsplus.services.filetransfer.http.download; + +import java.io.IOException; + +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.entities.FileParams; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.enums.FileStatus; +import de.thedevstack.conversationsplus.http.Http; +import de.thedevstack.conversationsplus.http.HttpClient; +import de.thedevstack.conversationsplus.http.HttpHeadRetrievedListener; +import de.thedevstack.conversationsplus.persistance.DatabaseBackend; +import de.thedevstack.conversationsplus.utils.MessageUtil; +import de.thedevstack.conversationsplus.utils.UiUpdateHelper; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.MediaType; +import okhttp3.Response; + +/** + * + */ +public class HttpRetrieveHead implements Http, Callback { + private static final String LOGTAG = "http-retrieve-head"; + + private Message message; + private String url; + + private HttpHeadRetrievedListener listener; + + public HttpRetrieveHead(Message message) { + this.message = message; + this.url = (null != message && null != message.getFileParams()) ? message.getFileParams().getUrl() : null; + if (null == this.url) { + /* + * If this code is reached and the URL is null something went wrong. + * Try again to extract the file parameters from the message. + */ + MessageUtil.extractFileParamsFromBody(message); + this.url = (null != message.getFileParams()) ? message.getFileParams().getUrl() : null; + if (null == this.url) { + message.setTreatAsDownloadable(Message.Decision.NEVER); // TODO find sth better + if (null != message.getFileParams()) { + MessageUtil.setAndSaveFileStatus(message, FileStatus.NOT_FOUND); + } + } + } + } + + public void retrieveAndSetContentTypeAndLength() { + if (null != this.url) { + Logging.d(LOGTAG, "retrieve file size and mime type."); + + try { + MessageUtil.setAndSaveFileStatus(message, FileStatus.CHECKING_FILE_SIZE); + HttpClient.retrieveHead(this.url, this); + } catch (IOException e) { + Logging.e(LOGTAG, "Error while trying to call '" + url + "'.", e); + } + } + } + + private static long parseContentLength(String contentLength) { + long length = -1; + if (null != contentLength) { + try { + length = Long.parseLong(contentLength, 10); + } catch (NumberFormatException e) { + } + } + return length; + } + + @Override + public void onFailure(Call call, IOException e) { + Logging.e(LOGTAG, "Error while trying to call '" + call.request().url() + "'.", e); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + Logging.d(LOGTAG, "Response for retrieving file size and mime type received."); + FileParams fileParams = message.getFileParams(); + if (response.isSuccessful()) { + MediaType mediaType = response.body().contentType(); + String contentType = null != mediaType ? (mediaType.type() + "/" + mediaType.subtype()) : response.header(MIME_REQUEST_PROPERTY_NAME); + String contentLength = response.header(HEADER_NAME_CONTENT_LENGTH); + + long size = parseContentLength(contentLength); + fileParams.setSize(size); + fileParams.setMimeType(contentType); + if (0 < size) { + fileParams.setFileStatus(FileStatus.NEEDS_DOWNLOAD); + } + DatabaseBackend.getInstance().updateMessage(message); + UiUpdateHelper.updateConversationUi(); + if (null != this.listener) { + this.listener.onFileSizeRetrieved(size, this.message); + } + } else { + if (response.code() == HTTP_NOT_FOUND) { + Logging.d(LOGTAG, "remote file '" + response.request().url() + "' not found."); + MessageUtil.setAndSaveFileStatus(message, FileStatus.NOT_FOUND); + } else { + Logging.d(LOGTAG, "remote file '" + response.request().url() + "' not loaded - response code: " + response.code() + "."); + } + } + } + + public void setListener(HttpHeadRetrievedListener listener) { + this.listener = listener; + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java index 8cae599c..73c18f15 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java @@ -2,23 +2,32 @@ package de.thedevstack.conversationsplus.services.filetransfer.http.upload; import android.os.PowerManager; +import org.apache.http.conn.ssl.StrictHostnameVerifier; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.UnknownHostException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; import java.util.Scanner; +import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.X509TrustManager; import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.Message; -import de.thedevstack.conversationsplus.http.HttpConnectionManager; import de.thedevstack.conversationsplus.persistance.FileBackend; import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason; +import de.thedevstack.conversationsplus.utils.CryptoHelper; +import de.thedevstack.conversationsplus.utils.SSLSocketHelper; import de.thedevstack.conversationsplus.utils.StreamUtil; import de.thedevstack.conversationsplus.utils.UiUpdateHelper; import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; @@ -29,9 +38,9 @@ public class HttpFileUploader implements Runnable { private static final String MIME_REQUEST_PROPERTY_NAME = "Content-Type"; private static final String USER_AGENT_REQUEST_PROPERTY_NAME = "User-Agent"; private static final int BUFFER_LENGTH = 4096; - private final HttpFileTransferEntity entity; + private final HttpUploadFileTransferEntity entity; - public HttpFileUploader(HttpFileTransferEntity entity) { + public HttpFileUploader(HttpUploadFileTransferEntity entity) { this.entity = entity; } @@ -55,7 +64,7 @@ public class HttpFileUploader implements Runnable { connection = (HttpURLConnection) putUrl.openConnection(); if (connection instanceof HttpsURLConnection) { - HttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, true); + setupTrustManager((HttpsURLConnection) connection, true); } connection.setRequestMethod(HTTP_METHOD); connection.setFixedLengthStreamingMode((int) file.getExpectedSize()); @@ -147,4 +156,37 @@ public class HttpFileUploader implements Runnable { } return httpResponseMessage; } + + public static void setupTrustManager(final HttpsURLConnection connection, final boolean interactive) { + final X509TrustManager trustManager; + final HostnameVerifier hostnameVerifier; + if (interactive) { + trustManager = ConversationsPlusApplication.getMemorizingTrustManager(); + hostnameVerifier = ConversationsPlusApplication.getMemorizingTrustManager().wrapHostnameVerifier( + new StrictHostnameVerifier()); + } else { + trustManager = ConversationsPlusApplication.getMemorizingTrustManager() + .getNonInteractive(); + hostnameVerifier = ConversationsPlusApplication.getMemorizingTrustManager() + .wrapHostnameVerifierNonInteractive( + new StrictHostnameVerifier()); + } + try { + final SSLContext sc = SSLSocketHelper.getSSLContext(); + sc.init(null, new X509TrustManager[]{trustManager}, + ConversationsPlusApplication.getSecureRandom()); + + final SSLSocketFactory sf = sc.getSocketFactory(); + final String[] cipherSuites = CryptoHelper.getOrderedCipherSuites( + sf.getSupportedCipherSuites()); + if (cipherSuites.length > 0) { + sc.getDefaultSSLParameters().setCipherSuites(cipherSuites); + + } + + connection.setSSLSocketFactory(sf); + connection.setHostnameVerifier(hostnameVerifier); + } catch (final KeyManagementException | NoSuchAlgorithmException ignored) { + } + } }
\ No newline at end of file diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferEntity.java index 985dafcb..54186983 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferEntity.java @@ -18,15 +18,15 @@ import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload /** * */ -public class HttpFileTransferEntity extends FileTransferEntity { +public class HttpUploadFileTransferEntity extends FileTransferEntity { private HttpUploadSlot slot; private final byte[] key; private final boolean delayed; - public HttpFileTransferEntity(Message message, boolean delayed) { - super(message); + public HttpUploadFileTransferEntity(Message message, boolean delayed) { + super(message, true); this.getMessage().setHttpUploaded(true); - this.getMessage().setNoDownloadable(); // TODO Set rmeote file status to uploaded + this.getMessage().setNoDownloadable(); FileParams fileParams = this.getMessage().getFileParams(); if (null == fileParams) { fileParams = new FileParams(); @@ -45,6 +45,17 @@ public class HttpFileTransferEntity extends FileTransferEntity { this.delayed = delayed; } + /** + * Returns the global transferable status. + * + * @return {@value STATUS_FAILED} if #isFailed returns <code>true</code>, {@value STATUS_UPLOADING} otherwise + */ + @Override + public int getStatus() { + int status = (isFailed()) ? STATUS_FAILED : STATUS_UPLOADING; + return status; + } + public void setSlot(HttpUploadSlot slot) { this.slot = slot; } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java index f0bb438d..c2e92a9e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java @@ -9,7 +9,6 @@ import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.Message; -import de.thedevstack.conversationsplus.persistance.FileBackend; import de.thedevstack.conversationsplus.services.AbstractConnectionManager; import de.thedevstack.conversationsplus.services.FileTransferService; import de.thedevstack.conversationsplus.services.filetransfer.AbstractFileTransferService; @@ -53,7 +52,7 @@ public class HttpUploadFileTransferService extends AbstractFileTransferService i Logging.d("httpupload", "Starting to upload file"); boolean started = false; try { - final HttpFileTransferEntity entity = new HttpFileTransferEntity(message, delay); + final HttpUploadFileTransferEntity entity = new HttpUploadFileTransferEntity(message, delay); this.addStatusListenerToEntity(entity); entity.startAttempt(); Account account = message.getConversation().getAccount(); @@ -99,6 +98,7 @@ public class HttpUploadFileTransferService extends AbstractFileTransferService i && null != message.getConversation() && null != message.getConversation().getAccount() && null != message.getFileParams() + && message.needsUploading() && AccountUtil.isHttpUploadAvailable(message.getConversation().getAccount(), message.getFileParams().getSize()); } } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadSlotRequestReceived.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadSlotRequestReceived.java index 2687878d..022aedcf 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadSlotRequestReceived.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadSlotRequestReceived.java @@ -13,9 +13,9 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; * */ public class HttpUploadSlotRequestReceived implements OnIqPacketReceived { - private final HttpFileTransferEntity entity; + private final HttpUploadFileTransferEntity entity; - public HttpUploadSlotRequestReceived(HttpFileTransferEntity entity) { + public HttpUploadSlotRequestReceived(HttpUploadFileTransferEntity entity) { this.entity = entity; } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadedFileEncryptionUiCallback.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadedFileEncryptionUiCallback.java index f363a675..dc36851f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadedFileEncryptionUiCallback.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadedFileEncryptionUiCallback.java @@ -11,9 +11,9 @@ import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; * */ public class HttpUploadedFileEncryptionUiCallback implements UiCallback<Message> { - private final HttpFileTransferEntity entity; + private final HttpUploadFileTransferEntity entity; - public HttpUploadedFileEncryptionUiCallback(HttpFileTransferEntity entity) { + public HttpUploadedFileEncryptionUiCallback(HttpUploadFileTransferEntity entity) { this.entity = entity; } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/jingle/JingleFileTransferService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/jingle/JingleFileTransferService.java index 5d8ddd4e..ca708fe6 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/jingle/JingleFileTransferService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/jingle/JingleFileTransferService.java @@ -47,6 +47,7 @@ public class JingleFileTransferService extends AbstractFileTransferService imple */ @Override public boolean accept(Message message) { - return message.fixCounterpart(); // No clue why - but this seems to be the check for jingle file transfer + return message.needsUploading() + && message.fixCounterpart(); // No clue why - but this seems to be the check for jingle file transfer } } |