Skip to content

Commit

Permalink
Restore wakelock and change to PARTIAL_WAKE_LOCK
Browse files Browse the repository at this point in the history
  • Loading branch information
kitadai31 committed Dec 17, 2024
1 parent d546045 commit e989c55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<queries>
<intent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.drawable.Icon
import android.os.Build
import android.os.PowerManager
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.work.ForegroundInfo
Expand Down Expand Up @@ -106,9 +107,21 @@ class PatcherWorker(
Log.d(tag, "Failed to set foreground info:", e)
}

val wakeLock: PowerManager.WakeLock =
(applicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager)
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "$tag::Patcher")
.apply {
acquire(10 * 60 * 1000L)
Log.d(tag, "Acquired wakelock.")
}

val args = workerRepository.claimInput(this)

return runPatcher(args)
return try {
runPatcher(args)
} finally {
wakeLock.release()
}
}

private suspend fun runPatcher(args: Args): Result {
Expand Down

0 comments on commit e989c55

Please sign in to comment.