@@ -25,12 +25,10 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker
2525import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
2626import com.nextcloud.client.network.ConnectivityService
2727import com.nextcloud.client.preferences.SubFolderRule
28- import com.nextcloud.utils.ForegroundServiceHelper
2928import com.nextcloud.utils.extensions.updateStatus
3029import com.owncloud.android.R
3130import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
3231import com.owncloud.android.datamodel.FileDataStorageManager
33- import com.owncloud.android.datamodel.ForegroundServiceType
3432import com.owncloud.android.datamodel.MediaFolderType
3533import com.owncloud.android.datamodel.SyncedFolder
3634import com.owncloud.android.datamodel.SyncedFolderProvider
@@ -85,8 +83,6 @@ class AutoUploadWorker(
8583 syncedFolder = syncedFolderProvider.getSyncedFolderByID(syncFolderId)
8684 ?.takeIf { it.isEnabled } ? : return Result .failure()
8785
88- trySetForeground()
89-
9086 /* *
9187 * Receives from [com.nextcloud.client.jobs.ContentObserverWork.checkAndTriggerAutoUpload]
9288 */
@@ -97,7 +93,6 @@ class AutoUploadWorker(
9793 }
9894
9995 collectFileChangesFromContentObserverWork(contentUris)
100- updateNotification()
10196 uploadFiles(syncedFolder)
10297
10398 Log_OC .d(TAG , " ✅ ${syncedFolder.remotePath} finished checking files." )
@@ -109,18 +104,11 @@ class AutoUploadWorker(
109104 }
110105
111106 override suspend fun getForegroundInfo (): ForegroundInfo {
112- val notification = createNotification(
113- context.getString(R .string.upload_files)
114- )
115-
116- return ForegroundServiceHelper .createWorkerForegroundInfo(
117- NOTIFICATION_ID ,
118- notification,
119- ForegroundServiceType .DataSync
120- )
107+ val notification = createNotification(context.getString(R .string.upload_files))
108+ return notificationManager.getForegroundInfo(notification)
121109 }
122110
123- private fun updateNotification () {
111+ private suspend fun updateNotification () {
124112 getStartNotificationTitle()?.let { (localFolderName, remoteFolderName) ->
125113 try {
126114 val startNotification = createNotification(
@@ -131,7 +119,7 @@ class AutoUploadWorker(
131119 )
132120 )
133121
134- notificationManager.showNotification (startNotification)
122+ setForeground( notificationManager.getForegroundInfo (startNotification) )
135123 } catch (e: Exception ) {
136124 Log_OC .w(TAG , " ⚠️ Could not update notification: ${e.message} " )
137125 }
@@ -141,21 +129,12 @@ class AutoUploadWorker(
141129 private suspend fun trySetForeground () {
142130 try {
143131 val notification = createNotification(context.getString(R .string.upload_files))
144- updateForegroundInfo( notification)
132+ setForeground(notificationManager.getForegroundInfo( notification) )
145133 } catch (e: Exception ) {
146134 Log_OC .w(TAG , " ⚠️ Could not set foreground service: ${e.message} " )
147135 }
148136 }
149137
150- private suspend fun updateForegroundInfo (notification : Notification ) {
151- val foregroundInfo = ForegroundServiceHelper .createWorkerForegroundInfo(
152- NOTIFICATION_ID ,
153- notification,
154- ForegroundServiceType .DataSync
155- )
156- setForeground(foregroundInfo)
157- }
158-
159138 private fun createNotification (title : String ): Notification = notificationManager.notificationBuilder
160139 .setContentTitle(title)
161140 .setSmallIcon(R .drawable.uploads)
@@ -297,6 +276,9 @@ class AutoUploadWorker(
297276 val lightVersion = context.resources.getBoolean(R .bool.syncedFolder_light)
298277 val currentLocale = context.resources.configuration.locales[0 ]
299278
279+ trySetForeground()
280+ updateNotification()
281+
300282 var lastId = 0
301283 while (true ) {
302284 val filePathsWithIds = repository.getFilePathsWithIds(syncedFolder, lastId)
0 commit comments