Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88dc6c43 authored by Mark Kim's avatar Mark Kim
Browse files

Handle PackageManager.NameNotFoundException thrown from

`PackageManager.isAppArchivable` as false

Test: AppArchiveButtonTest
Bug: 333465028
Change-Id: I4ecbdabbf3869615834eda5c3fbe489c5ad9eadb
parent 02f1db61
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -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
        return try {
            (!isArchived
                    && userPackageManager.isAppArchivable(packageName)
                    // We apply the same device policy for both the uninstallation and archive
                    // button.
            && !appButtonRepository.isUninstallBlockedByAdmin(this)
                    && !appButtonRepository.isUninstallBlockedByAdmin(this))
        } catch (e: PackageManager.NameNotFoundException) {
            false
        }
    }

    private fun onArchiveClicked(app: ApplicationInfo) {
+13 −0
Original line number Diff line number Diff line
@@ -109,6 +109,19 @@ class AppArchiveButtonTest {
        assertThat(enabledActionButton.enabled).isFalse()
    }

    @Test
    fun appArchiveButton_whenPackageIsNotFound_isDisabled() {
        val app = ApplicationInfo().apply {
            packageName = PACKAGE_NAME
            isArchived = false
        }
        whenever(userPackageManager.isAppArchivable(app.packageName)).thenThrow(PackageManager.NameNotFoundException())

        val actionButton = setContent(app)

        assertThat(actionButton.enabled).isFalse()
    }

    @Test
    fun appArchiveButton_displaysRightTextAndIcon() {
        val app = ApplicationInfo().apply {