Skip to content

Commit

Permalink
fix: Screen turns off while patching due to wrong WakeLock
Browse files Browse the repository at this point in the history
  • Loading branch information
kitadai31 committed Aug 18, 2024
1 parent 747017a commit d546045
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<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,9 +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 android.view.WindowManager
import androidx.core.content.ContextCompat
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
Expand Down Expand Up @@ -108,21 +106,9 @@ class PatcherWorker(
Log.d(tag, "Failed to set foreground info:", e)
}

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

val args = workerRepository.claimInput(this)

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

private suspend fun runPatcher(args: Args): Result {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/app/revanced/manager/ui/screen/PatcherScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package app.revanced.manager.ui.screen

import android.app.Activity
import android.view.WindowManager
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
Expand All @@ -25,6 +27,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
Expand Down Expand Up @@ -85,6 +88,16 @@ fun PatcherScreen(
}
}

if (patcherSucceeded == null) {
DisposableEffect(Unit) {
val window = (context as Activity).window
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
onDispose {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
}

if (showInstallPicker)
InstallPickerDialog(
onDismiss = { showInstallPicker = false },
Expand Down

0 comments on commit d546045

Please sign in to comment.