From c44d7c6be64be790878ddf1f21c0d9e91d238245 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 22 Apr 2014 10:17:21 -0700 Subject: [PATCH] Prohibit uninstall of the default (or only) home app We suppress the ability to uninstall (including uninstall of updates to system-bundled apps) when the package in question is either the only installed home app, or has been explicitly tagged by the user as the "every time" home app among all those installed. Bug 14162565 Change-Id: I582bb0d2abf0911ac68813f4c7e6fd7d17bfc2ca --- .../settings/applications/InstalledAppDetails.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java index 1b3938c2d7..cbb06a04a4 100644 --- a/src/com/android/settings/applications/InstalledAppDetails.java +++ b/src/com/android/settings/applications/InstalledAppDetails.java @@ -366,11 +366,28 @@ public class InstalledAppDetails extends Fragment mUninstallButton.setText(R.string.uninstall_text); } } - // If this is a device admin, it can't be uninstall or disabled. + // If this is a device admin, it can't be uninstalled or disabled. // We do this here so the text of the button is still set correctly. if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) { enabled = false; } + + // If this is the default (or only) home app, suppress uninstall (even if + // we still think it should be allowed for other reasons) + if (enabled && mHomePackages.contains(mPackageInfo.packageName)) { + ArrayList homeActivities = new ArrayList(); + ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities); + if (currentDefaultHome == null) { + // 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()); + } + } + mUninstallButton.setEnabled(enabled); if (enabled) { // Register listener -- 2.11.0