Get and save app label before archiving the app

Test: manual

Bug: 317125320
Change-Id: I34763106f669e3f2c0f349cdec977ceb57291e01
This commit is contained in:
Mark Kim
2024-01-11 10:57:03 +00:00
parent 59d67c3dc2
commit 5e5f1dd724
3 changed files with 15 additions and 6 deletions

View File

@@ -54,6 +54,7 @@ class AppArchiveButton(
private val packageName = packageInfoPresenter.packageName
private val userHandle = UserHandle.of(packageInfoPresenter.userId)
private var broadcastReceiverIsCreated = false
private lateinit var appLabel: CharSequence
@Composable
fun getActionButton(app: ApplicationInfo): ActionButton {
@@ -61,11 +62,12 @@ class AppArchiveButton(
val intentFilter = IntentFilter(INTENT_ACTION)
DisposableBroadcastReceiverAsUser(intentFilter, userHandle) { intent ->
if (app.packageName == intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)) {
onReceive(intent, app)
onReceive(intent)
}
}
broadcastReceiverIsCreated = true
}
appLabel = userPackageManager.getApplicationLabel(app)
return ActionButton(
text = context.getString(R.string.archive),
imageVector = Icons.Outlined.CloudUpload,
@@ -113,10 +115,9 @@ class AppArchiveButton(
}
}
private fun onReceive(intent: Intent, app: ApplicationInfo) {
private fun onReceive(intent: Intent) {
when (val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, Int.MIN_VALUE)) {
PackageInstaller.STATUS_SUCCESS -> {
val appLabel = userPackageManager.getApplicationLabel(app)
Toast.makeText(
context,
context.getString(R.string.archiving_succeeded, appLabel),