From 3f4b629cd16b47610bff6fc2ae4b468c20bba99a Mon Sep 17 00:00:00 2001 From: Winson Date: Wed, 17 Nov 2021 14:00:21 -0800 Subject: [PATCH] Add specific uninstall dialog string for work profile Prompts the user with "Do you want to uninstall this app from the work profile?" when uninstalling an app where PackageInstaller was started from the parent profile specifically targeting the child managed profile. Bug: 193792780 Test: manual, test app which sends DELETE action Change-Id: I4e4295badfcd022452715e4657ce78eff027c1f9 --- .../PackageInstaller/res/values/strings.xml | 2 ++ .../handheld/UninstallAlertDialogFragment.java | 15 ++++++++++++--- .../television/UninstallAlertFragment.java | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/PackageInstaller/res/values/strings.xml b/packages/PackageInstaller/res/values/strings.xml index ca3ec3cf5b8ba..688d116914774 100644 --- a/packages/PackageInstaller/res/values/strings.xml +++ b/packages/PackageInstaller/res/values/strings.xml @@ -112,6 +112,8 @@ Do you want to uninstall this app for the user %1$s? + Do you want to uninstall this app from your work profile? + Replace this app with the factory version? All data will be removed. Replace this app with the factory version? All data will be removed. This affects all users of this device, including those with work profiles. diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java index 99f6a92206b99..36294ac040a60 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java @@ -31,6 +31,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.os.Bundle; +import android.os.Process; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; @@ -125,6 +126,7 @@ public class UninstallAlertDialogFragment extends DialogFragment implements final boolean isUpdate = ((dialogInfo.appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0); + final UserHandle myUserHandle = Process.myUserHandle(); UserManager userManager = UserManager.get(getActivity()); if (isUpdate) { if (isSingleUser(userManager)) { @@ -135,10 +137,17 @@ public class UninstallAlertDialogFragment extends DialogFragment implements } else { if (dialogInfo.allUsers && !isSingleUser(userManager)) { messageBuilder.append(getString(R.string.uninstall_application_text_all_users)); - } else if (!dialogInfo.user.equals(android.os.Process.myUserHandle())) { + } else if (!dialogInfo.user.equals(myUserHandle)) { UserInfo userInfo = userManager.getUserInfo(dialogInfo.user.getIdentifier()); - messageBuilder.append( - getString(R.string.uninstall_application_text_user, userInfo.name)); + if (userInfo.isManagedProfile() + && userInfo.profileGroupId == myUserHandle.getIdentifier()) { + messageBuilder.append( + getString(R.string.uninstall_application_text_current_user_work_profile, + userInfo.name)); + } else { + messageBuilder.append( + getString(R.string.uninstall_application_text_user, userInfo.name)); + } } else { messageBuilder.append(getString(R.string.uninstall_application_text)); } diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/television/UninstallAlertFragment.java b/packages/PackageInstaller/src/com/android/packageinstaller/television/UninstallAlertFragment.java index 21d25f5b030fd..2d241ca9038eb 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/television/UninstallAlertFragment.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/television/UninstallAlertFragment.java @@ -21,7 +21,10 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.os.Bundle; +import android.os.Process; +import android.os.UserHandle; import android.os.UserManager; + import androidx.leanback.app.GuidedStepFragment; import androidx.leanback.widget.GuidanceStylist; import androidx.leanback.widget.GuidedAction; @@ -59,6 +62,7 @@ public class UninstallAlertFragment extends GuidedStepFragment { final boolean isUpdate = ((dialogInfo.appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0); + final UserHandle myUserHandle = Process.myUserHandle(); UserManager userManager = UserManager.get(getActivity()); if (isUpdate) { if (isSingleUser(userManager)) { @@ -69,10 +73,17 @@ public class UninstallAlertFragment extends GuidedStepFragment { } else { if (dialogInfo.allUsers && !isSingleUser(userManager)) { messageBuilder.append(getString(R.string.uninstall_application_text_all_users)); - } else if (!dialogInfo.user.equals(android.os.Process.myUserHandle())) { + } else if (!dialogInfo.user.equals(myUserHandle)) { UserInfo userInfo = userManager.getUserInfo(dialogInfo.user.getIdentifier()); - messageBuilder.append( - getString(R.string.uninstall_application_text_user, userInfo.name)); + if (userInfo.isManagedProfile() + && userInfo.profileGroupId == myUserHandle.getIdentifier()) { + messageBuilder.append( + getString(R.string.uninstall_application_text_current_user_work_profile, + userInfo.name)); + } else { + messageBuilder.append( + getString(R.string.uninstall_application_text_user, userInfo.name)); + } } else { messageBuilder.append(getString(R.string.uninstall_application_text)); }