From d69f0f0a55e79e200be118352c8977a0366fe875 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 11:50:25 +0200 Subject: [PATCH 01/26] Init auto upload on boot Signed-off-by: Mario Danic --- src/main/AndroidManifest.xml | 3 + .../java/com/owncloud/android/MainApp.java | 87 +++++++++++-------- .../files/BootupBroadcastReceiver.java | 8 +- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f0a4268f62f4..5bb0ab5df2ce 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -235,6 +235,9 @@ + + + diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java index 0f4ac2720d3f..d429b17dbe00 100644 --- a/src/main/java/com/owncloud/android/MainApp.java +++ b/src/main/java/com/owncloud/android/MainApp.java @@ -125,26 +125,7 @@ public void onCreate() { Log_OC.d("Debug", "start logging"); } - updateToAutoUpload(); - cleanOldEntries(); - updateAutoUploadEntries(); - - if (PermissionUtil.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - splitOutAutoUploadEntries(); - } else { - PreferenceManager.setAutoUploadSplitEntries(this, true); - } - - initiateExistingAutoUploadEntries(); - - FilesSyncHelper.scheduleFilesSyncIfNeeded(); - FilesSyncHelper.restartJobsIfNeeded(); - - ReceiversHelper.registerNetworkChangeReceiver(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - ReceiversHelper.registerPowerChangeReceiver(); - } + initAutoUpload(); // register global protection with pass code registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @@ -190,6 +171,31 @@ public void onActivityDestroyed(Activity activity) { }); } + public static void initAutoUpload() { + updateToAutoUpload(); + cleanOldEntries(); + updateAutoUploadEntries(); + + if (getAppContext() != null) { + if (PermissionUtil.checkSelfPermission(getAppContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + splitOutAutoUploadEntries(); + } else { + PreferenceManager.setAutoUploadSplitEntries(getAppContext(), true); + } + } + + initiateExistingAutoUploadEntries(); + + FilesSyncHelper.scheduleFilesSyncIfNeeded(); + FilesSyncHelper.restartJobsIfNeeded(); + + ReceiversHelper.registerNetworkChangeReceiver(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + ReceiversHelper.registerPowerChangeReceiver(); + } + } + public static Context getAppContext() { return MainApp.mContext; } @@ -301,12 +307,13 @@ public static String getUserAgent() { return userAgent; } - private void updateToAutoUpload() { - if (PreferenceManager.instantPictureUploadEnabled(this) || - PreferenceManager.instantPictureUploadEnabled(this)) { + private static void updateToAutoUpload() { + Context context = getAppContext(); + if (PreferenceManager.instantPictureUploadEnabled(context) || + PreferenceManager.instantPictureUploadEnabled(context)) { // remove legacy shared preferences - SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); + SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.remove("instant_uploading") .remove("instant_video_uploading") .remove("instant_upload_path") @@ -322,16 +329,16 @@ private void updateToAutoUpload() { // show info pop-up try { - new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog) + new AlertDialog.Builder(context, R.style.Theme_ownCloud_Dialog) .setTitle(R.string.drawer_synced_folders) .setMessage(R.string.synced_folders_new_info) .setPositiveButton(R.string.drawer_open, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // show Auto Upload - Intent folderSyncIntent = new Intent(getApplicationContext(), + Intent folderSyncIntent = new Intent(context, SyncedFoldersActivity.class); dialog.dismiss(); - startActivity(folderSyncIntent); + context.startActivity(folderSyncIntent); } }) .setNegativeButton(R.string.drawer_close, new DialogInterface.OnClickListener() { @@ -347,21 +354,23 @@ public void onClick(DialogInterface dialog, int which) { } } - private void updateAutoUploadEntries() { + private static void updateAutoUploadEntries() { // updates entries to reflect their true paths - if (!PreferenceManager.getAutoUploadPathsUpdate(this)) { + Context context = getAppContext(); + if (!PreferenceManager.getAutoUploadPathsUpdate(context)) { SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext().getContentResolver()); syncedFolderProvider.updateAutoUploadPaths(mContext); } } - private void splitOutAutoUploadEntries() { - if (!PreferenceManager.getAutoUploadSplitEntries(this)) { + private static void splitOutAutoUploadEntries() { + Context context = getAppContext(); + if (!PreferenceManager.getAutoUploadSplitEntries(context)) { // magic to split out existing synced folders in two when needed // otherwise, we migrate them to their proper type (image or video) Log_OC.i(TAG, "Migrate synced_folders records for image/video split"); - ContentResolver contentResolver = this.getContentResolver(); + ContentResolver contentResolver = context.getContentResolver(); SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver); @@ -405,11 +414,11 @@ private void splitOutAutoUploadEntries() { syncedFolderProvider.deleteSyncedFolder(id); } - PreferenceManager.setAutoUploadSplitEntries(this, true); + PreferenceManager.setAutoUploadSplitEntries(context, true); } } - private void initiateExistingAutoUploadEntries() { + private static void initiateExistingAutoUploadEntries() { new Thread(() -> { if (!PreferenceManager.getAutoUploadInit(getAppContext())) { SyncedFolderProvider syncedFolderProvider = @@ -427,13 +436,15 @@ private void initiateExistingAutoUploadEntries() { }).start(); } - private void cleanOldEntries() { + private static void cleanOldEntries() { // previous versions of application created broken entries in the SyncedFolderProvider // database, and this cleans all that and leaves 1 (newest) entry per synced folder - if (!PreferenceManager.getLegacyClean(this)) { + Context context = getAppContext(); + + if (!PreferenceManager.getLegacyClean(context)) { SyncedFolderProvider syncedFolderProvider = - new SyncedFolderProvider(MainApp.getAppContext().getContentResolver()); + new SyncedFolderProvider(context.getContentResolver()); List syncedFolderList = syncedFolderProvider.getSyncedFolders(); Map, Long> syncedFolders = new HashMap<>(); @@ -454,7 +465,7 @@ private void cleanOldEntries() { if (ids.size() > 0) { syncedFolderProvider.deleteSyncedFoldersNotInList(mContext, ids); } else { - PreferenceManager.setLegacyClean(this, true); + PreferenceManager.setLegacyClean(context, true); } } } diff --git a/src/main/java/com/owncloud/android/files/BootupBroadcastReceiver.java b/src/main/java/com/owncloud/android/files/BootupBroadcastReceiver.java index 76d499b69135..ac4be345e938 100644 --- a/src/main/java/com/owncloud/android/files/BootupBroadcastReceiver.java +++ b/src/main/java/com/owncloud/android/files/BootupBroadcastReceiver.java @@ -4,6 +4,7 @@ * @author David A. Velasco * Copyright (C) 2012 Bartek Przybylski * Copyright (C) 2015 ownCloud Inc. + * Copyright (C) 2017 Mario Danic * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -24,6 +25,7 @@ import android.content.Context; import android.content.Intent; +import com.owncloud.android.MainApp; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.services.observer.FileObserverService; @@ -46,13 +48,11 @@ public class BootupBroadcastReceiver extends BroadcastReceiver { */ @Override public void onReceive(Context context, Intent intent) { - if (!intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { - Log_OC.e(TAG, "Incorrect action sent " + intent.getAction()); - return; - } Log_OC.d(TAG, "Starting file observer service..."); Intent initObservers = FileObserverService.makeInitIntent(context); context.startService(initObservers); + + MainApp.initAutoUpload(); } } From 910b038f5bbac1ced6730ac372d8a400d3bef225 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 12:01:22 +0200 Subject: [PATCH 02/26] Update locking code Signed-off-by: Mario Danic --- .../operations/UploadFileOperation.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 0e4d343aa496..a0d1fd30b6cf 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -421,6 +421,8 @@ protected RemoteOperationResult run(OwnCloudClient client) { channel = new RandomAccessFile(mFile.getStoragePath(), "rw").getChannel(); fileLock = channel.tryLock(); } catch (FileNotFoundException e) { + // this basically means that the file is on SD card + // try to copy file to temporary dir if it doesn't exist if (temporalFile == null) { String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); mFile.setStoragePath(temporalPath); @@ -428,24 +430,18 @@ protected RemoteOperationResult run(OwnCloudClient client) { result = copy(originalFile, temporalFile); - if (result != null) { - return result; - } else { + if (result == null) { if (temporalFile.length() == originalFile.length()) { channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel(); fileLock = channel.tryLock(); } else { - while (temporalFile.length() != originalFile.length()) { - Files.deleteIfExists(Paths.get(temporalPath)); - result = copy(originalFile, temporalFile); - - if (result != null) { - return result; - } else { - channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw"). - getChannel(); - fileLock = channel.tryLock(); - } + Files.deleteIfExists(Paths.get(temporalPath)); + result = copy(originalFile, temporalFile); + + if (result == null) { + channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw"). + getChannel(); + fileLock = channel.tryLock(); } } } @@ -455,14 +451,18 @@ protected RemoteOperationResult run(OwnCloudClient client) { } } - result = mUploadOperation.execute(client); + if (result == null) { + result = mUploadOperation.execute(client); + + /// move local temporal file or original file to its corresponding + // location in the ownCloud local folder + if (!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED) { + result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); + } - /// move local temporal file or original file to its corresponding - // location in the ownCloud local folder - if (!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED) { - result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); } + } catch (FileNotFoundException e) { Log_OC.d(TAG, mOriginalStoragePath + " not exists anymore"); result = new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND); @@ -486,6 +486,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { if (temporalFile != null && !originalFile.equals(temporalFile)) { temporalFile.delete(); } + if (result == null) { result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR); } From ccdfdaf1877b9028d6e49a6d36f37df12bcf1c1d Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 12:25:31 +0200 Subject: [PATCH 03/26] Try to get correct size Signed-off-by: Mario Danic --- .../datamodel/UploadsStorageManager.java | 1 + .../operations/UploadFileOperation.java | 56 ++++++++++++------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 9c9ebb6a37a6..9d139771be04 100644 --- a/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -154,6 +154,7 @@ public int updateUpload(OCUpload ocUpload) { cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value); cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue()); cv.put(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP, ocUpload.getUploadEndTimestamp()); + cv.put(ProviderTableMeta.UPLOADS_FILE_SIZE, ocUpload.getFileSize()); int result = getDB().update(ProviderTableMeta.CONTENT_URI_UPLOADS, cv, diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index a0d1fd30b6cf..829757a86e49 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -28,6 +28,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.ThumbnailsCacheManager; +import com.owncloud.android.datamodel.UploadsStorageManager; import com.owncloud.android.db.OCUpload; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.OwnCloudClient; @@ -396,25 +397,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { Long timeStampLong = originalFile.lastModified() / 1000; String timeStamp = timeStampLong.toString(); - /// perform the upload - if (mChunked && - (new File(mFile.getStoragePath())).length() > - ChunkedUploadRemoteFileOperation.CHUNK_SIZE) { - mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); - } else { - mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); - } - - Iterator listener = mDataTransferListeners.iterator(); - while (listener.hasNext()) { - mUploadOperation.addDatatransferProgressListener(listener.next()); - } - - if (mCancellationRequested.get()) { - throw new OperationCancelledException(); - } FileChannel channel = null; try { @@ -451,6 +433,42 @@ protected RemoteOperationResult run(OwnCloudClient client) { } } + long size; + UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), + mContext); + if ((size = mFile.getStoragePath().length()) == 0 && !(new File(mFile.getStoragePath()).isDirectory())) { + size = channel.size(); + } + + for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { + if (ocUpload.getUploadId() == getOCUploadId()) { + ocUpload.setFileSize(size); + uploadsStorageManager.updateUpload(ocUpload); + break; + } + + } + + /// perform the upload + if (mChunked && + (new File(mFile.getStoragePath())).length() > + ChunkedUploadRemoteFileOperation.CHUNK_SIZE) { + mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + } else { + mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + } + + Iterator listener = mDataTransferListeners.iterator(); + while (listener.hasNext()) { + mUploadOperation.addDatatransferProgressListener(listener.next()); + } + + if (mCancellationRequested.get()) { + throw new OperationCancelledException(); + } + if (result == null) { result = mUploadOperation.execute(client); From e08bda58401edd54b3efdfe91246e4e256880773 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 21:13:02 +0200 Subject: [PATCH 04/26] Use new size variable Signed-off-by: Mario Danic --- .../com/owncloud/android/operations/UploadFileOperation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 829757a86e49..80f95678a282 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -451,8 +451,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { /// perform the upload if (mChunked && - (new File(mFile.getStoragePath())).length() > - ChunkedUploadRemoteFileOperation.CHUNK_SIZE) { + (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); } else { From f106872bbb95ec2e38ee1b8c112cacd043c8add2 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 21:31:16 +0200 Subject: [PATCH 05/26] Fix sizing Signed-off-by: Mario Danic --- build.gradle | 2 +- .../com/owncloud/android/operations/UploadFileOperation.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index b122155c88cf..f9b7f9d8318c 100644 --- a/build.gradle +++ b/build.gradle @@ -184,7 +184,7 @@ dependencies { /// dependencies for app building implementation name: 'touch-image-view' implementation 'com.android.support:multidex:1.0.2' - implementation 'com.github.nextcloud:android-library:1.0.26' + implementation 'com.github.nextcloud:android-library:upload-improvements-SNAPSHOT' implementation "com.android.support:support-v4:${supportLibraryVersion}" implementation "com.android.support:design:${supportLibraryVersion}" implementation 'com.jakewharton:disklrucache:2.0.2' diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 80f95678a282..53a07d5fc341 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -453,10 +453,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { if (mChunked && (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); } else { mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); } Iterator listener = mDataTransferListeners.iterator(); From 1aa07679228ebc53e8f27d0f3aef1c7eae16390c Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Fri, 1 Sep 2017 09:34:06 +0200 Subject: [PATCH 06/26] lint: Using dp instead of sp for text sizes --- src/main/res/layout/file_details_share_user_item.xml | 2 +- src/main/res/layout/fingerprintlock.xml | 2 +- src/main/res/layout/upload_list_item.xml | 4 ++-- src/main/res/values/dims.xml | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/res/layout/file_details_share_user_item.xml b/src/main/res/layout/file_details_share_user_item.xml index 16f59de85554..e824daf2778c 100644 --- a/src/main/res/layout/file_details_share_user_item.xml +++ b/src/main/res/layout/file_details_share_user_item.xml @@ -31,7 +31,7 @@ + android:textSize="32sp"/> + android:textSize="@dimen/upload_list_item_text_size"/> + android:textSize="@dimen/upload_list_item_text_size"/> diff --git a/src/main/res/values/dims.xml b/src/main/res/values/dims.xml index 0133ffc07a3f..4fab9ef46f35 100644 --- a/src/main/res/values/dims.xml +++ b/src/main/res/values/dims.xml @@ -71,7 +71,7 @@ 15dp 40dp 240dp - 16dip + 16sp 100dp 2dp 32dp @@ -83,7 +83,6 @@ 180dp 60dp 12sp - 12dip 35dp 12dp 2dp From 1ceb054ea0fdb1526dfb9a0ccc01aeab528989b4 Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot <> Date: Fri, 1 Sep 2017 07:46:23 +0000 Subject: [PATCH 07/26] Drone: update Lint results to reflect reduced error/warning count [skip ci] --- scripts/lint/lint-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint/lint-results.txt b/scripts/lint/lint-results.txt index d551712f07d4..e67c4cbda424 100644 --- a/scripts/lint/lint-results.txt +++ b/scripts/lint/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 1 error and 515 warnings + Lint Report: 1 error and 513 warnings From ffc618795b0fd667bbd2e0976b7490d7f9d41ff3 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Fri, 1 Sep 2017 11:12:21 +0200 Subject: [PATCH 08/26] Restore size Signed-off-by: Mario Danic --- .../com/owncloud/android/operations/UploadFileOperation.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 53a07d5fc341..cfc7ad70e2a2 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -436,8 +436,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { long size; UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext); - if ((size = mFile.getStoragePath().length()) == 0 && !(new File(mFile.getStoragePath()).isDirectory())) { + if (mFile.getStoragePath().length() == 0 && !(new File(mFile.getStoragePath()).isDirectory())) { size = channel.size(); + } else { + size = mFile.getStoragePath().length(); } for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { From 013566a27b7aa3c3c261da730652e4b98f069612 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Mon, 4 Sep 2017 15:46:34 +0200 Subject: [PATCH 09/26] Improve Signed-off-by: Mario Danic --- .../operations/UploadFileOperation.java | 103 +++++++++++------- .../adapter/ExpandableUploadListAdapter.java | 7 +- 2 files changed, 67 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index cfc7ad70e2a2..84e80f42022e 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -52,9 +52,11 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.RequestEntity; +import org.apache.commons.io.input.CountingInputStream; import org.lukhnos.nnio.file.Files; import org.lukhnos.nnio.file.Paths; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -398,72 +400,89 @@ protected RemoteOperationResult run(OwnCloudClient client) { String timeStamp = timeStampLong.toString(); + boolean onSDCard = false; FileChannel channel = null; try { channel = new RandomAccessFile(mFile.getStoragePath(), "rw").getChannel(); fileLock = channel.tryLock(); } catch (FileNotFoundException e) { + onSDCard = true; // this basically means that the file is on SD card // try to copy file to temporary dir if it doesn't exist - if (temporalFile == null) { - String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); - mFile.setStoragePath(temporalPath); - temporalFile = new File(temporalPath); + String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); + mFile.setStoragePath(temporalPath); + temporalFile = new File(temporalPath); - result = copy(originalFile, temporalFile); + Files.deleteIfExists(Paths.get(temporalPath)); + result = copy(originalFile, temporalFile); + + if (result == null) { + if (temporalFile.length() == originalFile.length()) { + channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel(); + fileLock = channel.tryLock(); + } else { + Files.deleteIfExists(Paths.get(temporalPath)); + result = copy(originalFile, temporalFile); - if (result == null) { - if (temporalFile.length() == originalFile.length()) { - channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel(); + if (result == null) { + channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw"). + getChannel(); fileLock = channel.tryLock(); } else { - Files.deleteIfExists(Paths.get(temporalPath)); - result = copy(originalFile, temporalFile); - - if (result == null) { - channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw"). - getChannel(); - fileLock = channel.tryLock(); - } + result = new RemoteOperationResult(ResultCode.LOCK_FAILED); } } - } else { - channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel(); - fileLock = channel.tryLock(); } } - long size; + long size = 0; UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext); - if (mFile.getStoragePath().length() == 0 && !(new File(mFile.getStoragePath()).isDirectory())) { - size = channel.size(); - } else { - size = mFile.getStoragePath().length(); - } + if (result == null) { + if ((mFile.getStoragePath().length() == 0 || onSDCard) && !(new File(mFile.getStoragePath()).isDirectory())) { + size = channel.size(); - for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { - if (ocUpload.getUploadId() == getOCUploadId()) { - ocUpload.setFileSize(size); - uploadsStorageManager.updateUpload(ocUpload); - break; + if (size == 0) { + CountingInputStream countingInputStream = new CountingInputStream(new BufferedInputStream( + new FileInputStream(mFile.getStoragePath()))); + + while (countingInputStream.read() != -1) { + + } + + size = countingInputStream.getByteCount(); + } + } else { + size = mFile.getStoragePath().length(); } - } + for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { + if (ocUpload.getUploadId() == getOCUploadId()) { + ocUpload.setFileSize(size); + uploadsStorageManager.updateUpload(ocUpload); + break; + } - /// perform the upload - if (mChunked && - (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { - mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); - } else { - mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + } } - Iterator listener = mDataTransferListeners.iterator(); - while (listener.hasNext()) { - mUploadOperation.addDatatransferProgressListener(listener.next()); + if (size > 0) { + /// perform the upload + if (mChunked && + (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { + mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + } else { + mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + } + + Iterator listener = mDataTransferListeners.iterator(); + while (listener.hasNext()) { + mUploadOperation.addDatatransferProgressListener(listener.next()); + } + } else { + result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR); } if (mCancellationRequested.get()) { diff --git a/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java index ce42214e3509..77c20b277abc 100755 --- a/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java @@ -237,7 +237,11 @@ private View getView(OCUpload[] uploadsItems, int position, View convertView, Vi // file size TextView fileSizeTextView = (TextView) view.findViewById(R.id.upload_file_size); - fileSizeTextView.setText(DisplayUtils.bytesToHumanReadable(upload.getFileSize()) + ", "); + if (upload.getFileSize() != 0) { + fileSizeTextView.setText(DisplayUtils.bytesToHumanReadable(upload.getFileSize()) + ", "); + } else { + fileSizeTextView.setText(""); + } //* upload date TextView uploadDateTextView = (TextView) view.findViewById(R.id.upload_date); @@ -269,6 +273,7 @@ private View getView(OCUpload[] uploadsItems, int position, View convertView, Vi /// Reset fields visibility uploadDateTextView.setVisibility(View.VISIBLE); pathTextView.setVisibility(View.VISIBLE); + fileSizeTextView.setVisibility(View.VISIBLE); accountNameTextView.setVisibility(View.VISIBLE); statusTextView.setVisibility(View.VISIBLE); From 6e309a6e5784ae61ab2878e3baa11cf8ad3ce322 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Mon, 4 Sep 2017 16:03:19 +0200 Subject: [PATCH 10/26] Fix Signed-off-by: Mario Danic --- .../com/owncloud/android/operations/UploadFileOperation.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 84e80f42022e..3695d158b2b8 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -428,8 +428,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw"). getChannel(); fileLock = channel.tryLock(); - } else { - result = new RemoteOperationResult(ResultCode.LOCK_FAILED); } } } From a0294b7e17fe86ac0f0b63476fccf6713b521db8 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Mon, 4 Sep 2017 18:05:28 +0200 Subject: [PATCH 11/26] Fix local uploads Signed-off-by: Mario Danic --- .../com/owncloud/android/operations/UploadFileOperation.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 3695d158b2b8..11511102a2fb 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -479,8 +479,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { while (listener.hasNext()) { mUploadOperation.addDatatransferProgressListener(listener.next()); } - } else { - result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR); } if (mCancellationRequested.get()) { From 3e914da3414747fb74dbc92b81e9d3c75dc41d59 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 10:15:14 +0200 Subject: [PATCH 12/26] Fix service Signed-off-by: Mario Danic --- .../com/owncloud/android/files/services/FileDownloader.java | 3 +++ .../java/com/owncloud/android/files/services/FileUploader.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/src/main/java/com/owncloud/android/files/services/FileDownloader.java index a44cc4be49b8..c0e3f8969370 100644 --- a/src/main/java/com/owncloud/android/files/services/FileDownloader.java +++ b/src/main/java/com/owncloud/android/files/services/FileDownloader.java @@ -28,6 +28,7 @@ import android.app.PendingIntent; import android.app.Service; import android.content.Intent; +import android.graphics.BitmapFactory; import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; @@ -127,6 +128,8 @@ public void onCreate() { mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext(). getResources().getString(R.string.app_name)) + .setSmallIcon(R.mipmap.ic_launcher) + .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .build(); // add AccountsUpdatedListener diff --git a/src/main/java/com/owncloud/android/files/services/FileUploader.java b/src/main/java/com/owncloud/android/files/services/FileUploader.java index 7e1d4de507a9..56d5c85b2295 100644 --- a/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -33,6 +33,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.graphics.BitmapFactory; import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; @@ -418,6 +419,8 @@ public void onCreate() { mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext(). getResources().getString(R.string.app_name)) + .setSmallIcon(R.mipmap.ic_launcher) + .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .build(); int failedCounter = mUploadsStorageManager.failInProgressUploads( From 0e0a6ac241447ac6ea65c91d9d84628898fc019d Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 11:17:30 +0200 Subject: [PATCH 13/26] Try to fix Signed-off-by: Mario Danic --- .../operations/UploadFileOperation.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 11511102a2fb..2ae8b851d47b 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -436,7 +436,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { long size = 0; UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext); - if (result == null) { + if (result == null || result.isSuccess()) { if ((mFile.getStoragePath().length() == 0 || onSDCard) && !(new File(mFile.getStoragePath()).isDirectory())) { size = channel.size(); @@ -468,11 +468,21 @@ protected RemoteOperationResult run(OwnCloudClient client) { /// perform the upload if (mChunked && (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { - mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + if (mFile.getStoragePath().length() == 0) { + mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + } else { + mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + } } else { - mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + if (mFile.getStoragePath().length() == 0) { + mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); + } else { + mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + } } Iterator listener = mDataTransferListeners.iterator(); @@ -485,7 +495,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { throw new OperationCancelledException(); } - if (result == null) { + if (result == null || result.isSuccess()) { result = mUploadOperation.execute(client); /// move local temporal file or original file to its corresponding From 9887e0fc07c43f39f9502003f3de2c96b23cdbe4 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 11:19:17 +0200 Subject: [PATCH 14/26] Set failed locking Signed-off-by: Mario Danic --- .../owncloud/android/operations/UploadFileOperation.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 2ae8b851d47b..972c56401f60 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -421,14 +421,8 @@ protected RemoteOperationResult run(OwnCloudClient client) { channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel(); fileLock = channel.tryLock(); } else { - Files.deleteIfExists(Paths.get(temporalPath)); - result = copy(originalFile, temporalFile); + result = new RemoteOperationResult(ResultCode.LOCK_FAILED); - if (result == null) { - channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw"). - getChannel(); - fileLock = channel.tryLock(); - } } } } From 3c10dfedfdf51ee46a50ed873a26af9aba6f28ed Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 11:20:02 +0200 Subject: [PATCH 15/26] Check if upload operation is null Signed-off-by: Mario Danic --- .../com/owncloud/android/operations/UploadFileOperation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 972c56401f60..0197060a9860 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -422,7 +422,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { fileLock = channel.tryLock(); } else { result = new RemoteOperationResult(ResultCode.LOCK_FAILED); - } } } @@ -489,7 +488,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { throw new OperationCancelledException(); } - if (result == null || result.isSuccess()) { + if (result == null || result.isSuccess() && mUploadOperation != null) { result = mUploadOperation.execute(client); /// move local temporal file or original file to its corresponding From b3a3d25186fffba20d951425ddd7c6b86491d96b Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 11:27:07 +0200 Subject: [PATCH 16/26] Fix coloring Signed-off-by: Mario Danic --- .../com/owncloud/android/files/services/FileDownloader.java | 6 ++++-- .../com/owncloud/android/files/services/FileUploader.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/src/main/java/com/owncloud/android/files/services/FileDownloader.java index c0e3f8969370..51374b1a677d 100644 --- a/src/main/java/com/owncloud/android/files/services/FileDownloader.java +++ b/src/main/java/com/owncloud/android/files/services/FileDownloader.java @@ -60,6 +60,7 @@ import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.ErrorMessageAdapter; +import com.owncloud.android.utils.ThemeUtils; import java.io.File; import java.util.AbstractList; @@ -128,8 +129,9 @@ public void onCreate() { mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext(). getResources().getString(R.string.app_name)) - .setSmallIcon(R.mipmap.ic_launcher) - .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) + .setSmallIcon(R.drawable.notification_icon) + .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon)) + .setColor(ThemeUtils.primaryColor()) .build(); // add AccountsUpdatedListener diff --git a/src/main/java/com/owncloud/android/files/services/FileUploader.java b/src/main/java/com/owncloud/android/files/services/FileUploader.java index 56d5c85b2295..afe2ca87a19f 100644 --- a/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -72,6 +72,7 @@ import com.owncloud.android.ui.activity.UploadListActivity; import com.owncloud.android.ui.notifications.NotificationUtils; import com.owncloud.android.utils.ErrorMessageAdapter; +import com.owncloud.android.utils.ThemeUtils; import java.io.File; import java.util.AbstractList; @@ -419,8 +420,9 @@ public void onCreate() { mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext(). getResources().getString(R.string.app_name)) - .setSmallIcon(R.mipmap.ic_launcher) - .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) + .setSmallIcon(R.drawable.notification_icon) + .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon)) + .setColor(ThemeUtils.primaryColor()) .build(); int failedCounter = mUploadsStorageManager.failInProgressUploads( From 913e8659a9a0bea3bca6b9a5f495c9aa91a6f8c5 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 13:08:34 +0200 Subject: [PATCH 17/26] Fix empty notification Signed-off-by: Mario Danic --- .../com/owncloud/android/files/services/FileDownloader.java | 1 + .../java/com/owncloud/android/files/services/FileUploader.java | 1 + src/main/res/values/strings.xml | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/src/main/java/com/owncloud/android/files/services/FileDownloader.java index 51374b1a677d..5cd2bc550f1a 100644 --- a/src/main/java/com/owncloud/android/files/services/FileDownloader.java +++ b/src/main/java/com/owncloud/android/files/services/FileDownloader.java @@ -129,6 +129,7 @@ public void onCreate() { mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext(). getResources().getString(R.string.app_name)) + .setContentText(getApplicationContext().getResources().getString(R.string.foreground_service_download)) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon)) .setColor(ThemeUtils.primaryColor()) diff --git a/src/main/java/com/owncloud/android/files/services/FileUploader.java b/src/main/java/com/owncloud/android/files/services/FileUploader.java index afe2ca87a19f..78e18d68cada 100644 --- a/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -420,6 +420,7 @@ public void onCreate() { mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext(). getResources().getString(R.string.app_name)) + .setContentText(getApplicationContext().getResources().getString(R.string.foreground_service_upload)) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon)) .setColor(ThemeUtils.primaryColor()) diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 289ca1180642..dae56a0befeb 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -695,4 +695,7 @@ Use your fingerprint to unlock the app BACK Go back to old login method + + Uploading files... + Downloading files... From 3539413c89ea63b2e4aeed49f4b32f7b50e97aed Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 13:43:33 +0200 Subject: [PATCH 18/26] Simplify Signed-off-by: Mario Danic --- .../operations/UploadFileOperation.java | 72 ++++++------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 0197060a9860..2735a57f5b09 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -52,11 +52,9 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.RequestEntity; -import org.apache.commons.io.input.CountingInputStream; import org.lukhnos.nnio.file.Files; import org.lukhnos.nnio.file.Paths; -import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -426,62 +424,38 @@ protected RemoteOperationResult run(OwnCloudClient client) { } } - long size = 0; UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext); - if (result == null || result.isSuccess()) { - if ((mFile.getStoragePath().length() == 0 || onSDCard) && !(new File(mFile.getStoragePath()).isDirectory())) { - size = channel.size(); - - if (size == 0) { - CountingInputStream countingInputStream = new CountingInputStream(new BufferedInputStream( - new FileInputStream(mFile.getStoragePath()))); - - while (countingInputStream.read() != -1) { - } + long size = 0; + try { + size = channel.size(); + } catch (IOException e1) { + size = new File(mFile.getStoragePath()).length(); + } - size = countingInputStream.getByteCount(); - } - } else { - size = mFile.getStoragePath().length(); + for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { + if (ocUpload.getUploadId() == getOCUploadId()) { + ocUpload.setFileSize(size); + uploadsStorageManager.updateUpload(ocUpload); + break; } + } - for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { - if (ocUpload.getUploadId() == getOCUploadId()) { - ocUpload.setFileSize(size); - uploadsStorageManager.updateUpload(ocUpload); - break; - } + /// perform the upload + if (mChunked && + (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { + mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); + } else { - } + mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), + mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); } - if (size > 0) { - /// perform the upload - if (mChunked && - (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) { - if (mFile.getStoragePath().length() == 0) { - mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); - } else { - mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); - } - } else { - if (mFile.getStoragePath().length() == 0) { - mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp, size); - } else { - mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), - mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict(), timeStamp); - } - } - - Iterator listener = mDataTransferListeners.iterator(); - while (listener.hasNext()) { - mUploadOperation.addDatatransferProgressListener(listener.next()); - } + Iterator listener = mDataTransferListeners.iterator(); + while (listener.hasNext()) { + mUploadOperation.addDatatransferProgressListener(listener.next()); } if (mCancellationRequested.get()) { From f87827c9817177dfc5c325c3796ceee5d1009a3f Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 13:45:49 +0200 Subject: [PATCH 19/26] Store size before going anywhere Signed-off-by: Mario Danic --- .../android/operations/UploadFileOperation.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 2735a57f5b09..19f0512be02c 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -320,6 +320,19 @@ protected RemoteOperationResult run(OwnCloudClient client) { File expectedFile = null; FileLock fileLock = null; + UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), + mContext); + + long size = new File(mFile.getStoragePath()).length(); + + for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { + if (ocUpload.getUploadId() == getOCUploadId()) { + ocUpload.setFileSize(size); + uploadsStorageManager.updateUpload(ocUpload); + break; + } + } + try { /// Check that connectivity conditions are met and delays the upload otherwise @@ -424,10 +437,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { } } - UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), - mContext); - - long size = 0; try { size = channel.size(); } catch (IOException e1) { From bad8fd9c9ab83689d9007a21b3e2f24a17074d85 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 13:47:59 +0200 Subject: [PATCH 20/26] Fix Signed-off-by: Mario Danic --- .../com/owncloud/android/operations/UploadFileOperation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 19f0512be02c..30f46ece5f20 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -323,7 +323,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext); - long size = new File(mFile.getStoragePath()).length(); + long size = 0; for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) { if (ocUpload.getUploadId() == getOCUploadId()) { @@ -332,7 +332,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { break; } } - + try { /// Check that connectivity conditions are met and delays the upload otherwise From 040ef3fc8c0cacabbae0229e88681964aa3bde42 Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Tue, 5 Sep 2017 13:48:37 +0200 Subject: [PATCH 21/26] replace ... with … --- gradle.properties | 21 +++++++++++++++++++++ src/main/res/values/strings.xml | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index e8b10e2b5cbb..6c24c840ca83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,22 @@ +## Project-wide Gradle settings. +# +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Tue Sep 05 11:44:24 CEST 2017 +systemProp.https.nonProxyHosts=localhost +systemProp.https.proxyPort=3128 +systemProp.http.proxyHost=proxy.msg.de +systemProp.http.nonProxyHosts=localhost +systemProp.https.proxyHost=proxy.msg.de +systemProp.http.proxyPort=3128 android.enableAapt2=false diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index dae56a0befeb..69c3843be699 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -696,6 +696,6 @@ BACK Go back to old login method - Uploading files... - Downloading files... + Uploading files… + Downloading files… From ae3035f4f4f25b539810b875ba1968af5afa40cd Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Tue, 5 Sep 2017 13:55:43 +0200 Subject: [PATCH 22/26] cleanup gradle settings --- gradle.properties | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6c24c840ca83..e8b10e2b5cbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,22 +1 @@ -## Project-wide Gradle settings. -# -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx1024m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -# -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -#Tue Sep 05 11:44:24 CEST 2017 -systemProp.https.nonProxyHosts=localhost -systemProp.https.proxyPort=3128 -systemProp.http.proxyHost=proxy.msg.de -systemProp.http.nonProxyHosts=localhost -systemProp.https.proxyHost=proxy.msg.de -systemProp.http.proxyPort=3128 android.enableAapt2=false From 96372f4981019af827484b7ac685b8d98f0eb887 Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Tue, 5 Sep 2017 14:18:11 +0200 Subject: [PATCH 23/26] codacy: remove unused variable --- .../com/owncloud/android/operations/UploadFileOperation.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 30f46ece5f20..9fa3f43d40d4 100644 --- a/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -410,14 +410,11 @@ protected RemoteOperationResult run(OwnCloudClient client) { Long timeStampLong = originalFile.lastModified() / 1000; String timeStamp = timeStampLong.toString(); - - boolean onSDCard = false; FileChannel channel = null; try { channel = new RandomAccessFile(mFile.getStoragePath(), "rw").getChannel(); fileLock = channel.tryLock(); } catch (FileNotFoundException e) { - onSDCard = true; // this basically means that the file is on SD card // try to copy file to temporary dir if it doesn't exist String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); From b353fb254d6705531ceb8eda7a997dec361f38ad Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 5 Sep 2017 14:25:18 +0200 Subject: [PATCH 24/26] Use old lib Signed-off-by: Mario Danic --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f9b7f9d8318c..045e2cd82631 100644 --- a/build.gradle +++ b/build.gradle @@ -184,7 +184,7 @@ dependencies { /// dependencies for app building implementation name: 'touch-image-view' implementation 'com.android.support:multidex:1.0.2' - implementation 'com.github.nextcloud:android-library:upload-improvements-SNAPSHOT' + implementation 'com.github.nextcloud:android-library:1.0.27' implementation "com.android.support:support-v4:${supportLibraryVersion}" implementation "com.android.support:design:${supportLibraryVersion}" implementation 'com.jakewharton:disklrucache:2.0.2' From d5333ebaa81fc542d60d0ed0ab5127b0dba7a147 Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot <> Date: Tue, 5 Sep 2017 12:29:57 +0000 Subject: [PATCH 25/26] Drone: update Lint results to reflect reduced error/warning count [skip ci] --- scripts/lint/lint-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint/lint-results.txt b/scripts/lint/lint-results.txt index e67c4cbda424..00f8637331de 100644 --- a/scripts/lint/lint-results.txt +++ b/scripts/lint/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 1 error and 513 warnings + Lint Report: 1 error and 512 warnings From 761c9f8ce9938c72e5f7df80aba381b9c1d1eb3d Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Tue, 5 Sep 2017 15:21:07 +0200 Subject: [PATCH 26/26] bump to com.github.nextcloud:android-library:1.0.28 fixing chunked upload file modification date --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 045e2cd82631..527aac2327ba 100644 --- a/build.gradle +++ b/build.gradle @@ -184,7 +184,7 @@ dependencies { /// dependencies for app building implementation name: 'touch-image-view' implementation 'com.android.support:multidex:1.0.2' - implementation 'com.github.nextcloud:android-library:1.0.27' + implementation 'com.github.nextcloud:android-library:1.0.28' implementation "com.android.support:support-v4:${supportLibraryVersion}" implementation "com.android.support:design:${supportLibraryVersion}" implementation 'com.jakewharton:disklrucache:2.0.2'