Commit 3c50ba67 authored by Adrien Béraud's avatar Adrien Béraud

Revert "datatransfer: use new API"

This reverts commit e7c9e570.

Reason for revert: wip

Change-Id: If03c88b17fd02f740e8a9b01b18768cc328533bf
parent a40bac52
......@@ -181,8 +181,8 @@ STATIC_LIBS_ALL="-llog -lOpenSLES -landroid \
-lyaml-cpp -ljsoncpp -lhttp_parser -lfmt\
-luuid -lz -ldl \
-lvpx -lopus -lspeex -lspeexdsp -lx264 \
-lgit2 \
-largon2 \
-lgit2 \
-liconv"
LIBRING_JNI_DIR=${ANDROID_APP_DIR}/app/src/main/libs/${ANDROID_ABI}
......
......@@ -759,13 +759,13 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
return;
}
requireActivity().startService(new Intent(DRingService.ACTION_FILE_ACCEPT, ConversationPath.toUri(accountId, conversationUri), requireContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId()));
}
@Override
public void refuseFile(String accountId, Uri conversationUri, DataTransfer transfer) {
requireActivity().startService(new Intent(DRingService.ACTION_FILE_CANCEL, ConversationPath.toUri(accountId, conversationUri), requireContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId()));
}
@Override
......
......@@ -651,7 +651,7 @@ public class DRingService extends Service {
}
private void handleFileAction(android.net.Uri uri, String action, Bundle extras) {
String id = extras.getString(KEY_TRANSFER_ID);
long id = extras.getLong(KEY_TRANSFER_ID);
ConversationPath path = ConversationPath.fromUri(uri);
if (action.equals(ACTION_FILE_ACCEPT)) {
mNotificationService.removeTransferNotification(path.getAccountId(), path.getConversationUri(), id);
......
......@@ -71,7 +71,7 @@ public class DeviceRuntimeServiceImpl extends DeviceRuntimeService {
@Override
public void loadNativeLibrary() {
//mExecutor.execute(() -> {
mExecutor.execute(() -> {
try {
System.loadLibrary("ring");
} catch (Exception e) {
......@@ -79,7 +79,7 @@ public class DeviceRuntimeServiceImpl extends DeviceRuntimeService {
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
//});
});
}
@Override
......
......@@ -471,12 +471,12 @@ public class NotificationServiceImpl implements NotificationService {
if (!remove) {
showFileTransferNotification(conversation, transfer);
} else {
removeTransferNotification(ConversationPath.toUri(conversation), transfer.getFileId());
removeTransferNotification(ConversationPath.toUri(conversation), transfer.getDaemonId());
}
}
@Override
public void removeTransferNotification(String accountId, Uri conversationUri, String transferId) {
public void removeTransferNotification(String accountId, Uri conversationUri, long transferId) {
removeTransferNotification(ConversationPath.toUri(accountId, conversationUri), transferId);
}
......@@ -485,7 +485,7 @@ public class NotificationServiceImpl implements NotificationService {
*
* @param transferId the transfer id which is required to generate the notification id
*/
public void removeTransferNotification(android.net.Uri path, String transferId) {
public void removeTransferNotification(android.net.Uri path, long transferId) {
int id = getFileTransferNotificationId(path, transferId);
dataTransferNotifications.remove(id);
cancelFileNotification(id, false);
......@@ -749,7 +749,7 @@ public class NotificationServiceImpl implements NotificationService {
}
android.net.Uri path = ConversationPath.toUri(conversation);
Log.d(TAG, "showFileTransferNotification " + path);
String dataTransferId = info.getFileId();
long dataTransferId = info.getDaemonId();
int notificationId = getFileTransferNotificationId(path, dataTransferId);
Intent intentConversation = new Intent(DRingService.ACTION_CONV_ACCEPT, path, mContext, DRingService.class);
......@@ -955,7 +955,7 @@ public class NotificationServiceImpl implements NotificationService {
return (NOTIF_MSG + accountId + contact.toString()).hashCode();
}
private int getFileTransferNotificationId(android.net.Uri path, String dataTransferId) {
private int getFileTransferNotificationId(android.net.Uri path, long dataTransferId) {
return (NOTIF_FILE_TRANSFER + path.toString() + dataTransferId).hashCode();
}
......
......@@ -632,13 +632,13 @@ public class TvConversationAdapter extends RecyclerView.Adapter<TvConversationVi
}
context.startService(new Intent(DRingService.ACTION_FILE_ACCEPT)
.setClass(context.getApplicationContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, file.getFileId()));
.putExtra(DRingService.KEY_TRANSFER_ID, file.getDaemonId()));
});
viewHolder.btnRefuse.setOnClickListener(v -> {
Context context = v.getContext();
context.startService(new Intent(DRingService.ACTION_FILE_CANCEL)
.setClass(context.getApplicationContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, file.getFileId()));
.putExtra(DRingService.KEY_TRANSFER_ID, file.getDaemonId()));
});
} else {
viewHolder.mAnswerLayout.setVisibility(View.GONE);
......
......@@ -807,7 +807,7 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres
requireActivity().startService(new Intent(DRingService.ACTION_FILE_ACCEPT)
.setClass(requireContext(), DRingService.class)
.setData(ConversationPath.toUri(accountId, conversationUri))
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId()));
}
@Override
......@@ -815,7 +815,7 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres
requireActivity().startService(new Intent(DRingService.ACTION_FILE_CANCEL)
.setClass(requireContext(), DRingService.class)
.setData(ConversationPath.toUri(accountId, conversationUri))
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId()));
}
}
......@@ -267,24 +267,18 @@ public class ConversationFacade {
}
public Completable sendFile(Conversation conversation, Uri to, File file) {
if (file == null || !file.exists() || !file.canRead()) {
Log.w(TAG, "sendFile: file not found or not readable: " + file);
return null;
}
if (conversation.isSwarm()) {
mAccountService.sendFile(conversation, file);
return Completable.complete();
}
return Single.fromCallable(() -> {
/*if (file == null || !file.exists() || !file.canRead()) {
if (file == null || !file.exists() || !file.canRead()) {
Log.w(TAG, "sendFile: file not found or not readable: " + file);
return null;
}*/
}
DataTransfer transfer = new DataTransfer(conversation, to.getRawRingId(), conversation.getAccountId(), file.getName(), true, file.length(), 0, null);
mHistoryService.insertInteraction(conversation.getAccountId(), conversation, transfer).blockingAwait();
DataTransfer transfer = new DataTransfer(conversation, to.getRawRingId(), conversation.getAccountId(), file.getName(), true, file.length(), 0, 0L);
if (conversation.isSwarm()) {
transfer.setSwarmInfo(conversation.getUri().getRawRingId(), null, null);
} else {
mHistoryService.insertInteraction(conversation.getAccountId(), conversation, transfer).blockingAwait();
}
transfer.destination = mDeviceRuntimeService.getConversationDir(conversation.getUri().getRawRingId());
return transfer;
......@@ -303,7 +297,7 @@ public class ConversationFacade {
if (element.getType() == Interaction.InteractionType.DATA_TRANSFER) {
DataTransfer transfer = (DataTransfer) element;
if (transfer.getStatus() == Interaction.InteractionStatus.TRANSFER_ONGOING) {
mAccountService.cancelDataTransfer(conversation.getAccountId(), conversation.getUri().getRawRingId(), transfer.getFileId());
mAccountService.cancelDataTransfer(conversation.getAccountId(), conversation.getUri().getRawRingId(), transfer.getDaemonId());
} else {
File file = mDeviceRuntimeService.getConversationPath(conversation.getUri().getRawRingId(), transfer.getStoragePath());
mDisposableBag.add(Completable.mergeArrayDelayError(
......@@ -684,10 +678,10 @@ public class ConversationFacade {
});
}
public void cancelFileTransfer(String accountId, Uri conversationId, String fileId) {
mAccountService.cancelDataTransfer(accountId, conversationId.isSwarm() ? conversationId.getRawRingId() : "", fileId);
mNotificationService.removeTransferNotification(accountId, conversationId, fileId);
DataTransfer transfer = mAccountService.getAccount(accountId).getDataTransfer(fileId);
public void cancelFileTransfer(String accountId, Uri conversationId, long id) {
mAccountService.cancelDataTransfer(accountId, conversationId.isSwarm() ? conversationId.getRawRingId() : "", id);
mNotificationService.removeTransferNotification(accountId, conversationId, id);
DataTransfer transfer = mAccountService.getAccount(accountId).getDataTransfer(id);
if (transfer != null)
deleteConversationItem((Conversation) transfer.getConversation(), transfer);
}
......
......@@ -65,7 +65,7 @@ public class Account {
private final Map<String, TrustRequest> mRequests = new HashMap<>();
private final Map<String, Contact> mContactCache = new HashMap<>();
private final Map<String, Conversation> swarmConversations = new HashMap<>();
private final HashMap<String, DataTransfer> mDataTransfers = new HashMap<>();
private final HashMap<Long, DataTransfer> mDataTransfers = new HashMap<>();
private final Map<String, Conversation> conversations = new HashMap<>();
private final Map<String, Conversation> pending = new HashMap<>();
......@@ -379,7 +379,6 @@ public class Account {
}
public Conversation onDataTransferEvent(DataTransfer transfer) {
Log.d(TAG, "Accoount onDataTransferEvent");
Conversation conversation = (Conversation) transfer.getConversation();
Interaction.InteractionStatus transferEventCode = transfer.getStatus();
if (transferEventCode == Interaction.InteractionStatus.TRANSFER_CREATED) {
......@@ -1121,12 +1120,12 @@ public class Account {
mLoadedProfile = profile;
}
public DataTransfer getDataTransfer(String id) {
public DataTransfer getDataTransfer(long id) {
return mDataTransfers.get(id);
}
public void putDataTransfer(String fileId, DataTransfer transfer) {
mDataTransfers.put(fileId, transfer);
public void putDataTransfer(long transferId, DataTransfer transfer) {
mDataTransfers.put(transferId, transfer);
}
private static class ConversationComparator implements Comparator<Conversation> {
......
......@@ -32,7 +32,7 @@ public class DataTransfer extends Interaction {
private long mBytesProgress;
//private final String mPeerId;
private String mExtension;
private String mFileId;
//private String mTransferId;
public File destination;
private static final Set<String> IMAGE_EXTENSIONS = HashUtils.asSet("jpg", "jpeg", "png", "gif");
......@@ -41,8 +41,7 @@ public class DataTransfer extends Interaction {
private static final int MAX_SIZE = 32 * 1024 * 1024;
private static final int UNLIMITED_SIZE = 256 * 1024 * 1024;
/* Legacy constructor */
public DataTransfer(ConversationHistory conversation, String peer, String account, String displayName, boolean isOutgoing, long totalSize, long bytesProgress, String fileId) {
public DataTransfer(ConversationHistory conversation, String peer, String account, String displayName, boolean isOutgoing, long totalSize, long bytesProgress, long daemonId) {
mAuthor = isOutgoing ? null : peer;
mAccount = account;
mConversation = conversation;
......@@ -53,15 +52,8 @@ public class DataTransfer extends Interaction {
mType = InteractionType.DATA_TRANSFER.toString();
mTimestamp = System.currentTimeMillis();
mIsRead = 1;
mDaemonId = daemonId;
mIsIncoming = !isOutgoing;
if (fileId != null) {
mFileId = fileId;
try {
mDaemonId = Long.parseUnsignedLong(fileId);
} catch (Exception e) {
}
}
}
public DataTransfer(Interaction interaction) {
......@@ -80,15 +72,18 @@ public class DataTransfer extends Interaction {
mIsIncoming = interaction.mIsIncoming;//mAuthor != null;
}
public DataTransfer(String fileId, String accountId, String peerUri, String displayName, boolean isOutgoing, long timestamp, long totalSize, long bytesProgress) {
public DataTransfer(long transferId, String accountId, String peerUri, String displayName, boolean isOutgoing, long timestamp, long totalSize, long bytesProgress) {
mDaemonId = transferId;
mAccount = accountId;
mFileId = fileId;
//mTransferId = transferId;
//mPeerId = peerUri;
mBody = displayName;
mAuthor = peerUri;
mIsIncoming = !isOutgoing;
mTotalSize = totalSize;
mBytesProgress = bytesProgress;
mTimestamp = timestamp;
//mDaemonId = Long.parseUnsignedLong(transferId);
mType = InteractionType.DATA_TRANSFER.toString();
}
......@@ -164,8 +159,5 @@ public class DataTransfer extends Interaction {
return maxSize == UNLIMITED_SIZE || getTotalSize() <= maxSize;
}
public String getFileId() {
return mFileId;
}
}
......@@ -29,6 +29,7 @@ import net.jami.daemon.Blob;
import net.jami.daemon.DataTransferInfo;
import net.jami.daemon.JamiService;
import net.jami.daemon.StringMap;
import net.jami.daemon.StringVect;
import net.jami.daemon.UintVect;
import net.jami.model.Account;
import net.jami.model.AccountConfig;
......@@ -1524,11 +1525,10 @@ public class AccountService {
String transferId = message.get("tid");
long tid = Long.parseLong(transferId);
String fileName = message.get("displayName");
String fileId = message.get("fileId");
long fileSize = Long.parseLong(message.get("totalSize"));
interaction = account.getDataTransfer(fileId);
interaction = account.getDataTransfer(tid);
if (interaction == null) {
interaction = new DataTransfer(account.getAccountID(), fileId, author, fileName, contact.isUser(), timestamp, fileSize, 0);
interaction = new DataTransfer(tid, account.getAccountID(), author, fileName, contact.isUser(), timestamp, fileSize, 0);
File path = mDeviceRuntimeService.getConversationPath(conversation.getUri().getRawRingId(), ((DataTransfer) interaction).getStoragePath());
boolean exists = path.exists();
if (exists)
......@@ -1690,7 +1690,7 @@ public class AccountService {
Log.i(TAG, "sendFile() id=" + dataTransfer.getId() + " accountId=" + dataTransferInfo.getAccountId() + ", peer=" + dataTransferInfo.getPeer() + ", filePath=" + dataTransferInfo.getPath());
long[] id = new long[1];
DataTransferError err = getDataTransferError(JamiService.sendFileLegacy(dataTransferInfo, id));
DataTransferError err = getDataTransferError(JamiService.sendFile(dataTransferInfo, id));
if (err != DataTransferError.SUCCESS) {
throw new IOException(err.name());
} else {
......@@ -1701,10 +1701,6 @@ public class AccountService {
}).subscribeOn(Schedulers.from(mExecutor));
}
public void sendFile(Conversation conversation, final File file) {
mExecutor.execute(() -> JamiService.sendFile(conversation.getAccountId(), conversation.getUri().getRawRingId(), file.getAbsolutePath(), file.getName(), ""));
}
public List<net.jami.daemon.Message> getLastMessages(String accountId, long baseTime) {
try {
return mExecutor.submit(() -> SwigNativeConverter.toJava(JamiService.getLastMessages(accountId, baseTime))).get();
......@@ -1714,11 +1710,11 @@ public class AccountService {
return new ArrayList<>();
}
public void acceptFileTransfer(final String accountId, final Uri conversationUri, String fileId) {
public void acceptFileTransfer(final String accountId, final Uri conversationUri, long id) {
Account account = getAccount(accountId);
if (account != null) {
Conversation conversation = account.getByUri(conversationUri);
acceptFileTransfer(conversation, account.getDataTransfer(fileId));
acceptFileTransfer(conversation, account.getDataTransfer(id));
}
}
......@@ -1726,18 +1722,18 @@ public class AccountService {
if (transfer == null)
return;
File path = mDeviceRuntimeService.getTemporaryPath(conversation.getUri().getRawRingId(), transfer.getStoragePath());
Log.i(TAG, "acceptFileTransfer() id=" + transfer.getFileId() + ", path=" + path.getAbsolutePath());
if (conversation.isSwarm()) {
String conversationId = conversation.getUri().getRawRingId();
JamiService.downloadFile(conversation.getAccountId(), conversationId, transfer.getFileId(), path.getAbsolutePath());
} else {
JamiService.acceptFileTransfer(conversation.getAccountId(), transfer.getFileId(), path.getAbsolutePath());
}
String conversationId = conversation.getUri().getRawRingId();
acceptFileTransfer(conversation.getAccountId(), conversationId, transfer.getDaemonId(), path.getAbsolutePath(), 0);
}
public void cancelDataTransfer(final String accountId, final String conversationId, final String fileId) {
Log.i(TAG, "cancelDataTransfer() id=" + fileId);
mExecutor.execute(() -> JamiService.cancelDataTransfer(accountId, conversationId, fileId));
private void acceptFileTransfer(final String accountId, final String conversationId, final Long dataTransferId, final String filePath, long offset) {
Log.i(TAG, "acceptFileTransfer() id=" + dataTransferId + ", path=" + filePath + ", offset=" + offset);
mExecutor.execute(() -> JamiService.acceptFileTransfer(accountId, conversationId, dataTransferId, filePath, offset));
}
public void cancelDataTransfer(final String accountId, final String conversationId, long dataTransferId) {
Log.i(TAG, "cancelDataTransfer() id=" + dataTransferId);
mExecutor.execute(() -> JamiService.cancelDataTransfer(accountId, conversationId, dataTransferId));
}
private class DataTransferRefreshTask implements Runnable {
......@@ -1756,7 +1752,7 @@ public class AccountService {
public void run() {
synchronized (mToUpdate) {
if (mToUpdate.getStatus() == Interaction.InteractionStatus.TRANSFER_ONGOING) {
dataTransferEvent(mAccount, mConversation, mToUpdate.getFileId(), 5);
dataTransferEvent(mAccount, mConversation, mToUpdate.getDaemonId(), 5);
} else {
scheduledTask.cancel(false);
scheduledTask = null;
......@@ -1765,7 +1761,7 @@ public class AccountService {
}
}
void dataTransferEvent(String accountId, String conversationId, final String fileId, int eventCode) {
void dataTransferEvent(String accountId, String conversationId, final long transferId, int eventCode) {
Account account = getAccount(accountId);
if (account != null) {
Conversation conversation = StringUtils.isEmpty(conversationId) ? null : account.getSwarm(conversationId);
......@@ -1773,37 +1769,33 @@ public class AccountService {
conversation = account.getByUri(conversationId);
if (conversation == null)
return;
dataTransferEvent(account, conversation, fileId, eventCode);
dataTransferEvent(account, conversation, transferId, eventCode);
}
}
void dataTransferEvent(Account account, Conversation conversation, final String fileId, int eventCode) {
void dataTransferEvent(Account account, Conversation conversation, final long transferId, int eventCode) {
Interaction.InteractionStatus transferStatus = getDataTransferEventCode(eventCode);
Log.d(TAG, "Data Transfer " + transferStatus);
DataTransferInfo info = new DataTransferInfo();
DataTransferError err = getDataTransferError(JamiService.dataTransferInfo(account.getAccountID(), fileId, info));
if (err != DataTransferError.SUCCESS) {
Log.d(TAG, "Data Transfer error getting details " + err);
if (getDataTransferError(JamiService.dataTransferInfo(account.getAccountID(), conversation.getUri().getRawRingId(), transferId, info)) != DataTransferError.SUCCESS)
return;
}
boolean outgoing = info.getFlags() == 0;
DataTransfer transfer = account.getDataTransfer(fileId);
DataTransfer transfer = account.getDataTransfer(transferId);
if (transfer == null) {
if (outgoing && mStartingTransfer != null) {
Log.d(TAG, "Data Transfer mStartingTransfer");
transfer = mStartingTransfer;
mStartingTransfer = null;
} else {
transfer = new DataTransfer(conversation, info.getPeer(), account.getAccountID(), info.getDisplayName(),
outgoing, info.getTotalSize(),
info.getBytesProgress(), fileId);
info.getBytesProgress(), transferId);
if (conversation.isSwarm()) {
transfer.setSwarmInfo(conversation.getUri().getRawRingId(), null, null);
} else {
mHistoryService.insertInteraction(account.getAccountID(), conversation, transfer).blockingAwait();
}
}
account.putDataTransfer(fileId, transfer);
account.putDataTransfer(transferId, transfer);
} else synchronized (transfer) {
InteractionStatus oldState = transfer.getStatus();
if (oldState != transferStatus) {
......@@ -1832,7 +1824,6 @@ public class AccountService {
}
}
Log.d(TAG, "Data Transfer dataTransferSubject.onNext");
dataTransferSubject.onNext(transfer);
}
......
......@@ -380,9 +380,9 @@ public class DaemonService {
class DaemonDataTransferCallback extends DataTransferCallback {
@Override
public void dataTransferEvent(String accountId, String conversationId, String fileId, int eventCode) {
Log.d(TAG, "dataTransferEvent: conversationId=" + conversationId + ", fileId=" + fileId + ", eventCode=" + eventCode);
mAccountService.dataTransferEvent(accountId, conversationId, fileId, eventCode);
public void dataTransferEvent(String accountId, String conversationId, long transferId, int eventCode) {
Log.d(TAG, "dataTransferEvent: conversationId=" + conversationId + ", transferId=" + transferId + ", eventCode=" + eventCode);
mAccountService.dataTransferEvent(accountId, conversationId, transferId, eventCode);
}
}
......
......@@ -52,7 +52,7 @@ public interface NotificationService {
void showFileTransferNotification(Conversation conversation, DataTransfer info);
void cancelFileNotification(int id, boolean isMigratingToService);
void handleDataTransferNotification(DataTransfer transfer, Conversation contact, boolean remove);
void removeTransferNotification(String accountId, Uri conversationUri, String fileId);
void removeTransferNotification(String accountId, Uri conversationUri, long transferId);
Object getDataTransferNotification(int notificationId);
void updateNotification(Object notification, int notificationId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment