mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
PlayStore: deliver runtime modules and resources on demand
Preserve component file inventories, reuse setup controls, and keep Play-managed resources behind a read-only guest stream. Build version 0.6.9.2 with version code 19 and support large signed release assets.
This commit is contained in:
1 parent
d25f6940ee
commit
5d10c8e96d
25 files changed
+1329
-83
No files matched your search
+6
-2
@@ -134,8 +134,8 @@ android {
|
||||
applicationId "com.droiddeck.launcher"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 37
|
||||
versionCode 18
|
||||
versionName "0.6.9.1"
|
||||
versionCode 19
|
||||
versionName "0.6.9.2"
|
||||
buildConfigField "String", "BUILD_LABEL", "\"${escapedBuildLabel}\""
|
||||
buildConfigField "String", "SOURCE_COMMIT", "\"${sourceCommit}\""
|
||||
buildConfigField "int", "PR_NUMBER", "${prNumber}"
|
||||
@@ -324,6 +324,8 @@ if (playDistribution) {
|
||||
def payloads = rootProject.file('build/playstore-payloads')
|
||||
def modules = new groovy.json.JsonSlurper().parse(new File(payloads, 'modules.json'))
|
||||
android.dynamicFeatures = modules.collect { ":${it}".toString() }.toSet()
|
||||
def packs = new groovy.json.JsonSlurper().parse(new File(payloads, 'assetpacks.json'))
|
||||
android.assetPacks = packs.collect { ":${it}".toString() }.toSet()
|
||||
android.sourceSets.main.assets.srcDir(new File(payloads, 'base/src/main/assets'))
|
||||
android.sourceSets.debug.manifest.srcFile('src/play/AndroidManifest.xml')
|
||||
android.sourceSets.release.manifest.srcFile('src/play/AndroidManifest.xml')
|
||||
@@ -400,6 +402,8 @@ tasks.named('preBuild').configure { dependsOn(buildRustStores) }
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.android.play:app-update:2.1.0'
|
||||
implementation 'com.google.android.play:feature-delivery:2.1.0'
|
||||
implementation 'com.google.android.play:asset-delivery:2.3.0'
|
||||
implementation "org.opencv:opencv:${trackingPack.OPENCV_VERSION}"
|
||||
implementation 'org.khronos.openxr:openxr_loader_for_android:1.1.49'
|
||||
implementation 'com.github.luben:zstd-jni:1.5.7-4@aar'
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.droiddeck.launcher.session.CrashHandler
|
||||
import com.droiddeck.launcher.session.GpuClockPin
|
||||
|
||||
class App : Application() {
|
||||
override fun attachBaseContext(base: android.content.Context) =
|
||||
override fun attachBaseContext(base: android.content.Context) {
|
||||
super.attachBaseContext(com.droiddeck.launcher.core.AppLanguage.wrap(base))
|
||||
if (BuildConfig.PLAY_DISTRIBUTION) com.google.android.play.core.splitcompat.SplitCompat.install(this)
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.WindowManager
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
@@ -578,6 +579,11 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
override fun startActivity(intent: Intent?) {
|
||||
if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready &&
|
||||
intent?.component?.className == SessionActivity::class.java.name) {
|
||||
com.droiddeck.launcher.core.PlayDelivery.defer(intent)
|
||||
return
|
||||
}
|
||||
val compat = protons.protonBusyId != null || ProtonExtras.installInProgress
|
||||
if (intent?.component?.className == SessionActivity::class.java.name) {
|
||||
if (compatLaunch != null) return
|
||||
@@ -1009,6 +1015,11 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (BuildConfig.PLAY_DISTRIBUTION) {
|
||||
@Suppress("DEPRECATION")
|
||||
val pending = savedInstanceState?.getParcelable<Intent>("play_pending_session")
|
||||
if (pending?.component?.className == SessionActivity::class.java.name) com.droiddeck.launcher.core.PlayDelivery.defer(pending)
|
||||
}
|
||||
if (savedInstanceState == null) readIntegrationIntent(intent)
|
||||
readGameIntent(intent)
|
||||
gameSyncFolder = GameFileSync.folder(this)
|
||||
@@ -1043,6 +1054,27 @@ class FrontEndActivity : ComponentActivity() {
|
||||
updates.start()
|
||||
setContent {
|
||||
DroidDeckTheme(theme, appScale = appScale) {
|
||||
val delivery by com.droiddeck.launcher.core.PlayDelivery.state.collectAsState()
|
||||
androidx.compose.runtime.LaunchedEffect(delivery.ready) {
|
||||
if (delivery.ready) {
|
||||
com.droiddeck.launcher.core.PlayDelivery.takePendingSession()?.let { startActivity(it) }
|
||||
if (BuildConfig.PLAY_DISTRIBUTION) {
|
||||
refresh()
|
||||
refreshDeliveredComponents(force = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BuildConfig.PLAY_DISTRIBUTION && !delivery.ready) ConfirmDialog(
|
||||
title = getString(R.string.app_name),
|
||||
text = if (delivery.busy && delivery.percent >= 0)
|
||||
getString(R.string.setup_runtime_progress, getString(R.string.rtinst_downloading), delivery.percent)
|
||||
else getString(if (delivery.failed) R.string.user_apps_download_failed else R.string.rtinst_downloading),
|
||||
confirm = getString(if (delivery.busy) R.string.common_working else R.string.stores_dl_retry),
|
||||
onConfirm = { com.droiddeck.launcher.core.PlayDelivery.start(this) },
|
||||
onDismiss = { com.droiddeck.launcher.core.PlayDelivery.cancel(); finish() },
|
||||
progress = if (delivery.busy) delivery.percent else null,
|
||||
confirmEnabled = !delivery.busy, closeOnConfirm = false,
|
||||
)
|
||||
com.droiddeck.launcher.ui.FocusGlideHost(androidx.compose.ui.Modifier.fillMaxSize().exposeTestTags()) {
|
||||
if (decky.deckyPendingZip != null) com.droiddeck.launcher.ui.DeckyZipWarningDialog(
|
||||
onConfirm = { decky.confirmPluginZip() }, onCancel = { decky.cancelPluginZip() },
|
||||
@@ -1755,6 +1787,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
com.droiddeck.launcher.core.PlayDelivery.start(this)
|
||||
compatLaunchVisible = true
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false)
|
||||
@@ -1774,10 +1807,24 @@ class FrontEndActivity : ComponentActivity() {
|
||||
refreshPhantomStatus()
|
||||
syncLossless()
|
||||
updates.onResume()
|
||||
catalogFresh = false
|
||||
oscMode = SessionPrefs.oscMode(this)
|
||||
refreshController()
|
||||
refreshHomeAppState()
|
||||
refreshSecondScreenDisplays()
|
||||
refresh()
|
||||
decky.deckyInstalled = DeckyManager.installed(this)
|
||||
DeckyManager.syncCefMarker(this)
|
||||
decky.deckySupervisor = DeckyManager.supervisorEnabled(this)
|
||||
refreshAddedGames()
|
||||
refreshDeliveredComponents()
|
||||
}
|
||||
|
||||
private fun refreshDeliveredComponents(force: Boolean = false) {
|
||||
if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready) return
|
||||
drivers.checkOnOpen()
|
||||
resumeInterruptedPackages()
|
||||
protons.checkUpdates()
|
||||
catalogFresh = false
|
||||
protons.checkUpdates(force)
|
||||
if (!SessionState.running && !componentsQueueBusy && !LinuxRuntimeInstaller.isBusy()) {
|
||||
componentsQueueBusy = true
|
||||
Thread({
|
||||
@@ -1792,15 +1839,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
}, "components-queue").start()
|
||||
} else if (showComponents) components.refreshComponents()
|
||||
oscMode = SessionPrefs.oscMode(this)
|
||||
refreshController()
|
||||
refreshHomeAppState()
|
||||
refreshSecondScreenDisplays()
|
||||
refresh()
|
||||
decky.deckyInstalled = DeckyManager.installed(this)
|
||||
DeckyManager.syncCefMarker(this)
|
||||
decky.deckySupervisor = DeckyManager.supervisorEnabled(this)
|
||||
refreshAddedGames()
|
||||
if (catalog == null) loadDesktopCatalog()
|
||||
if (!busy) Thread({ checkCatalog() }, "catalog").start()
|
||||
}
|
||||
@@ -1824,6 +1862,10 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == 7619 && BuildConfig.PLAY_DISTRIBUTION) {
|
||||
if (resultCode != RESULT_OK) com.droiddeck.launcher.core.PlayDelivery.cancel()
|
||||
return
|
||||
}
|
||||
if (HomeWidgets.onActivityResult(this, requestCode, resultCode)) return
|
||||
@Suppress("DEPRECATION")
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
@@ -1831,6 +1873,9 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
if (BuildConfig.PLAY_DISTRIBUTION) com.droiddeck.launcher.core.PlayDelivery.peekPendingSession()?.let {
|
||||
outState.putParcelable("play_pending_session", it)
|
||||
}
|
||||
if (slowUsbNever) SessionPrefs.setSlowUsbWarningOff(this)
|
||||
saveCompatLaunch(outState)
|
||||
pendingSwitch?.let { outState.putParcelable(KEY_PENDING_SWITCH, it) }
|
||||
@@ -1845,6 +1890,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
else @Suppress("DEPRECATION") state.getParcelable(key)
|
||||
|
||||
override fun onDestroy() {
|
||||
com.droiddeck.launcher.core.PlayDelivery.detach(this)
|
||||
cancelCompatLaunch()
|
||||
updates.unregister()
|
||||
super.onDestroy()
|
||||
@@ -1940,6 +1986,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private fun loadDesktopCatalog() {
|
||||
if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready) return
|
||||
if (catalogLoading || catalog != null) return
|
||||
catalogLoading = true
|
||||
Thread({
|
||||
|
||||
@@ -566,6 +566,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready) {
|
||||
runtimeRemovalBlocked = true
|
||||
com.droiddeck.launcher.core.PlayDelivery.defer(intent)
|
||||
startActivity(Intent(this, FrontEndActivity::class.java))
|
||||
finish()
|
||||
return
|
||||
}
|
||||
if (com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isRemoving() ||
|
||||
com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isMaintaining()) {
|
||||
runtimeRemovalBlocked = true
|
||||
|
||||
@@ -16,10 +16,10 @@ public final class ComponentDownloads {
|
||||
|
||||
public static void init(Context context) {
|
||||
if (BuildConfig.PLAY_DISTRIBUTION) {
|
||||
Context application = context.getApplicationContext();
|
||||
PlayDelivery.INSTANCE.init(context);
|
||||
store = new ComponentPayloadStore(path -> {
|
||||
try {
|
||||
return application.getAssets().open(path);
|
||||
return PlayDelivery.INSTANCE.open(path);
|
||||
} catch (IOException error) {
|
||||
throw new java.io.UncheckedIOException(error);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.droiddeck.launcher.BuildConfig
|
||||
import com.google.android.gms.tasks.Tasks
|
||||
import com.google.android.gms.tasks.Task
|
||||
import java.util.concurrent.TimeUnit
|
||||
import com.google.android.play.core.assetpacks.AssetPackManagerFactory
|
||||
import com.google.android.play.core.assetpacks.model.AssetPackStatus
|
||||
import com.google.android.play.core.splitcompat.SplitCompat
|
||||
import com.google.android.play.core.splitinstall.SplitInstallManagerFactory
|
||||
import com.google.android.play.core.splitinstall.SplitInstallRequest
|
||||
import com.google.android.play.core.splitinstall.model.SplitInstallSessionStatus
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.io.FilterInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
internal object PlayDelivery {
|
||||
data class State(val ready: Boolean = !BuildConfig.PLAY_DISTRIBUTION, val busy: Boolean = false,
|
||||
val failed: Boolean = false, val percent: Int = -1)
|
||||
|
||||
private val mutableState = MutableStateFlow(State())
|
||||
val state = mutableState.asStateFlow()
|
||||
private lateinit var app: Context
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val running = AtomicBoolean(false)
|
||||
private val cancelled = AtomicBoolean(false)
|
||||
private var activity = WeakReference<Activity>(null)
|
||||
@Volatile private var session = 0
|
||||
@Volatile private var confirmation = false
|
||||
@Volatile private var attempt = 0
|
||||
private var pendingSession: android.content.Intent? = null
|
||||
private var server: android.net.LocalServerSocket? = null
|
||||
private val clients = java.util.concurrent.Semaphore(2)
|
||||
private val splits by lazy { SplitInstallManagerFactory.create(app) }
|
||||
private val assets by lazy { AssetPackManagerFactory.getInstance(app) }
|
||||
private val definition by lazy {
|
||||
app.assets.open("play-components/delivery.json").bufferedReader().use { JSONObject(it.readText()) }
|
||||
}
|
||||
private fun names(key: String): List<String> = definition.getJSONArray(key).let { list ->
|
||||
(0 until list.length()).map { list.getString(it) }
|
||||
}
|
||||
|
||||
fun init(context: Context) {
|
||||
if (!BuildConfig.PLAY_DISTRIBUTION) return
|
||||
app = context.applicationContext
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun defer(intent: android.content.Intent) { pendingSession = android.content.Intent(intent) }
|
||||
|
||||
@Synchronized
|
||||
fun peekPendingSession(): android.content.Intent? = pendingSession?.let { android.content.Intent(it) }
|
||||
|
||||
@Synchronized
|
||||
fun takePendingSession(): android.content.Intent? = pendingSession.also { pendingSession = null }
|
||||
|
||||
fun start(owner: Activity) {
|
||||
if (!BuildConfig.PLAY_DISTRIBUTION) return
|
||||
activity = WeakReference(owner)
|
||||
if (mutableState.value.ready) return
|
||||
if (!running.compareAndSet(false, true)) return
|
||||
cancelled.set(false)
|
||||
attempt++
|
||||
confirmation = false
|
||||
mutableState.value = State(busy = true)
|
||||
Thread({
|
||||
var completed = State(failed = true)
|
||||
try {
|
||||
installModules()
|
||||
confirmation = false
|
||||
installAssets()
|
||||
checkCancelled()
|
||||
startServer()
|
||||
completed = State(ready = true, percent = 100)
|
||||
} catch (error: Exception) {
|
||||
android.util.Log.w("PlayDelivery", "Play component delivery failed", error)
|
||||
} finally {
|
||||
if (cancelled.get()) cancel()
|
||||
running.set(false)
|
||||
mutableState.value = completed
|
||||
}
|
||||
}, "play-components").start()
|
||||
}
|
||||
|
||||
fun detach(owner: Activity) {
|
||||
if (activity.get() === owner) activity.clear()
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
cancelled.set(true)
|
||||
synchronized(this) { pendingSession = null }
|
||||
if (session > 0) splits.cancelInstall(session)
|
||||
if (::app.isInitialized) runCatching { assets.cancel(names("packs")) }
|
||||
}
|
||||
|
||||
private fun <T> await(task: Task<T>): T = Tasks.await(task, 30, TimeUnit.SECONDS)
|
||||
|
||||
private fun checkCancelled() {
|
||||
if (cancelled.get() || Thread.currentThread().isInterrupted) throw IOException("Play delivery cancelled")
|
||||
}
|
||||
|
||||
private fun installModules() {
|
||||
val missing = names("modules").filterNot { it in splits.installedModules }
|
||||
if (missing.isEmpty()) return
|
||||
val previous = await(splits.sessionStates).firstOrNull {
|
||||
it.moduleNames().containsAll(missing) && it.status() in setOf(
|
||||
SplitInstallSessionStatus.PENDING, SplitInstallSessionStatus.DOWNLOADING,
|
||||
SplitInstallSessionStatus.DOWNLOADED, SplitInstallSessionStatus.INSTALLING,
|
||||
SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION)
|
||||
}
|
||||
session = previous?.sessionId() ?: run {
|
||||
val request = attempt
|
||||
val task = splits.startInstall(SplitInstallRequest.newBuilder().apply { missing.forEach(::addModule) }.build())
|
||||
task.addOnSuccessListener { id -> if (request == attempt && cancelled.get()) splits.cancelInstall(id) }
|
||||
await(task)
|
||||
}
|
||||
while (true) {
|
||||
checkCancelled()
|
||||
val current = await(splits.getSessionState(session))
|
||||
val request = attempt
|
||||
when (current.status()) {
|
||||
SplitInstallSessionStatus.INSTALLED -> {
|
||||
if (!SplitCompat.install(app) || !splits.installedModules.containsAll(missing))
|
||||
throw IOException("Play modules could not be activated")
|
||||
session = 0
|
||||
return
|
||||
}
|
||||
SplitInstallSessionStatus.FAILED, SplitInstallSessionStatus.CANCELED ->
|
||||
throw IOException("Play module delivery failed: ${current.errorCode()}")
|
||||
SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> handler.post {
|
||||
val owner = activity.get()
|
||||
if (request == attempt && session == current.sessionId() && running.get() && !cancelled.get() &&
|
||||
!confirmation && owner != null && !owner.isFinishing && !owner.isDestroyed) {
|
||||
runCatching { splits.startConfirmationDialogForResult(current, owner, 7619) }
|
||||
.onSuccess { confirmation = it }.onFailure { cancel() }
|
||||
}
|
||||
}
|
||||
}
|
||||
val total = current.totalBytesToDownload()
|
||||
mutableState.value = State(busy = true, percent = if (total > 0)
|
||||
(current.bytesDownloaded() * 80 / total).toInt().coerceIn(0, 80) else -1)
|
||||
Thread.sleep(350)
|
||||
}
|
||||
}
|
||||
|
||||
private fun installAssets() {
|
||||
val packs = names("packs")
|
||||
val missing = packs.filter { assets.getPackLocation(it) == null }
|
||||
if (missing.isEmpty()) return
|
||||
val requestAttempt = attempt
|
||||
val fetch = assets.fetch(missing)
|
||||
fetch.addOnSuccessListener { if (requestAttempt == attempt && cancelled.get()) assets.cancel(missing) }
|
||||
await(fetch)
|
||||
while (true) {
|
||||
checkCancelled()
|
||||
val states = await(assets.getPackStates(missing)).packStates().values
|
||||
if (states.any { it.status() == AssetPackStatus.FAILED || it.status() == AssetPackStatus.CANCELED })
|
||||
throw IOException("Play data delivery failed")
|
||||
if (missing.all { assets.getPackLocation(it) != null }) return
|
||||
val request = attempt
|
||||
if (states.any { it.status() == AssetPackStatus.WAITING_FOR_WIFI || it.status() == AssetPackStatus.REQUIRES_USER_CONFIRMATION })
|
||||
handler.post {
|
||||
val owner = activity.get()
|
||||
if (request == attempt && running.get() && !cancelled.get() &&
|
||||
!confirmation && owner != null && !owner.isFinishing && !owner.isDestroyed) {
|
||||
confirmation = true
|
||||
assets.showConfirmationDialog(owner).addOnSuccessListener { result ->
|
||||
if (request == attempt && result != Activity.RESULT_OK) cancel()
|
||||
}.addOnFailureListener { if (request == attempt) cancel() }
|
||||
}
|
||||
}
|
||||
val total = states.sumOf { it.totalBytesToDownload() }
|
||||
val downloaded = states.sumOf { it.bytesDownloaded() }
|
||||
mutableState.value = State(busy = true, percent = if (total > 0)
|
||||
(80 + downloaded * 19 / total).toInt().coerceIn(80, 99) else -1)
|
||||
Thread.sleep(500)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun startServer() {
|
||||
if (server != null) return
|
||||
val listener = android.net.LocalServerSocket(app.packageName + ".play-components")
|
||||
server = listener
|
||||
Thread({
|
||||
while (true) {
|
||||
val client = try { listener.accept() } catch (_: IOException) { break }
|
||||
if (!clients.tryAcquire()) { client.close(); continue }
|
||||
Thread({
|
||||
try {
|
||||
client.use {
|
||||
client.soTimeout = 30_000
|
||||
if (client.peerCredentials.uid != android.os.Process.myUid()) return@use
|
||||
val input = java.io.DataInputStream(client.inputStream)
|
||||
val length = input.readInt()
|
||||
if (length !in 1..256) return@use
|
||||
val path = ByteArray(length).also(input::readFully).toString(Charsets.UTF_8)
|
||||
if (!Regex("play-components/[0-9a-f]{64}/[0-9]{4,}").matches(path)) return@use
|
||||
val output = client.outputStream
|
||||
open(path).use { source ->
|
||||
output.write(1)
|
||||
source.copyTo(output, 65536)
|
||||
}
|
||||
}
|
||||
} catch (error: IOException) {
|
||||
android.util.Log.w("PlayDelivery", "Component stream closed", error)
|
||||
} finally {
|
||||
clients.release()
|
||||
}
|
||||
}, "play-component-reader").apply { isDaemon = true; start() }
|
||||
}
|
||||
}, "play-component-server").apply { isDaemon = true; start() }
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun open(path: String): InputStream {
|
||||
try {
|
||||
return app.assets.open(path)
|
||||
} catch (_: java.io.FileNotFoundException) {
|
||||
val info = app.packageManager.getApplicationInfo(app.packageName, 0)
|
||||
for (split in info.splitSourceDirs.orEmpty()) {
|
||||
val archive = ZipFile(split)
|
||||
val entry = archive.getEntry("assets/$path")
|
||||
if (entry == null) {
|
||||
archive.close()
|
||||
continue
|
||||
}
|
||||
return object : FilterInputStream(archive.getInputStream(entry)) {
|
||||
override fun close() { try { super.close() } finally { archive.close() } }
|
||||
}
|
||||
}
|
||||
for (name in names("packs")) {
|
||||
val directory = assets.getPackLocation(name)?.assetsPath()?.let(::File) ?: continue
|
||||
val file = File(directory, path)
|
||||
if (file.canonicalPath.startsWith(directory.canonicalPath + File.separator) && file.isFile)
|
||||
return file.inputStream()
|
||||
}
|
||||
if (!running.get()) mutableState.value = State(failed = true)
|
||||
throw IOException("Play component is not installed: $path")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,7 +292,12 @@ public final class LinuxRuntime {
|
||||
if (!BuildConfig.PLAY_DISTRIBUTION) return;
|
||||
java.util.LinkedHashSet<File> directories = new java.util.LinkedHashSet<>();
|
||||
directories.add(new File(context.getApplicationInfo().sourceDir).getParentFile());
|
||||
String[] splits = context.getApplicationInfo().splitSourceDirs;
|
||||
String[] splits;
|
||||
try {
|
||||
splits = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).splitSourceDirs;
|
||||
} catch (android.content.pm.PackageManager.NameNotFoundException error) {
|
||||
throw new IllegalStateException(error);
|
||||
}
|
||||
if (splits != null) for (String split : splits) directories.add(new File(split).getParentFile());
|
||||
int index = 0;
|
||||
for (File directory : directories) {
|
||||
|
||||
@@ -57,12 +57,22 @@ fun ChooseAppDisplayDialog(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ConfirmDialog(title: String, text: String, confirm: String, onConfirm: () -> Unit, onDismiss: () -> Unit) {
|
||||
fun ConfirmDialog(title: String, text: String, confirm: String, onConfirm: () -> Unit, onDismiss: () -> Unit,
|
||||
progress: Int? = null, confirmEnabled: Boolean = true, closeOnConfirm: Boolean = true) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = { Text(text) },
|
||||
confirmButton = { TextButton(onClick = { onDismiss(); onConfirm() }, modifier = Modifier.focusGlide(CircleShape)) { Text(confirm) } },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Text(text)
|
||||
if (progress != null) {
|
||||
if (progress >= 0) androidx.compose.material3.LinearProgressIndicator(
|
||||
progress = { progress / 100f }, modifier = Modifier.fillMaxWidth().height(4.dp))
|
||||
else androidx.compose.material3.LinearProgressIndicator(modifier = Modifier.fillMaxWidth().height(4.dp))
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(enabled = confirmEnabled, onClick = { if (closeOnConfirm) onDismiss(); onConfirm() }, modifier = Modifier.focusGlide(CircleShape)) { Text(confirm) } },
|
||||
dismissButton = { TextButton(onClick = onDismiss, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import com.github.luben.zstd.Zstd
|
||||
import com.github.luben.zstd.ZstdInputStream
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
class PlayArchiveFramesTest {
|
||||
private fun tar(name: String, bytes: ByteArray): ByteArray {
|
||||
val output = ByteArrayOutputStream()
|
||||
TarArchiveOutputStream(output).use { archive ->
|
||||
archive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX)
|
||||
val entry = TarArchiveEntry(name).apply { size = bytes.size.toLong(); mode = 493 }
|
||||
archive.putArchiveEntry(entry)
|
||||
archive.write(bytes)
|
||||
archive.closeArchiveEntry()
|
||||
}
|
||||
return output.toByteArray()
|
||||
}
|
||||
|
||||
@Test fun runtimeDecoderReadsCodeAndDataFramesAsOneCompleteArchive() {
|
||||
val code = byteArrayOf(127, 69, 76, 70)
|
||||
val data = byteArrayOf(0, 1, 0, 0, 4, 5, 6)
|
||||
val dataName = "usr/share/fonts/" + "directory/".repeat(12) + "font.ttf"
|
||||
val joined = Zstd.compress(tar("usr/bin/program", code).copyOf(1024), 19) +
|
||||
Zstd.compress(tar(dataName, data), 19)
|
||||
val contents = linkedMapOf<String, ByteArray>()
|
||||
ZstdInputStream(ByteArrayInputStream(joined)).use { decoded ->
|
||||
TarArchiveInputStream(decoded).use { archive ->
|
||||
while (true) {
|
||||
val entry = archive.nextEntry ?: break
|
||||
assertEquals(493, entry.mode)
|
||||
contents[entry.name] = archive.readBytes()
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals(listOf("usr/bin/program", dataName), contents.keys.toList())
|
||||
assertArrayEquals(code, contents["usr/bin/program"])
|
||||
assertArrayEquals(data, contents[dataName])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user