Allow uninstallation of current home app

Change the behavior to allow uninstallation of the current home app
if it is a non-system app and/or there are other candidate apps
available.

Bug: 131721576
Test: atest com.android.settings.applications.appinfo.AppButtonsPreferenceControllerTest
Test: atest com.android.settings.spa.app.appinfo.AppButtonRepositoryTest
Change-Id: I556966894240aaf91c0e6424dce514b6a35d1001
This commit is contained in:
lpeter
2023-12-14 09:18:02 +00:00
parent 576acec126
commit b3e2179531
4 changed files with 128 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.om.OverlayManager
import android.content.pm.ApplicationInfo
import android.content.pm.Flags
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.util.Log
@@ -95,7 +96,7 @@ class AppButtonRepository(private val context: Context) {
isDisallowControl(app) -> return false
uninstallDisallowedDueToHomeApp(app.packageName) -> return false
uninstallDisallowedDueToHomeApp(app) -> return false
// Resource overlays can be uninstalled iff they are public (installed on /data) and
// disabled. ("Enabled" means they are in use by resource management.)
@@ -113,7 +114,8 @@ class AppButtonRepository(private val context: Context) {
* can go to Home settings and pick a different one, after which we'll permit uninstallation
* of the now-not-default one.
*/
private fun uninstallDisallowedDueToHomeApp(packageName: String): Boolean {
fun uninstallDisallowedDueToHomeApp(applicationInfo: ApplicationInfo): Boolean {
val packageName = applicationInfo.packageName
val homePackageInfo = getHomePackageInfo()
return when {
packageName !in homePackageInfo.homePackages -> false
@@ -121,8 +123,17 @@ class AppButtonRepository(private val context: Context) {
// Disallow uninstall when this is the only home app.
homePackageInfo.homePackages.size == 1 -> true
// Disallow if this is the explicit default home app.
else -> packageName == homePackageInfo.currentDefaultHome?.packageName
packageName == homePackageInfo.currentDefaultHome?.packageName -> {
if (Flags.improveHomeAppBehavior()) {
// Disallow the uninstallation of the current home app if it is a system app.
return applicationInfo.isSystemApp()
} else {
// Disallow if this is the explicit default home app.
return true
}
}
else -> false
}
}