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
diff --git a/packages/PackageInstaller/res/values/strings.xml b/packages/PackageInstaller/res/values/strings.xml
index ca3ec3c..688d116 100644
--- a/packages/PackageInstaller/res/values/strings.xml
+++ b/packages/PackageInstaller/res/values/strings.xml
@@ -112,6 +112,8 @@
<!-- [CHAR LIMIT=none] -->
<string name="uninstall_application_text_user">Do you want to uninstall this app for the user <xliff:g id="username">%1$s</xliff:g>?</string>
<!-- [CHAR LIMIT=none] -->
+ <string name="uninstall_application_text_current_user_work_profile">Do you want to uninstall this app from your work profile?</string>
+ <!-- [CHAR LIMIT=none] -->
<string name="uninstall_update_text">Replace this app with the factory version? All data will be removed.</string>
<!-- [CHAR LIMIT=none] -->
<string name="uninstall_update_text_multiuser">Replace this app with the factory version? All data will be removed. This affects all users of this device, including those with work profiles.</string>
diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
index 99f6a92..36294ac 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.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 @@
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 @@
} 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 21d25f5..2d241ca 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.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 @@
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 @@
} 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));
}