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

@@ -32,6 +32,7 @@ import android.content.IntentFilter;
import android.content.om.OverlayInfo;
import android.content.om.OverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.Flags;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -434,10 +435,17 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
// No preferred default, so permit uninstall only when
// there is more than one candidate
enabled = (mHomePackages.size() > 1);
} else {
// There is an explicit default home app -- forbid uninstall of
// that one, but permit it for installed-but-inactive ones.
enabled = !mPackageInfo.packageName.equals(currentDefaultHome.getPackageName());
} else if (mPackageInfo.packageName.equals(currentDefaultHome.getPackageName())) {
if (Flags.improveHomeAppBehavior()) {
// Allow uninstallation of current home app if it is a non-system app
// and/or there are other candidate apps available.
if (mPackageInfo.applicationInfo.isSystemApp()
|| mHomePackages.size() == 1) {
enabled = false;
}
} else {
enabled = false;
}
}
}
}