mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 07:52:18 +03:00
Merge remote-tracking branch 'origin/master' into dev
This commit is contained in:
commit
880ad62cf5
6 changed files with 215 additions and 119 deletions
|
@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
@ -174,15 +175,22 @@ public class UploadStorageManagerTest extends AbstractIT {
|
|||
}
|
||||
}
|
||||
|
||||
public String generateUniqueNumber() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
private OCUpload createUpload(Account account) {
|
||||
OCUpload upload = new OCUpload(File.separator + "very long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long LocalPath",
|
||||
"long long long long long long long LocalPath " +
|
||||
generateUniqueNumber(),
|
||||
OCFile.PATH_SEPARATOR + "very long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long RemotePath",
|
||||
"long long long long long long long long long long long long RemotePath " +
|
||||
generateUniqueNumber(),
|
||||
account.name);
|
||||
|
||||
upload.setFileSize(new Random().nextInt(20000) * 10000);
|
||||
|
|
|
@ -384,6 +384,12 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name="androidx.work.impl.foreground.SystemForegroundService"
|
||||
android:directBootAware="false"
|
||||
android:enabled="@bool/enable_system_foreground_service_default"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
<service
|
||||
android:name=".services.OperationsService"
|
||||
android:exported="false" />
|
||||
|
|
|
@ -25,9 +25,12 @@ package com.nextcloud.client.jobs
|
|||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.text.TextUtils
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import androidx.work.Worker
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.ForegroundInfo
|
||||
import androidx.work.WorkerParameters
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
|
@ -37,6 +40,7 @@ import com.owncloud.android.R
|
|||
import com.owncloud.android.datamodel.ArbitraryDataProvider
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
|
||||
import com.owncloud.android.datamodel.FilesystemDataProvider
|
||||
import com.owncloud.android.datamodel.ForegroundServiceType
|
||||
import com.owncloud.android.datamodel.MediaFolderType
|
||||
import com.owncloud.android.datamodel.SyncedFolder
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider
|
||||
|
@ -45,6 +49,7 @@ import com.owncloud.android.files.services.FileUploader
|
|||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
import com.owncloud.android.ui.activity.SettingsActivity
|
||||
import com.owncloud.android.ui.notifications.NotificationUtils
|
||||
import com.owncloud.android.utils.FileStorageUtils
|
||||
import com.owncloud.android.utils.FilesSyncHelper
|
||||
import com.owncloud.android.utils.MimeType
|
||||
|
@ -66,16 +71,38 @@ class FilesSyncWork(
|
|||
private val powerManagementService: PowerManagementService,
|
||||
private val syncedFolderProvider: SyncedFolderProvider,
|
||||
private val backgroundJobManager: BackgroundJobManager
|
||||
) : Worker(context, params) {
|
||||
) : CoroutineWorker(context, params) {
|
||||
|
||||
companion object {
|
||||
const val TAG = "FilesSyncJob"
|
||||
const val SKIP_CUSTOM = "skipCustom"
|
||||
const val OVERRIDE_POWER_SAVING = "overridePowerSaving"
|
||||
const val FOREGROUND_SERVICE_ID = 414
|
||||
}
|
||||
|
||||
override fun doWork(): Result {
|
||||
@Suppress("MagicNumber")
|
||||
private fun createForegroundInfo(progressPercent: Int): ForegroundInfo {
|
||||
// update throughout worker execution to give use feedback how far worker is
|
||||
|
||||
val notification = NotificationCompat.Builder(context, NotificationUtils.NOTIFICATION_CHANNEL_FILE_SYNC)
|
||||
.setTicker(context.getString(R.string.autoupload_worker_foreground_info))
|
||||
.setContentText(context.getString(R.string.autoupload_worker_foreground_info))
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setContentTitle(context.getString(R.string.autoupload_worker_foreground_info))
|
||||
.setOngoing(true)
|
||||
.setProgress(100, progressPercent, false)
|
||||
.build()
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ForegroundInfo(FOREGROUND_SERVICE_ID, notification, ForegroundServiceType.DataSync.getId())
|
||||
} else {
|
||||
ForegroundInfo(FOREGROUND_SERVICE_ID, notification)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
override suspend fun doWork(): Result {
|
||||
backgroundJobManager.logStartOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class))
|
||||
setForeground(createForegroundInfo(0))
|
||||
|
||||
val overridePowerSaving = inputData.getBoolean(OVERRIDE_POWER_SAVING, false)
|
||||
// If we are in power save mode, better to postpone upload
|
||||
|
@ -93,13 +120,18 @@ class FilesSyncWork(
|
|||
connectivityService,
|
||||
powerManagementService
|
||||
)
|
||||
setForeground(createForegroundInfo(5))
|
||||
FilesSyncHelper.insertAllDBEntries(skipCustom, syncedFolderProvider)
|
||||
setForeground(createForegroundInfo(50))
|
||||
// Create all the providers we'll need
|
||||
val filesystemDataProvider = FilesystemDataProvider(contentResolver)
|
||||
val currentLocale = resources.configuration.locale
|
||||
val dateFormat = SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale)
|
||||
dateFormat.timeZone = TimeZone.getTimeZone(TimeZone.getDefault().id)
|
||||
for (syncedFolder in syncedFolderProvider.syncedFolders) {
|
||||
|
||||
val syncedFolders = syncedFolderProvider.syncedFolders
|
||||
for ((index, syncedFolder) in syncedFolders.withIndex()) {
|
||||
setForeground(createForegroundInfo((50 + (index.toDouble() / syncedFolders.size.toDouble()) * 50).toInt()))
|
||||
if (syncedFolder.isEnabled && (!skipCustom || MediaFolderType.CUSTOM != syncedFolder.type)) {
|
||||
syncFolder(
|
||||
context,
|
||||
|
|
|
@ -55,10 +55,10 @@ public class FilesystemDataProvider {
|
|||
|
||||
public int deleteAllEntriesForSyncedFolder(String syncedFolderId) {
|
||||
return contentResolver.delete(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
|
||||
new String[]{syncedFolderId}
|
||||
);
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
|
||||
new String[]{syncedFolderId}
|
||||
);
|
||||
}
|
||||
|
||||
public void updateFilesystemFileAsSentForUpload(String path, String syncedFolderId) {
|
||||
|
@ -66,12 +66,12 @@ public class FilesystemDataProvider {
|
|||
cv.put(ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD, 1);
|
||||
|
||||
contentResolver.update(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
cv,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
|
||||
new String[]{path, syncedFolderId}
|
||||
);
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
cv,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
|
||||
new String[]{path, syncedFolderId}
|
||||
);
|
||||
}
|
||||
|
||||
public Set<String> getFilesForUpload(String localPath, String syncedFolderId) {
|
||||
|
@ -80,20 +80,20 @@ public class FilesystemDataProvider {
|
|||
String likeParam = localPath + "%";
|
||||
|
||||
Cursor cursor = contentResolver.query(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
null,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " LIKE ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " = ?",
|
||||
new String[]{likeParam, syncedFolderId, "0", "0"},
|
||||
null);
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
null,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " LIKE ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " = ?",
|
||||
new String[]{likeParam, syncedFolderId, "0", "0"},
|
||||
null);
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
String value = cursor.getString(cursor.getColumnIndexOrThrow(
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
|
||||
if (value == null) {
|
||||
Log_OC.e(TAG, "Cannot get local path");
|
||||
} else {
|
||||
|
@ -159,11 +159,11 @@ public class FilesystemDataProvider {
|
|||
|
||||
|
||||
int result = contentResolver.update(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
cv,
|
||||
ProviderMeta.ProviderTableMeta._ID + "=?",
|
||||
new String[]{String.valueOf(data.getId())}
|
||||
);
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
cv,
|
||||
ProviderMeta.ProviderTableMeta._ID + "=?",
|
||||
new String[]{String.valueOf(data.getId())}
|
||||
);
|
||||
|
||||
if (result == 0) {
|
||||
Log_OC.v(TAG, "Failed to update filesystem data with local path: " + localPath);
|
||||
|
@ -174,33 +174,33 @@ public class FilesystemDataProvider {
|
|||
private FileSystemDataSet getFilesystemDataSet(String localPathParam, SyncedFolder syncedFolder) {
|
||||
|
||||
Cursor cursor = contentResolver.query(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
null,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
|
||||
new String[]{localPathParam, Long.toString(syncedFolder.getId())},
|
||||
null
|
||||
);
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
|
||||
null,
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " = ? and " +
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
|
||||
new String[]{localPathParam, Long.toString(syncedFolder.getId())},
|
||||
null
|
||||
);
|
||||
|
||||
FileSystemDataSet dataSet = null;
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
int id = cursor.getInt(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta._ID));
|
||||
String localPath = cursor.getString(cursor.getColumnIndexOrThrow(
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
|
||||
long modifiedAt = cursor.getLong(cursor.getColumnIndexOrThrow(
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_MODIFIED));
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_MODIFIED));
|
||||
boolean isFolder = false;
|
||||
if (cursor.getInt(cursor.getColumnIndexOrThrow(
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER)) != 0) {
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER)) != 0) {
|
||||
isFolder = true;
|
||||
}
|
||||
long foundAt = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderMeta.
|
||||
ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY));
|
||||
ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY));
|
||||
|
||||
boolean isSentForUpload = false;
|
||||
if (cursor.getInt(cursor.getColumnIndexOrThrow(
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD)) != 0) {
|
||||
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD)) != 0) {
|
||||
isSentForUpload = true;
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ public class FilesystemDataProvider {
|
|||
Log_OC.e(TAG, "Arbitrary value could not be created from cursor");
|
||||
} else {
|
||||
dataSet = new FileSystemDataSet(id, localPath, modifiedAt, isFolder, isSentForUpload, foundAt,
|
||||
syncedFolder.getId(), crc32);
|
||||
syncedFolder.getId(), crc32);
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
@ -223,11 +223,12 @@ public class FilesystemDataProvider {
|
|||
|
||||
private long getFileChecksum(String filepath) {
|
||||
|
||||
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(filepath))){
|
||||
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(filepath))) {
|
||||
CRC32 crc = new CRC32();
|
||||
int cnt;
|
||||
while ((cnt = inputStream.read()) != -1) {
|
||||
crc.update(cnt);
|
||||
byte[] buf = new byte[1024 * 64];
|
||||
int size;
|
||||
while ((size = inputStream.read(buf)) > 0) {
|
||||
crc.update(buf, 0, size);
|
||||
}
|
||||
|
||||
return crc.getValue();
|
||||
|
|
|
@ -87,6 +87,17 @@ public class UploadsStorageManager extends Observable {
|
|||
* @return upload id, -1 if the insert process fails.
|
||||
*/
|
||||
public long storeUpload(OCUpload ocUpload) {
|
||||
OCUpload existingUpload = getPendingCurrentOrFailedUpload(ocUpload);
|
||||
if (existingUpload != null) {
|
||||
Log_OC.v(TAG, "Will update upload in db since " + ocUpload.getLocalPath() + " already exists as " +
|
||||
"pending, current or failed upload");
|
||||
long existingId = existingUpload.getUploadId();
|
||||
ocUpload.setUploadId(existingId);
|
||||
updateUpload(ocUpload);
|
||||
return existingId;
|
||||
}
|
||||
|
||||
|
||||
Log_OC.v(TAG, "Inserting " + ocUpload.getLocalPath() + " with status=" + ocUpload.getUploadStatus());
|
||||
|
||||
ContentValues cv = getContentValues(ocUpload);
|
||||
|
@ -100,14 +111,26 @@ public class UploadsStorageManager extends Observable {
|
|||
long new_id = Long.parseLong(result.getPathSegments().get(1));
|
||||
ocUpload.setUploadId(new_id);
|
||||
notifyObserversNow();
|
||||
|
||||
return new_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public long[] storeUploads(final List<OCUpload> ocUploads) {
|
||||
Log_OC.v(TAG, "Inserting " + ocUploads.size() + " uploads");
|
||||
ArrayList<ContentProviderOperation> operations = new ArrayList<>(ocUploads.size());
|
||||
for (OCUpload ocUpload : ocUploads) {
|
||||
|
||||
OCUpload existingUpload = getPendingCurrentOrFailedUpload(ocUpload);
|
||||
if (existingUpload != null) {
|
||||
Log_OC.v(TAG, "Will update upload in db since " + ocUpload.getLocalPath() + " already exists as" +
|
||||
" pending, current or failed upload");
|
||||
ocUpload.setUploadId(existingUpload.getUploadId());
|
||||
updateUpload(ocUpload);
|
||||
continue;
|
||||
}
|
||||
|
||||
final ContentProviderOperation operation = ContentProviderOperation
|
||||
.newInsert(ProviderTableMeta.CONTENT_URI_UPLOADS)
|
||||
.withValues(getContentValues(ocUpload))
|
||||
|
@ -173,10 +196,10 @@ public class UploadsStorageManager extends Observable {
|
|||
cv.put(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN, ocUpload.getFolderUnlockToken());
|
||||
|
||||
int result = getDB().update(ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
cv,
|
||||
ProviderTableMeta._ID + "=?",
|
||||
new String[]{String.valueOf(ocUpload.getUploadId())}
|
||||
);
|
||||
cv,
|
||||
ProviderTableMeta._ID + "=?",
|
||||
new String[]{String.valueOf(ocUpload.getUploadId())}
|
||||
);
|
||||
|
||||
Log_OC.d(TAG, "updateUpload returns with: " + result + " for file: " + ocUpload.getLocalPath());
|
||||
if (result != SINGLE_RESULT) {
|
||||
|
@ -198,10 +221,10 @@ public class UploadsStorageManager extends Observable {
|
|||
|
||||
String path = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_PATH));
|
||||
Log_OC.v(
|
||||
TAG,
|
||||
"Updating " + path + " with status:" + status + " and result:"
|
||||
+ (result == null ? "null" : result.toString()) + " (old:"
|
||||
+ upload.toFormattedString() + ')');
|
||||
TAG,
|
||||
"Updating " + path + " with status:" + status + " and result:"
|
||||
+ (result == null ? "null" : result.toString()) + " (old:"
|
||||
+ upload.toFormattedString() + ')');
|
||||
|
||||
upload.setUploadStatus(status);
|
||||
upload.setLastResult(result);
|
||||
|
@ -237,17 +260,17 @@ public class UploadsStorageManager extends Observable {
|
|||
|
||||
int returnValue = 0;
|
||||
Cursor c = getDB().query(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
null,
|
||||
ProviderTableMeta._ID + "=?",
|
||||
new String[]{String.valueOf(id)},
|
||||
null
|
||||
);
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
null,
|
||||
ProviderTableMeta._ID + "=?",
|
||||
new String[]{String.valueOf(id)},
|
||||
null
|
||||
);
|
||||
|
||||
if (c != null) {
|
||||
if (c.getCount() != SINGLE_RESULT) {
|
||||
Log_OC.e(TAG, c.getCount() + " items for id=" + id
|
||||
+ " available in UploadDb. Expected 1. Failed to update upload db.");
|
||||
+ " available in UploadDb. Expected 1. Failed to update upload db.");
|
||||
} else {
|
||||
returnValue = updateUploadInternal(c, status, result, remotePath, localPath);
|
||||
}
|
||||
|
@ -260,8 +283,7 @@ public class UploadsStorageManager extends Observable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Should be called when some value of this DB was changed. All observers
|
||||
* are informed.
|
||||
* Should be called when some value of this DB was changed. All observers are informed.
|
||||
*/
|
||||
public void notifyObserversNow() {
|
||||
Log_OC.d(TAG, "notifyObserversNow");
|
||||
|
@ -311,10 +333,10 @@ public class UploadsStorageManager extends Observable {
|
|||
*/
|
||||
public int removeUpload(String accountName, String remotePath) {
|
||||
int result = getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=? AND " + ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?",
|
||||
new String[]{accountName, remotePath}
|
||||
);
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=? AND " + ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?",
|
||||
new String[]{accountName, remotePath}
|
||||
);
|
||||
Log_OC.d(TAG, "delete returns " + result + " for file " + remotePath + " in " + accountName);
|
||||
if (result > 0) {
|
||||
notifyObserversNow();
|
||||
|
@ -330,10 +352,10 @@ public class UploadsStorageManager extends Observable {
|
|||
*/
|
||||
public int removeUploads(String accountName) {
|
||||
int result = getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
|
||||
new String[]{accountName}
|
||||
);
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
|
||||
new String[]{accountName}
|
||||
);
|
||||
Log_OC.d(TAG, "delete returns " + result + " for uploads in " + accountName);
|
||||
if (result > 0) {
|
||||
notifyObserversNow();
|
||||
|
@ -345,7 +367,34 @@ public class UploadsStorageManager extends Observable {
|
|||
return getUploads(null, (String[]) null);
|
||||
}
|
||||
|
||||
public OCUpload getUploadByRemotePath(String remotePath){
|
||||
public OCUpload getPendingCurrentOrFailedUpload(OCUpload upload) {
|
||||
try (Cursor cursor = getDB().query(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
null,
|
||||
ProviderTableMeta.UPLOADS_REMOTE_PATH + "=? and " +
|
||||
ProviderTableMeta.UPLOADS_LOCAL_PATH + "=? and " +
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=? and (" +
|
||||
ProviderTableMeta.UPLOADS_STATUS + "=? or " +
|
||||
ProviderTableMeta.UPLOADS_STATUS + "=? )",
|
||||
new String[]{
|
||||
upload.getRemotePath(),
|
||||
upload.getLocalPath(),
|
||||
upload.getAccountName(),
|
||||
String.valueOf(UploadStatus.UPLOAD_IN_PROGRESS.value),
|
||||
String.valueOf(UploadStatus.UPLOAD_FAILED.value)
|
||||
},
|
||||
ProviderTableMeta.UPLOADS_REMOTE_PATH + " ASC")) {
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
return createOCUploadFromCursor(cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OCUpload getUploadByRemotePath(String remotePath) {
|
||||
OCUpload result = null;
|
||||
try (Cursor cursor = getDB().query(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
|
@ -492,20 +541,20 @@ public class UploadsStorageManager extends Observable {
|
|||
upload.setFileSize(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_FILE_SIZE)));
|
||||
upload.setUploadId(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta._ID)));
|
||||
upload.setUploadStatus(
|
||||
UploadStatus.fromValue(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_STATUS)))
|
||||
);
|
||||
UploadStatus.fromValue(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_STATUS)))
|
||||
);
|
||||
upload.setLocalAction(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR)));
|
||||
upload.setNameCollisionPolicy(NameCollisionPolicy.deserialize(c.getInt(
|
||||
c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY))));
|
||||
c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY))));
|
||||
upload.setCreateRemoteFolder(c.getInt(
|
||||
c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)) == 1);
|
||||
c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)) == 1);
|
||||
upload.setUploadEndTimestamp(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP)));
|
||||
upload.setLastResult(UploadResult.fromValue(
|
||||
c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LAST_RESULT))));
|
||||
c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LAST_RESULT))));
|
||||
upload.setCreatedBy(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_CREATED_BY)));
|
||||
upload.setUseWifiOnly(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) == 1);
|
||||
upload.setWhileChargingOnly(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY))
|
||||
== 1);
|
||||
== 1);
|
||||
upload.setFolderUnlockToken(c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN)));
|
||||
}
|
||||
return upload;
|
||||
|
@ -599,8 +648,8 @@ public class UploadsStorageManager extends Observable {
|
|||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
user.getAccountName());
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
user.getAccountName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -611,15 +660,15 @@ public class UploadsStorageManager extends Observable {
|
|||
public OCUpload[] getFailedButNotDelayedUploads() {
|
||||
|
||||
return getUploads(ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value + AND +
|
||||
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.LOCK_FAILED.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue(),
|
||||
(String[]) null
|
||||
);
|
||||
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.LOCK_FAILED.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue(),
|
||||
(String[]) null
|
||||
);
|
||||
}
|
||||
|
||||
private ContentResolver getDB() {
|
||||
|
@ -638,10 +687,10 @@ public class UploadsStorageManager extends Observable {
|
|||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
new String[]{user.getAccountName()}
|
||||
);
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
new String[]{user.getAccountName()}
|
||||
);
|
||||
Log_OC.d(TAG, "delete all failed uploads but those delayed for Wifi");
|
||||
if (deleted > 0) {
|
||||
notifyObserversNow();
|
||||
|
@ -673,29 +722,29 @@ public class UploadsStorageManager extends Observable {
|
|||
|
||||
if (uploadResult.isCancelled()) {
|
||||
removeUpload(
|
||||
upload.getUser().getAccountName(),
|
||||
upload.getRemotePath()
|
||||
);
|
||||
upload.getUser().getAccountName(),
|
||||
upload.getRemotePath()
|
||||
);
|
||||
} else {
|
||||
String localPath = (FileUploader.LOCAL_BEHAVIOUR_MOVE == upload.getLocalBehaviour())
|
||||
? upload.getStoragePath() : null;
|
||||
? upload.getStoragePath() : null;
|
||||
|
||||
if (uploadResult.isSuccess()) {
|
||||
updateUploadStatus(
|
||||
upload.getOCUploadId(),
|
||||
UploadStatus.UPLOAD_SUCCEEDED,
|
||||
UploadResult.UPLOADED,
|
||||
upload.getRemotePath(),
|
||||
localPath
|
||||
);
|
||||
upload.getOCUploadId(),
|
||||
UploadStatus.UPLOAD_SUCCEEDED,
|
||||
UploadResult.UPLOADED,
|
||||
upload.getRemotePath(),
|
||||
localPath
|
||||
);
|
||||
} else {
|
||||
updateUploadStatus(
|
||||
upload.getOCUploadId(),
|
||||
UploadStatus.UPLOAD_FAILED,
|
||||
UploadResult.fromOperationResult(uploadResult),
|
||||
upload.getRemotePath(),
|
||||
localPath
|
||||
);
|
||||
upload.getOCUploadId(),
|
||||
UploadStatus.UPLOAD_FAILED,
|
||||
UploadResult.fromOperationResult(uploadResult),
|
||||
upload.getRemotePath(),
|
||||
localPath
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -705,20 +754,19 @@ public class UploadsStorageManager extends Observable {
|
|||
*/
|
||||
public void updateDatabaseUploadStart(UploadFileOperation upload) {
|
||||
String localPath = (FileUploader.LOCAL_BEHAVIOUR_MOVE == upload.getLocalBehaviour())
|
||||
? upload.getStoragePath() : null;
|
||||
? upload.getStoragePath() : null;
|
||||
|
||||
updateUploadStatus(
|
||||
upload.getOCUploadId(),
|
||||
UploadStatus.UPLOAD_IN_PROGRESS,
|
||||
UploadResult.UNKNOWN,
|
||||
upload.getRemotePath(),
|
||||
localPath
|
||||
);
|
||||
upload.getOCUploadId(),
|
||||
UploadStatus.UPLOAD_IN_PROGRESS,
|
||||
UploadResult.UNKNOWN,
|
||||
upload.getRemotePath(),
|
||||
localPath
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the status of any in progress upload from UploadStatus.UPLOAD_IN_PROGRESS
|
||||
* to UploadStatus.UPLOAD_FAILED
|
||||
* Changes the status of any in progress upload from UploadStatus.UPLOAD_IN_PROGRESS to UploadStatus.UPLOAD_FAILED
|
||||
*
|
||||
* @return Number of uploads which status was changed.
|
||||
*/
|
||||
|
|
|
@ -628,6 +628,7 @@
|
|||
<string name="autoupload_hide_folder">Hide folder</string>
|
||||
<string name="autoupload_configure">Configure</string>
|
||||
<string name="synced_folders_configure_folders">Configure folders</string>
|
||||
<string name="autoupload_worker_foreground_info">Preparing auto upload</string>
|
||||
|
||||
<string name="empty" translatable="false" />
|
||||
<string name="test_server_button">Test server connection</string>
|
||||
|
|
Loading…
Reference in a new issue