Merge remote-tracking branch 'origin/master' into dev

This commit is contained in:
Tobias Kaminsky 2023-11-30 02:31:03 +01:00
commit dea86b27da
6 changed files with 78 additions and 28 deletions

View file

@ -137,6 +137,7 @@ interface BackgroundJobManager {
fun startAccountRemovalJob(accountName: String, remoteWipe: Boolean)
fun startFilesUploadJob(user: User)
fun getFileUploads(user: User): LiveData<List<JobInfo>>
fun cancelFilesUploadJob(user: User)
fun startPdfGenerateAndUploadWork(user: User, uploadFolder: String, imagePaths: List<String>, pdfPath: String)

View file

@ -461,6 +461,10 @@ internal class BackgroundJobManagerImpl(
return workInfo.map { it -> it.map { fromWorkInfo(it) ?: JobInfo() } }
}
override fun cancelFilesUploadJob(user: User) {
workManager.cancelJob(JOB_FILES_UPLOAD, user)
}
override fun startPdfGenerateAndUploadWork(
user: User,
uploadFolder: String,

View file

@ -76,6 +76,7 @@ class FilesUploadWorker(
private val notificationManager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private val fileUploaderDelegate = FileUploaderDelegate()
private var currentUploadFileOperation: UploadFileOperation? = null
override fun doWork(): Result {
val accountName = inputData.getString(ACCOUNT)
@ -89,7 +90,7 @@ class FilesUploadWorker(
* they will be present in the pages that follow.
*/
var currentPage = uploadsStorageManager.getCurrentAndPendingUploadsForAccountPageAscById(-1, accountName)
while (currentPage.isNotEmpty()) {
while (currentPage.isNotEmpty() && !isStopped) {
Log_OC.d(TAG, "Handling ${currentPage.size} uploads for account $accountName")
val lastId = currentPage.last().uploadId
handlePendingUploads(currentPage, accountName)
@ -105,11 +106,16 @@ class FilesUploadWorker(
val user = userAccountManager.getUser(accountName)
for (upload in uploads) {
if (isStopped) {
break
}
// create upload file operation
if (user.isPresent) {
val uploadFileOperation = createUploadFileOperation(upload, user.get())
currentUploadFileOperation = uploadFileOperation
val result = upload(uploadFileOperation, user.get())
currentUploadFileOperation = null
fileUploaderDelegate.sendBroadcastUploadFinished(
uploadFileOperation,
@ -172,13 +178,16 @@ class FilesUploadWorker(
Log_OC.e(TAG, "Error uploading", e)
uploadResult = RemoteOperationResult<Any?>(e)
} finally {
uploadsStorageManager.updateDatabaseUploadResult(uploadResult, uploadFileOperation)
// only update db if operation finished and worker didn't get canceled
if (!(isStopped && uploadResult.isCancelled)) {
uploadsStorageManager.updateDatabaseUploadResult(uploadResult, uploadFileOperation)
// / notify result
notifyUploadResult(uploadFileOperation, uploadResult)
// / notify result
notifyUploadResult(uploadFileOperation, uploadResult)
// cancel notification
notificationManager.cancel(FOREGROUND_SERVICE_ID)
// cancel notification
notificationManager.cancel(FOREGROUND_SERVICE_ID)
}
}
return uploadResult
@ -357,6 +366,12 @@ class FilesUploadWorker(
lastPercent = percent
}
override fun onStopped() {
super.onStopped()
currentUploadFileOperation?.cancel(null)
notificationManager.cancel(FOREGROUND_SERVICE_ID)
}
companion object {
val TAG: String = FilesUploadWorker::class.java.simpleName
private const val FOREGROUND_SERVICE_ID: Int = 412

View file

@ -89,6 +89,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;
import javax.inject.Inject;
@ -1152,24 +1153,34 @@ public class FileUploader extends Service
* @param remotePath Remote target of the upload
* @param resultCode Setting result code will pause rather than cancel the job
*/
private void cancel(String accountName, String remotePath, @Nullable ResultCode resultCode) {
Pair<UploadFileOperation, String> removeResult = mPendingUploads.remove(accountName, remotePath);
UploadFileOperation upload = removeResult.first;
if (upload == null && mCurrentUpload != null && mCurrentAccount != null &&
mCurrentUpload.getRemotePath().startsWith(remotePath) && accountName.equals(mCurrentAccount.name)) {
public void cancel(String accountName, String remotePath, @Nullable ResultCode resultCode) {
// Cancel for Android version >= Android 11
if (useFilesUploadWorker(getApplicationContext())){
try{
new FilesUploadHelper().cancelFileUpload(remotePath, accountManager.getUser(accountName).get());
}catch(NoSuchElementException e){
Log_OC.e(TAG,"Error cancelling current upload because user does not exist!");
}
} else {
// Cancel for Android version <= Android 10
Pair<UploadFileOperation, String> removeResult = mPendingUploads.remove(accountName, remotePath);
UploadFileOperation upload = removeResult.first;
if (upload == null && mCurrentUpload != null && mCurrentAccount != null &&
mCurrentUpload.getRemotePath().startsWith(remotePath) && accountName.equals(mCurrentAccount.name)) {
upload = mCurrentUpload;
}
upload = mCurrentUpload;
}
if (upload != null) {
upload.cancel(resultCode);
// need to update now table in mUploadsStorageManager,
// since the operation will not get to be run by FileUploader#uploadFile
if (resultCode != null) {
mUploadsStorageManager.updateDatabaseUploadResult(new RemoteOperationResult(resultCode), upload);
notifyUploadResult(upload, new RemoteOperationResult(resultCode));
} else {
mUploadsStorageManager.removeUpload(accountName, remotePath);
if (upload != null) {
upload.cancel(resultCode);
// need to update now table in mUploadsStorageManager,
// since the operation will not get to be run by FileUploader#uploadFile
if (resultCode != null) {
mUploadsStorageManager.updateDatabaseUploadResult(new RemoteOperationResult(resultCode), upload);
notifyUploadResult(upload, new RemoteOperationResult(resultCode));
} else {
mUploadsStorageManager.removeUpload(accountName, remotePath);
}
}
}
}
@ -1180,16 +1191,19 @@ public class FileUploader extends Service
* @param user Nextcloud user
*/
public void cancel(User user) {
if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(user)) {
mCurrentUpload.cancel(ResultCode.CANCELLED);
}
cancelPendingUploads(user.getAccountName());
cancel(user.getAccountName());
}
public void cancel(String accountName) {
if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(accountName)) {
mCurrentUpload.cancel(ResultCode.CANCELLED);
cancelPendingUploads(accountName);
if (useFilesUploadWorker(getApplicationContext())) {
new FilesUploadHelper().restartUploadJob(accountManager.getUser(accountName).get());
}else{
if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(accountName)) {
mCurrentUpload.cancel(ResultCode.CANCELLED);
}
}
}
public void clearListeners() {

View file

@ -70,6 +70,19 @@ class FilesUploadHelper {
backgroundJobManager.startFilesUploadJob(user)
}
fun cancelFileUpload(remotePath: String, user: User) {
// need to update now table in mUploadsStorageManager,
// since the operation will not get to be run by FileUploader#uploadFile
uploadsStorageManager.removeUpload(user.accountName, remotePath)
restartUploadJob(user)
}
fun restartUploadJob(user: User) {
backgroundJobManager.cancelFilesUploadJob(user)
backgroundJobManager.startFilesUploadJob(user)
}
fun uploadUpdatedFile(
user: User,
existingFiles: Array<OCFile>,

View file

@ -203,6 +203,7 @@
<string name="did_not_check_for_dupes">Nu s-au verificat duplicatele.</string>
<string name="digest_algorithm_not_available">Algoritmul \'digest\' nu este disponibil pe telefonul tău.</string>
<string name="direct_login_failed">Eroare la autentificare prin legătură directă!</string>
<string name="direct_login_text">Autentificare cu %1$s la %2$s</string>
<string name="disable_new_media_folder_detection_notifications">Dezactivează</string>
<string name="dismiss">Elimină</string>
<string name="dismiss_notification_description">Elimină notificarea</string>
@ -440,6 +441,7 @@
<string name="locked_by_app">Blocat de aplicația%1$s </string>
<string name="log_send_mail_subject">%1$s înregistrările app-ului Android</string>
<string name="log_send_no_mail_app">Nu există nici o aplicație pentru a trimite fisiere log. Vă rugăm instalați un client de email.</string>
<string name="logged_in_as">Autentificat ca %1$s</string>
<string name="login">Autentificare</string>
<string name="login_url_helper_text">Linkul către %1$s interfața web atunci când deschizi linkul în browser.</string>
<string name="logs_menu_delete">Șterge fișiere log</string>
@ -912,6 +914,7 @@
<string name="wait_a_moment">Așteaptă un moment…</string>
<string name="wait_checking_credentials">Se verifică datele de autentificare stocate</string>
<string name="wait_for_tmp_copy_from_private_storage">Copiere fișier din stocare privată</string>
<string name="webview_version_check_alert_dialog_message">Pentru a vă autentifica, actualizați componenta WebView a sistemului Android</string>
<string name="webview_version_check_alert_dialog_positive_button_title">Actualizare</string>
<string name="what_s_new_image">Ce imagine este nouă</string>
<string name="whats_new_skip">Sari peste</string>