Show upload failed notification when failed normal upload

avoid:

2023-03-01 16:47:40.443 23569-23628 UploadAndS...ilesWorker com.nextcloud.talk2                  E  Something went wrong when trying to upload file
                                                                                                    java.lang.NullPointerException
                                                                                                    	at com.nextcloud.talk.jobs.UploadAndShareFilesWorker.showFailedToUploadNotification(UploadAndShareFilesWorker.kt:258)
                                                                                                    	at com.nextcloud.talk.jobs.UploadAndShareFilesWorker.doWork(UploadAndShareFilesWorker.kt:163)
                                                                                                    	at androidx.work.Worker$1.run(Worker.java:86)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                    	at java.lang.Thread.run(Thread.java:919)
2023-03-01 16:47:40.444 23569-23607 WM-WorkerWrapper        com.nextcloud.talk2                  E  Work [ id=27e4e319-a966-4515-ac07-d6ad7ee68268, tags={ com.nextcloud.talk.jobs.UploadAndShareFilesWorker } ] failed because it threw an exception/error
                                                                                                    java.util.concurrent.ExecutionException: java.lang.NullPointerException
                                                                                                    	at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:516)
                                                                                                    	at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
                                                                                                    	at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:311)
                                                                                                    	at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                    	at java.lang.Thread.run(Thread.java:919)
                                                                                                    Caused by: java.lang.NullPointerException
                                                                                                    	at com.nextcloud.talk.jobs.UploadAndShareFilesWorker.showFailedToUploadNotification(UploadAndShareFilesWorker.kt:258)
                                                                                                    	at com.nextcloud.talk.jobs.UploadAndShareFilesWorker.doWork(UploadAndShareFilesWorker.kt:167)
                                                                                                    	at androidx.work.Worker$1.run(Worker.java:86)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
                                                                                                    	at java.lang.Thread.run(Thread.java:919) 
2023-03-01 16:47:40.446 23569-23607 WM-WorkerWrapper        com.nextcloud.talk2                  I  Worker result FAILURE for Work [ id=27e4e319-a966-

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-01 17:30:57 +01:00
parent 362a2be7cd
commit 4883f62964
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 29 additions and 2 deletions

View File

@ -121,10 +121,12 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
val remotePath = getRemotePath(currentUser)
val uploadSuccess: Boolean
initNotificationSetup()
if (file != null && file.length() > CHUNK_UPLOAD_THRESHOLD_SIZE) {
Log.d(TAG, "starting chunked upload because size is " + file.length())
initNotification()
initNotificationWithPercentage()
val mimeType = context.contentResolver.getType(sourceFileUri)?.toMediaTypeOrNull()
uploadSuccess = ChunkedFileUploader(
@ -190,14 +192,16 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
mNotifyManager!!.notify(notificationId, notification)
}
private fun initNotification() {
private fun initNotificationSetup() {
mNotifyManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
mBuilder = NotificationCompat.Builder(
context,
NotificationUtils.NotificationChannels
.NOTIFICATION_CHANNEL_UPLOADS.name
)
}
private fun initNotificationWithPercentage() {
notification = mBuilder!!
.setContentTitle(context.resources.getString(R.string.nc_upload_in_progess))
.setContentText(getNotificationContentText(ZERO_PERCENT))
@ -258,6 +262,7 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
notification = mBuilder!!
.setContentTitle(failureTitle)
.setContentText(failureText)
.setSmallIcon(R.drawable.baseline_error_24)
.setOngoing(false)
.build()

View File

@ -0,0 +1,22 @@
<!--
@author Google LLC
Copyright (C) 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector android:height="24dp" android:fillColor="#ffffff"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
</vector>