From bc95630994227736aff46885ca1d9345829e83e2 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Thu, 9 Apr 2015 12:19:53 +0100 Subject: [PATCH] Update warning dialog on work profile deletion. Bug: 20024761 Change-Id: I23b0eaa7742d9d23a29a2a48ab6e3d92fe310560 --- res/layout/delete_managed_profile_dialog.xml | 73 +++++++++++++++++ res/values/dimens.xml | 7 ++ res/values/strings.xml | 4 +- res/values/styles.xml | 7 +- src/com/android/settings/Utils.java | 28 ++++++- .../android/settings/users/UserDialogs.java | 81 ++++++++++++++----- 6 files changed, 177 insertions(+), 23 deletions(-) create mode 100644 res/layout/delete_managed_profile_dialog.xml diff --git a/res/layout/delete_managed_profile_dialog.xml b/res/layout/delete_managed_profile_dialog.xml new file mode 100644 index 00000000000..da763c9c1b1 --- /dev/null +++ b/res/layout/delete_managed_profile_dialog.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 30be6e867b1..e4e925588eb 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -232,4 +232,11 @@ 16dp 12dp 9dp + + + 16dp + 24dp + 72dp + 8dp + 16dp diff --git a/res/values/strings.xml b/res/values/strings.xml index 0b9842856aa..e08b692c64f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5443,7 +5443,7 @@ All apps and data will be deleted. - All apps and data in this profile will be deleted. + All apps and data in this profile will be deleted if you continue. All apps and data will be deleted. @@ -6275,6 +6275,8 @@ Work profile + + This profile is managed by: (Experimental) diff --git a/res/values/styles.xml b/res/values/styles.xml index 7a917a96200..d0d2ead3229 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -327,4 +327,9 @@ ?android:attr/textColorPrimary normal - + + + \ No newline at end of file diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index d05160c3855..4ddba80522b 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -22,9 +22,11 @@ import android.annotation.Nullable; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.app.AlertDialog; +import android.app.AppGlobals; import android.app.Dialog; import android.app.Fragment; import android.app.IActivityManager; +import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; @@ -32,6 +34,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; +import android.content.pm.IPackageManager; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -1153,4 +1156,27 @@ public final class Utils { view.setVisibility(shown ? View.VISIBLE : View.INVISIBLE); } } -} + + /** + * Returns the application info of the currently installed MDM package. + */ + public static ApplicationInfo getAdminApplicationInfo(Context context, int profileId) { + DevicePolicyManager dpm = + (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); + ComponentName mdmPackage = dpm.getProfileOwnerAsUser(profileId); + if (mdmPackage == null) { + return null; + } + String mdmPackageName = mdmPackage.getPackageName(); + try { + IPackageManager ipm = AppGlobals.getPackageManager(); + ApplicationInfo mdmApplicationInfo = + ipm.getApplicationInfo(mdmPackageName, 0, profileId); + return mdmApplicationInfo; + } catch (RemoteException e) { + Log.e(TAG, "Error while retrieving application info for package " + mdmPackageName + + ", userId " + profileId, e); + return null; + } + } +} \ No newline at end of file diff --git a/src/com/android/settings/users/UserDialogs.java b/src/com/android/settings/users/UserDialogs.java index 2d92464ac13..23012b3f3bc 100644 --- a/src/com/android/settings/users/UserDialogs.java +++ b/src/com/android/settings/users/UserDialogs.java @@ -20,11 +20,19 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.content.pm.UserInfo; +import android.graphics.drawable.Drawable; import android.os.UserHandle; import android.os.UserManager; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; import com.android.settings.R; +import com.android.settings.Utils; /** * Helper class for displaying dialogs related to user settings. @@ -44,27 +52,60 @@ public final class UserDialogs { DialogInterface.OnClickListener onConfirmListener) { UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); UserInfo userInfo = um.getUserInfo(removingUserId); - int titleResId; - int messageResId; - if (UserHandle.myUserId() == removingUserId) { - titleResId = R.string.user_confirm_remove_self_title; - messageResId = R.string.user_confirm_remove_self_message; - } else if (userInfo.isRestricted()) { - titleResId = R.string.user_profile_confirm_remove_title; - messageResId = R.string.user_profile_confirm_remove_message; - } else if (userInfo.isManagedProfile()) { - titleResId = R.string.work_profile_confirm_remove_title; - messageResId = R.string.work_profile_confirm_remove_message; - } else { - titleResId = R.string.user_confirm_remove_title; - messageResId = R.string.user_confirm_remove_message; - } - return new AlertDialog.Builder(context) - .setTitle(titleResId) - .setMessage(messageResId) + AlertDialog.Builder builder = new AlertDialog.Builder(context) .setPositiveButton(R.string.user_delete_button, onConfirmListener) - .setNegativeButton(android.R.string.cancel, null) - .create(); + .setNegativeButton(android.R.string.cancel, null); + if (UserHandle.myUserId() == removingUserId) { + builder.setTitle(R.string.user_confirm_remove_self_title); + builder.setMessage(R.string.user_confirm_remove_self_message); + } else if (userInfo.isRestricted()) { + builder.setTitle(R.string.user_profile_confirm_remove_title); + builder.setMessage(R.string.user_profile_confirm_remove_message); + } else if (userInfo.isManagedProfile()) { + builder.setTitle(R.string.work_profile_confirm_remove_title); + View view = createRemoveManagedUserDialogView(context, removingUserId); + if (view != null) { + builder.setView(view); + } else { + builder.setMessage(R.string.work_profile_confirm_remove_message); + } + } else { + builder.setTitle(R.string.user_confirm_remove_title); + builder.setMessage(R.string.user_confirm_remove_message); + } + return builder.create(); + } + + /** + * Creates a view to be used in the confirmation dialog for removing work profile. + */ + private static View createRemoveManagedUserDialogView(Context context, int userId) { + PackageManager packageManager = context.getPackageManager(); + ApplicationInfo mdmApplicationInfo = Utils.getAdminApplicationInfo(context, userId); + if (mdmApplicationInfo == null) { + return null; + } + LayoutInflater inflater = + (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + View view = inflater.inflate(R.layout.delete_managed_profile_dialog, null); + ImageView imageView = + (ImageView) view.findViewById(R.id.delete_managed_profile_mdm_icon_view); + Drawable badgedApplicationIcon = packageManager.getUserBadgedIcon( + packageManager.getApplicationIcon(mdmApplicationInfo), new UserHandle(userId)); + imageView.setImageDrawable(badgedApplicationIcon); + + CharSequence appLabel = packageManager.getApplicationLabel(mdmApplicationInfo); + CharSequence badgedAppLabel = packageManager.getUserBadgedLabel(appLabel, + new UserHandle(userId)); + TextView textView = + (TextView) view.findViewById(R.id.delete_managed_profile_device_manager_name); + textView.setText(appLabel); + if (!appLabel.toString().contentEquals(badgedAppLabel)) { + textView.setContentDescription(badgedAppLabel); + } + + return view; } /**