-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build Fix #12111
Merged
AndyScherzinger
merged 4 commits into
master
from
fix/SyncFileNotEnoughSpaceDialogFragment
Oct 31, 2023
Merged
Build Fix #12111
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings | |
import java.io.File | ||
import java.security.SecureRandom | ||
import java.util.AbstractList | ||
import java.util.Vector | ||
import javax.inject.Inject | ||
|
||
class FileDownloader : Service(), OnDatatransferProgressListener, OnAccountsUpdateListener { | ||
|
@@ -184,54 +183,75 @@ class FileDownloader : Service(), OnDatatransferProgressListener, OnAccountsUpda | |
if (!intent.hasExtra(EXTRA_USER) || !intent.hasExtra(EXTRA_FILE)) { | ||
Log_OC.e(TAG, "Not enough information provided in intent") | ||
return START_NOT_STICKY | ||
} else { | ||
val user = intent.getParcelableExtra<User>(EXTRA_USER) | ||
val file = intent.getParcelableExtra<OCFile>(EXTRA_FILE) | ||
val behaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR) | ||
var downloadType: DownloadType? = DownloadType.DOWNLOAD | ||
if (intent.hasExtra(DOWNLOAD_TYPE)) { | ||
downloadType = intent.getSerializableExtra(DOWNLOAD_TYPE) as DownloadType? | ||
} | ||
val activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME) | ||
val packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME) | ||
conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1) | ||
val requestedDownloads: AbstractList<String> = Vector() | ||
try { | ||
val newDownload = DownloadFileOperation( | ||
user, | ||
file, | ||
behaviour, | ||
activityName, | ||
packageName, | ||
baseContext, | ||
downloadType | ||
) | ||
newDownload.addDatatransferProgressListener(this) | ||
newDownload.addDatatransferProgressListener(mBinder as FileDownloaderBinder?) | ||
val putResult = mPendingDownloads.putIfAbsent( | ||
user!!.accountName, | ||
file!!.remotePath, | ||
newDownload | ||
) | ||
if (putResult != null) { | ||
val downloadKey = putResult.first | ||
requestedDownloads.add(downloadKey) | ||
sendBroadcastNewDownload(newDownload, putResult.second) | ||
} // else, file already in the queue of downloads; don't repeat the request | ||
} catch (e: IllegalArgumentException) { | ||
Log_OC.e(TAG, "Not enough information provided in intent: " + e.message) | ||
return START_NOT_STICKY | ||
} | ||
if (requestedDownloads.size > 0) { | ||
val msg = mServiceHandler!!.obtainMessage() | ||
msg.arg1 = startId | ||
msg.obj = requestedDownloads | ||
mServiceHandler!!.sendMessage(msg) | ||
} | ||
|
||
val user = intent.getParcelableExtra<User>(EXTRA_USER) | ||
val file = intent.getParcelableExtra<OCFile>(EXTRA_FILE) | ||
val behaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR) | ||
var downloadType: DownloadType? = DownloadType.DOWNLOAD | ||
if (intent.hasExtra(DOWNLOAD_TYPE)) { | ||
downloadType = intent.getSerializableExtra(DOWNLOAD_TYPE) as DownloadType? | ||
} | ||
val activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME) | ||
val packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME) | ||
conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1) | ||
|
||
val requestedDownloads = handleDownloadRequest(user, file, behaviour, downloadType, activityName, packageName) | ||
|
||
if (requestedDownloads.isNotEmpty()) { | ||
val msg = mServiceHandler?.obtainMessage() | ||
msg?.arg1 = startId | ||
msg?.obj = requestedDownloads | ||
msg?.let { | ||
mServiceHandler?.sendMessage(it) | ||
} | ||
} | ||
|
||
return START_NOT_STICKY | ||
} | ||
|
||
@Suppress("LongParameterList") | ||
private fun handleDownloadRequest( | ||
user: User?, | ||
file: OCFile?, | ||
behaviour: String?, | ||
downloadType: DownloadType?, | ||
activityName: String?, | ||
packageName: String? | ||
): List<String> { | ||
val requestedDownloads: MutableList<String> = ArrayList() | ||
|
||
if (user == null || file == null) { | ||
return requestedDownloads | ||
} | ||
|
||
try { | ||
val newDownload = DownloadFileOperation( | ||
user, | ||
file, | ||
behaviour, | ||
activityName, | ||
packageName, | ||
baseContext, | ||
downloadType | ||
) | ||
newDownload.addDatatransferProgressListener(this) | ||
newDownload.addDatatransferProgressListener(mBinder as FileDownloaderBinder?) | ||
|
||
val putResult = mPendingDownloads.putIfAbsent(user.accountName, file.remotePath, newDownload) | ||
|
||
if (putResult != null) { | ||
val downloadKey = putResult.first | ||
requestedDownloads.add(downloadKey) | ||
sendBroadcastNewDownload(newDownload, putResult.second) | ||
} | ||
} catch (e: IllegalArgumentException) { | ||
Log_OC.e(TAG, "Not enough information provided in intent: " + e.message) | ||
} | ||
|
||
return requestedDownloads | ||
} | ||
|
||
/** | ||
* Provides a binder object that clients can use to perform operations on the queue of downloads, | ||
* excepting the addition of new files. | ||
|
@@ -286,13 +306,9 @@ class FileDownloader : Service(), OnDatatransferProgressListener, OnAccountsUpda | |
if (download != null) { | ||
download.cancel() | ||
} else { | ||
if (mCurrentDownload != null && currentUser.isPresent && | ||
mCurrentDownload!! | ||
.remotePath | ||
.startsWith(file.remotePath) && account.name == currentUser.get().accountName | ||
) { | ||
mCurrentDownload!!.cancel() | ||
} | ||
mCurrentDownload?.takeIf { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix This condition is too complex (4). Defined complexity threshold for conditions is set to '4' |
||
it.remotePath.startsWith(file.remotePath) && account.name == currentUser?.get()?.accountName | ||
}?.cancel() | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,31 +399,34 @@ open class FolderPickerActivity : | |
} | ||
|
||
override fun onClick(v: View) { | ||
if (v == mCancelBtn) { | ||
finish() | ||
} else if (v == mCopyBtn || v == mMoveBtn) { | ||
val i = intent | ||
val resultData = Intent() | ||
resultData.putExtra(EXTRA_FOLDER, listOfFilesFragment!!.currentFile) | ||
val targetFiles = i.getParcelableArrayListExtra<Parcelable>(EXTRA_FILES) | ||
if (targetFiles != null) { | ||
resultData.putParcelableArrayListExtra(EXTRA_FILES, targetFiles) | ||
} | ||
when (v) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix Function onClick is nested too deeply. |
||
mCancelBtn -> finish() | ||
mCopyBtn, mMoveBtn -> copyOrMove(v) | ||
} | ||
} | ||
|
||
mTargetFilePaths.let { | ||
if (it != null) { | ||
if (v == mCopyBtn) { | ||
fileOperationsHelper.moveOrCopyFiles(OperationsService.ACTION_COPY_FILE, it, file) | ||
} else { | ||
fileOperationsHelper.moveOrCopyFiles(OperationsService.ACTION_MOVE_FILE, it, file) | ||
} | ||
} | ||
private fun copyOrMove(v: View) { | ||
val i = intent | ||
val resultData = Intent() | ||
resultData.putExtra(EXTRA_FOLDER, listOfFilesFragment?.currentFile) | ||
|
||
i.getParcelableArrayListExtra<Parcelable>(EXTRA_FILES)?.let { targetFiles -> | ||
resultData.putParcelableArrayListExtra(EXTRA_FILES, targetFiles) | ||
} | ||
|
||
resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, it) | ||
mTargetFilePaths?.let { | ||
val action = when (v) { | ||
mCopyBtn -> OperationsService.ACTION_COPY_FILE | ||
mMoveBtn -> OperationsService.ACTION_MOVE_FILE | ||
else -> throw IllegalArgumentException("Unknown operation") | ||
} | ||
setResult(RESULT_OK, resultData) | ||
finish() | ||
|
||
fileOperationsHelper.moveOrCopyFiles(action, it, file) | ||
resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, it) | ||
} | ||
|
||
setResult(RESULT_OK, resultData) | ||
finish() | ||
} | ||
|
||
override fun onRemoteOperationFinish(operation: RemoteOperation<*>?, result: RemoteOperationResult<*>) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Function onStartCommand has 3 return statements which exceeds the limit of 2.