Skip to content

Commit a002468

Browse files
committed
Avoid using broken Parcel constructor of PackageInstaller.SessionParams, causing installation to silently fail
1 parent e741347 commit a002468

File tree

1 file changed

+12
-9
lines changed
  • app/src/main/java/dev/zwander/installwithoptions/util

1 file changed

+12
-9
lines changed

app/src/main/java/dev/zwander/installwithoptions/util/Installer.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.content.Context
55
import android.content.Intent
66
import android.content.IntentFilter
77
import android.content.pm.PackageInstaller
8-
import android.os.Parcel
98
import android.util.Log
109
import androidx.activity.compose.rememberLauncherForActivityResult
1110
import androidx.activity.result.contract.ActivityResultContracts
@@ -56,9 +55,10 @@ data class Installer(
5655
fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
5756
val context = LocalContext.current
5857
val scope = rememberCoroutineScope()
59-
val permissionStarter = rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()) {
60-
Log.e("InstallWithOptions", "permission result ${Settings.gson.toJson(it)}")
61-
}
58+
val permissionStarter =
59+
rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()) {
60+
Log.e("InstallWithOptions", "permission result ${Settings.gson.toJson(it)}")
61+
}
6262

6363
var statuses by remember {
6464
mutableStateOf<List<Pair<String, String>>>(listOf())
@@ -82,7 +82,7 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
8282
override fun applyOptions(params: PackageInstaller.SessionParams): PackageInstaller.SessionParams {
8383
getMutableOptions().forEach { it.apply(params) }
8484

85-
return PackageInstaller.SessionParams(Parcel.obtain().apply { params.writeToParcel(this, 0) })
85+
return params
8686
}
8787
}
8888
}
@@ -126,8 +126,8 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
126126
isInstalling = true
127127
}
128128

129-
try {
130-
scope.launch(Dispatchers.IO) {
129+
scope.launch(Dispatchers.IO) {
130+
try {
131131
shellInterface?.install(
132132
files.map {
133133
context.contentResolver.openAssetFileDescriptor(
@@ -140,9 +140,12 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
140140
applier,
141141
MutableOption.InstallerPackage.settingsKey.getValue(),
142142
)
143+
} catch (e: Exception) {
144+
statuses = files.map {
145+
(it.name ?: it.uri.toString()) to (e.localizedMessage ?: e.message
146+
?: e.toString())
147+
}
143148
}
144-
} catch (e: Exception) {
145-
statuses = files.map{ (it.name ?: it.uri.toString()) to (e.localizedMessage ?: e.message ?: e.toString()) }
146149
}
147150
}
148151

0 commit comments

Comments
 (0)