@@ -6,9 +6,9 @@ import android.app.NotificationManager
66import android.content.Context
77import android.os.Build
88import android.util.Log
9- import androidx.core.app.ActivityCompat
109import androidx.core.app.NotificationCompat
1110import androidx.core.app.NotificationManagerCompat
11+ import androidx.core.content.ContextCompat
1212import androidx.work.CoroutineWorker
1313import androidx.work.Data
1414import androidx.work.WorkerParameters
@@ -50,11 +50,11 @@ class FileCleanupWorker(
5050 }
5151 val action = inputData.getString(KEY_ACTION ) ? : ACTION_DELETE
5252 val paths = rawPaths.toList()
53- println ( " FileCleanupWorker ---> Received paths: $paths " )
53+ Log .d( TAG , " Received paths: $paths " )
5454 val files = mutableListOf<File >()
5555 var hasNonProtectedPath = false
5656 for (path in paths) {
57- println ( " FileCleanupWorker ---> Checking path: $path " )
57+ Log .d( TAG , " Checking path: $path " )
5858 val file = File (path)
5959 if (file.isProtectedAndroidDir()) {
6060 Log .i(TAG , " Skipping protected path: ${file.absolutePath} " )
@@ -64,11 +64,11 @@ class FileCleanupWorker(
6464 val exists = file.exists()
6565 val isFile = file.isFile
6666 val isDirectory = file.isDirectory
67- println ( " FileCleanupWorker ---> File exists: $exists isFile: $isFile isDirectory: $isDirectory " )
67+ Log .d( TAG , " File exists: $exists isFile: $isFile isDirectory: $isDirectory " )
6868 if (exists) {
69- println ( " FileCleanupWorker ---> canRead: ${file.canRead()} canWrite: ${file.canWrite()} " )
69+ Log .d( TAG , " canRead: ${file.canRead()} canWrite: ${file.canWrite()} " )
7070 if (isDirectory) {
71- println ( " FileCleanupWorker ---> directory children: ${file.listFiles()?.size ? : 0 } " )
71+ Log .d( TAG , " directory children: ${file.listFiles()?.size ? : 0 } " )
7272 }
7373 files + = file
7474 }
@@ -114,7 +114,7 @@ class FileCleanupWorker(
114114 setProgress(workDataOf(KEY_PROGRESS_CURRENT to processed, KEY_PROGRESS_TOTAL to total))
115115
116116 val hasPermission = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
117- ActivityCompat .checkSelfPermission(
117+ ContextCompat .checkSelfPermission(
118118 applicationContext,
119119 Manifest .permission.POST_NOTIFICATIONS ,
120120 ) == android.content.pm.PackageManager .PERMISSION_GRANTED
@@ -145,20 +145,20 @@ class FileCleanupWorker(
145145 return Result .failure()
146146 }
147147
148- println ( " FileCleanupWorker ---> Attempting to $action : ${file.absolutePath} " )
148+ Log .d( TAG , " Attempting to $action : ${file.absolutePath} " )
149149 when (val res = performAction(action, listOf (file))) {
150150 is DataState .Error -> {
151151 failedPaths + = file.absolutePath
152152 val reason = when (val err = res.error) {
153153 is Errors .Custom -> err.message
154154 else -> err.toString()
155155 }
156- println ( " FileCleanupWorker ---> ERROR deleting ${file.absolutePath} → reason = $reason " )
156+ Log .e( TAG , " Error deleting ${file.absolutePath} → reason = $reason " )
157157 Log .w(TAG , " Failed to process ${file.absolutePath} : $reason " )
158158 }
159159 else -> {
160160 successCount++
161- println ( " FileCleanupWorker ---> Deleted: ${file.absolutePath} → result = success" )
161+ Log .i( TAG , " Deleted: ${file.absolutePath} → result = success" )
162162 }
163163 }
164164 processed++
@@ -193,7 +193,7 @@ class FileCleanupWorker(
193193 builder.setProgress(0 , 0 , false )
194194
195195 val failedCount = failedPaths.size
196- println ( " FileCleanupWorker ---> Deleted $successCount , failed $failedCount " )
196+ Log .i( TAG , " Deleted $successCount , failed $failedCount " )
197197 val resultData = Data .Builder ().apply {
198198 if (failedPaths.isNotEmpty()) {
199199 putStringArray(KEY_FAILED_PATHS , failedPaths.toTypedArray())
0 commit comments