Merge "Handle PackageManager.NameNotFoundException thrown from PackageManager.isAppArchivable as false" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
d18aba0792
@@ -21,6 +21,7 @@ import android.content.Intent
|
|||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.pm.PackageInstaller
|
import android.content.pm.PackageInstaller
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@@ -87,11 +88,15 @@ class AppArchiveButton(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun ApplicationInfo.isActionButtonEnabled(): Boolean {
|
private fun ApplicationInfo.isActionButtonEnabled(): Boolean {
|
||||||
return !isArchived
|
return try {
|
||||||
&& userPackageManager.isAppArchivable(packageName)
|
(!isArchived
|
||||||
// We apply the same device policy for both the uninstallation and archive
|
&& userPackageManager.isAppArchivable(packageName)
|
||||||
// button.
|
// We apply the same device policy for both the uninstallation and archive
|
||||||
&& !appButtonRepository.isUninstallBlockedByAdmin(this)
|
// button.
|
||||||
|
&& !appButtonRepository.isUninstallBlockedByAdmin(this))
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onArchiveClicked(app: ApplicationInfo) {
|
private fun onArchiveClicked(app: ApplicationInfo) {
|
||||||
|
|||||||
@@ -109,6 +109,19 @@ class AppArchiveButtonTest {
|
|||||||
assertThat(enabledActionButton.enabled).isFalse()
|
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
|
@Test
|
||||||
fun appArchiveButton_displaysRightTextAndIcon() {
|
fun appArchiveButton_displaysRightTextAndIcon() {
|
||||||
val app = ApplicationInfo().apply {
|
val app = ApplicationInfo().apply {
|
||||||
|
|||||||
Reference in New Issue
Block a user