Merge "Allow uninstallation of current home app" into main

This commit is contained in:
Joanne Chung
2024-02-02 05:02:50 +00:00
committed by Android (Google) Code Review
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;
}
}
}
}

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
}
}