Handle PackageManager.NameNotFoundException thrown from

`PackageManager.isAppArchivable` as false

Test: AppArchiveButtonTest
Bug: 333465028
Change-Id: I4ecbdabbf3869615834eda5c3fbe489c5ad9eadb
This commit is contained in:
Mark Kim
2024-04-15 20:00:52 +00:00
parent 02f1db61d8
commit 88dc6c43c3
2 changed files with 23 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ApplicationInfo
import android.content.pm.PackageInstaller
import android.content.pm.PackageManager
import android.os.UserHandle
import android.util.Log
import android.widget.Toast
@@ -87,11 +88,15 @@ class AppArchiveButton(
}
private fun ApplicationInfo.isActionButtonEnabled(): Boolean {
return !isArchived
&& userPackageManager.isAppArchivable(packageName)
// We apply the same device policy for both the uninstallation and archive
// button.
&& !appButtonRepository.isUninstallBlockedByAdmin(this)
return try {
(!isArchived
&& userPackageManager.isAppArchivable(packageName)
// We apply the same device policy for both the uninstallation and archive
// button.
&& !appButtonRepository.isUninstallBlockedByAdmin(this))
} catch (e: PackageManager.NameNotFoundException) {
false
}
}
private fun onArchiveClicked(app: ApplicationInfo) {