Skip to content

Commit

Permalink
- only keep screen on in DownloadActivity during the network download…
Browse files Browse the repository at this point in the history
… and not during the hole Android activity (#620)
  • Loading branch information
Tobi823 committed Mar 2, 2025
1 parent e5b3208 commit da447f9
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class DownloadActivity : AppCompatActivity() {
setContentView(R.layout.activity_download)
AppCompatDelegate.setDefaultNightMode(ForegroundSettings.themePreference)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // prevent network timeouts
// I did not understand Android edge-to-edge completely,
// but this should prevent elements hidden behind the system bars.
setOnApplyWindowInsetsListener(findViewById(R.id.download_activity__main_layout)) { v: View, insets: WindowInsetsCompat ->
Expand Down Expand Up @@ -187,7 +186,6 @@ class DownloadActivity : AppCompatActivity() {
deleteCachedApkFileIfSuitable(downloadViewModel.installationSuccess)
}
lifecycle.removeObserver(installer)
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

override fun onSupportNavigateUp(): Boolean {
Expand Down Expand Up @@ -302,7 +300,6 @@ class DownloadActivity : AppCompatActivity() {
reuseCurrentDownloadWithoutErrorChecking(status)
}
}

true
} catch (e: Exception) {
debug("reusing the existing download of $[app.name} failed", e)
Expand Down Expand Up @@ -355,13 +352,15 @@ class DownloadActivity : AppCompatActivity() {
val channel = Channel<DownloadStatus>()
val download =
downloadViewModel.viewModelScope.async { // capture exception so that CrashListener will not caught it
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // prevent network timeouts
try {
appImpl.download(applicationContext, status.latestVersion, channel)
return@async Result.success(true)
} catch (e: Exception) {
return@async Result.failure(e)
} finally {
channel.close(DisplayableException("Progress channel was not yet closed. This should never happen"))
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
downloadViewModel.storeNewRunningDownload(status, download, channel)
Expand Down Expand Up @@ -433,6 +432,11 @@ class DownloadActivity : AppCompatActivity() {
}
}

override fun onPause() {
super.onPause()
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // prevent network timeouts
}

companion object {
const val EXTRA_APP_NAME = "app_name"
const val LOG_PREFIX = "DownloadActivity"
Expand Down

0 comments on commit da447f9

Please sign in to comment.