mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
Keep the session alive in the background, rename the package, sign with the testkey, and draw the app a logo
The session now belongs to a foreground service rather than the activity. Android demotes a process as soon as its last visible activity goes and the low-memory killer reaps the guest, so leaving Big Picture to answer a message came back to a dead Steam; the service holds the process at perceptible priority, a partial wake lock keeps the CPU from dropping the guest's threads, and a high-performance WiFi lock keeps a backgrounded download from being throttled to nothing. The notification is silent (IMPORTANCE_LOW), carries a Stop action, and returns to the session when tapped. Back now puts the app away and leaves Steam running; a swipe out of recents ends the session. The compositor moved with it: it is process-wide, started once, and merely swaps the Surface it presents into as the activity comes and goes. Package is com.steamdeck.launcher, signed with the AOSP testkey (v1+v2+v3) so every build installs over the last one, and CI asserts all three schemes. The launcher icon is our own controller on a purple glow — the spirit of the Steam tile the client entry uses, none of its geometry.
This commit is contained in:
1 parent
4031f512fc
commit
344e70afc6
49 files changed
+977
-615
No files matched your search
@@ -0,0 +1,161 @@
|
||||
package com.steamdeck.launcher
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import com.steamdeck.launcher.core.FileUtils
|
||||
import com.steamdeck.launcher.runtime.LinuxRuntime
|
||||
import com.steamdeck.launcher.runtime.LinuxRuntimeInstaller
|
||||
|
||||
/**
|
||||
* The whole app outside a session: is the runtime installed, is there a newer one, and one button
|
||||
* that starts Steam. Everything a Steam client can do — the library, the store, downloads,
|
||||
* settings — is the client's own job once {@link SessionActivity} has it on screen.
|
||||
*/
|
||||
class MainActivity : Activity() {
|
||||
private lateinit var status: TextView
|
||||
private lateinit var detail: TextView
|
||||
private lateinit var progress: ProgressBar
|
||||
private lateinit var playButton: Button
|
||||
private lateinit var runtimeButton: Button
|
||||
|
||||
private val ui = Handler(Looper.getMainLooper())
|
||||
@Volatile private var busy = false
|
||||
@Volatile private var available: LinuxRuntimeInstaller.Release? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
status = findViewById(R.id.status)
|
||||
detail = findViewById(R.id.detail)
|
||||
progress = findViewById(R.id.progress)
|
||||
playButton = findViewById(R.id.play)
|
||||
runtimeButton = findViewById(R.id.runtime)
|
||||
|
||||
playButton.setOnClickListener { startActivity(Intent(this, SessionActivity::class.java)) }
|
||||
runtimeButton.setOnClickListener { onRuntimeButton() }
|
||||
findViewById<TextView>(R.id.credits).setOnClickListener {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.credits_title)
|
||||
.setMessage(R.string.credits_body)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
// The session's logs land in Downloads so a failed run can be handed over as a folder
|
||||
// rather than dug out of app-private storage. targetSdk 28 means the old permission still
|
||||
// grants exactly that.
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
render()
|
||||
if (!busy) Thread({ checkCatalog() }, "catalog").start()
|
||||
}
|
||||
|
||||
private fun onRuntimeButton() {
|
||||
if (busy) return
|
||||
val installed = LinuxRuntimeInstaller.installedVersion(this)
|
||||
if (installed != null && available?.version == installed) {
|
||||
// Nothing to install: offer the one destructive thing this screen can do.
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.remove_runtime)
|
||||
.setMessage(R.string.remove_runtime_message)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.remove) { _, _ ->
|
||||
Thread({
|
||||
LinuxRuntimeInstaller.uninstall(this)
|
||||
ui.post { render() }
|
||||
}, "uninstall").start()
|
||||
}
|
||||
.show()
|
||||
return
|
||||
}
|
||||
val release = available
|
||||
if (release == null) {
|
||||
Thread({ checkCatalog() }, "catalog").start()
|
||||
return
|
||||
}
|
||||
install(release)
|
||||
}
|
||||
|
||||
private fun install(release: LinuxRuntimeInstaller.Release) {
|
||||
busy = true
|
||||
render()
|
||||
Thread({
|
||||
val ok = LinuxRuntimeInstaller.install(this, release) { stage, percent ->
|
||||
ui.post {
|
||||
progress.isIndeterminate = percent < 0
|
||||
if (percent >= 0) progress.progress = percent
|
||||
detail.text = if (percent >= 0) "$stage $percent%" else stage
|
||||
}
|
||||
}
|
||||
busy = false
|
||||
ui.post {
|
||||
if (!ok) detail.text = getString(R.string.install_failed)
|
||||
render()
|
||||
}
|
||||
}, "install").start()
|
||||
}
|
||||
|
||||
private fun checkCatalog() {
|
||||
val release = LinuxRuntimeInstaller.fetchRelease()
|
||||
if (release != null) available = release
|
||||
Log.i(TAG, "catalog: " + (release?.version ?: "unreachable"))
|
||||
ui.post { render() }
|
||||
}
|
||||
|
||||
private fun render() {
|
||||
val installed = LinuxRuntimeInstaller.installedVersion(this)
|
||||
val ready = LinuxRuntime.isInstalled(this)
|
||||
progress.visibility = if (busy) View.VISIBLE else View.GONE
|
||||
playButton.isEnabled = ready && !busy
|
||||
runtimeButton.isEnabled = !busy
|
||||
|
||||
val offered = available
|
||||
when {
|
||||
busy -> {
|
||||
status.setText(R.string.working)
|
||||
runtimeButton.setText(R.string.working)
|
||||
}
|
||||
!ready -> {
|
||||
status.setText(R.string.runtime_missing)
|
||||
runtimeButton.setText(R.string.install_runtime)
|
||||
detail.text = if (offered != null) {
|
||||
getString(R.string.runtime_download_size,
|
||||
offered.version, FileUtils.sizeToString(offered.size))
|
||||
} else {
|
||||
getString(R.string.catalog_unreachable)
|
||||
}
|
||||
}
|
||||
offered != null && offered.version != installed -> {
|
||||
status.setText(R.string.ready)
|
||||
runtimeButton.setText(R.string.update_runtime)
|
||||
detail.text = getString(R.string.runtime_update, installed ?: "?", offered.version)
|
||||
}
|
||||
else -> {
|
||||
status.setText(R.string.ready)
|
||||
runtimeButton.setText(R.string.remove_runtime)
|
||||
detail.text = getString(R.string.runtime_installed, installed ?: "?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MainActivity"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user