Update warning dialog on work profile deletion.
Bug: 20024761 Change-Id: I23b0eaa7742d9d23a29a2a48ab6e3d92fe310560
This commit is contained in:
73
res/layout/delete_managed_profile_dialog.xml
Normal file
73
res/layout/delete_managed_profile_dialog.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/delete_profile_dialog_padding_top"
|
||||
android:paddingLeft="@dimen/delete_profile_dialog_padding_left_right"
|
||||
android:paddingRight="@dimen/delete_profile_dialog_padding_left_right"
|
||||
android:fadeScrollbars="false" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/delete_managed_profile_opening_paragraph"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/opening_paragraph_delete_profile_unknown_company"
|
||||
style="@style/TextAppearance.RemoveDialogContent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/mdm_app_info_height"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="@dimen/mdm_app_info_padding_top_bottom"
|
||||
android:paddingTop="@dimen/mdm_app_info_padding_top_bottom" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete_managed_profile_mdm_icon_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="centerInside"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/delete_managed_profile_device_manager_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/mdm_app_name_padding_left"
|
||||
style="@style/TextAppearance.RemoveDialogContent" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/delete_managed_profile_closing_paragraph"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/work_profile_confirm_remove_message"
|
||||
style="@style/TextAppearance.RemoveDialogContent" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@@ -232,4 +232,11 @@
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="fab_elevation">12dp</dimen>
|
||||
<dimen name="fab_press_translation_z">9dp</dimen>
|
||||
|
||||
<!-- Delete managed profile dialog -->
|
||||
<dimen name="delete_profile_dialog_padding_top">16dp</dimen>
|
||||
<dimen name="delete_profile_dialog_padding_left_right">24dp</dimen>
|
||||
<dimen name="mdm_app_info_height">72dp</dimen>
|
||||
<dimen name="mdm_app_info_padding_top_bottom">8dp</dimen>
|
||||
<dimen name="mdm_app_name_padding_left">16dp</dimen>
|
||||
</resources>
|
||||
|
@@ -5443,7 +5443,7 @@
|
||||
<!-- User removal confirmation message [CHAR LIMIT=none] -->
|
||||
<string name="user_confirm_remove_message">All apps and data will be deleted.</string>
|
||||
<!-- Work profile removal confirmation message [CHAR LIMIT=none] -->
|
||||
<string name="work_profile_confirm_remove_message">All apps and data in this profile will be deleted.</string>
|
||||
<string name="work_profile_confirm_remove_message">All apps and data in this profile will be deleted if you continue.</string>
|
||||
<!-- User profile removal confirmation message [CHAR LIMIT=none] -->
|
||||
<string name="user_profile_confirm_remove_message">All apps and data will be deleted.</string>
|
||||
<!-- Setting label to show that a new user is being added [CHAR LIMIT=30] -->
|
||||
@@ -6275,6 +6275,8 @@
|
||||
|
||||
<!-- Title for a work profile. [CHAR LIMIT=25] -->
|
||||
<string name="managed_user_title">Work profile</string>
|
||||
<!-- Opening string on the dialog that prompts the user to confirm that they really want to delete their existing work profile. The administration app icon and name appear after the final colon. [CHAR LIMIT=NONE] -->
|
||||
<string name="opening_paragraph_delete_profile_unknown_company">This profile is managed by:</string>
|
||||
|
||||
<!-- Summary Title for saying that the preference is experimental and will evolve over time due to User feedback. [CHAR LIMIT=NONE] -->
|
||||
<string name="experimental_preference">(Experimental)</string>
|
||||
|
@@ -327,4 +327,9 @@
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:textStyle">normal</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
<style name="TextAppearance.RemoveDialogContent" parent="@android:style/TextAppearance.Material">
|
||||
<item name="android:textSize">16sp</item>
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
</style>
|
||||
</resources>
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user