Add support messages to device admin pages.
Add support message to device admin settings pages. Show policy information for device owners and profile owners. Allow a user to remove profile from profile owners admin page. Bug: 26416662 Change-Id: I95424da50067b7c0ba1618a083a31448d406188f
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:paddingBottom="@dimen/admin_details_dialog_padding">
|
android:paddingBottom="@dimen/admin_details_dialog_padding">
|
||||||
<ImageView
|
<ImageView android:id="@+id/admin_support_icon"
|
||||||
android:layout_width="@dimen/admin_details_dialog_icon_size"
|
android:layout_width="@dimen/admin_details_dialog_icon_size"
|
||||||
android:layout_height="@dimen/admin_details_dialog_icon_size"
|
android:layout_height="@dimen/admin_details_dialog_icon_size"
|
||||||
android:src="@drawable/ic_settings_lock_outline"
|
android:src="@drawable/ic_settings_lock_outline"
|
||||||
@@ -46,25 +46,23 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<TextView android:id="@+id/disabled_by_admin_msg"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
|
||||||
android:textColor="?android:attr/textColorSecondary" />
|
|
||||||
<TextView android:id="@+id/admin_support_msg"
|
<TextView android:id="@+id/admin_support_msg"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||||
|
android:text="@string/default_admin_support_msg"
|
||||||
|
android:maxLength="200"
|
||||||
|
android:autoLink="email|phone"
|
||||||
android:textColor="?android:attr/textColorSecondary" />
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
<TextView android:id="@+id/admins_policies_list"
|
<TextView android:id="@+id/admins_policies_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="@dimen/admin_details_dialog_link_padding_top"
|
android:paddingTop="@dimen/admin_details_dialog_link_padding_top"
|
||||||
android:text="@string/list_of_administrators"
|
android:text="@string/admin_support_more_info"
|
||||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||||
android:textColor="?android:attr/colorAccent"
|
android:textColor="?android:attr/colorAccent"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:background="?android:attr/selectableItemBackground" />
|
android:background="?android:attr/selectableItemBackground" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -100,8 +100,10 @@
|
|||||||
<TextView android:id="@+id/admin_warning"
|
<TextView android:id="@+id/admin_warning"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:padding="10dip" />
|
android:padding="10dip" />
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/admin_policies"
|
<LinearLayout android:id="@+id/admin_policies"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -109,6 +111,13 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingStart="16dip"
|
android:paddingStart="16dip"
|
||||||
android:paddingEnd="12dip" />
|
android:paddingEnd="12dip" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/admin_support_message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:autoLink="email|phone"
|
||||||
|
android:padding="10dip" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -4435,7 +4435,6 @@
|
|||||||
<!-- Message when there are no available device admins to display -->
|
<!-- Message when there are no available device admins to display -->
|
||||||
<string name="no_device_admins">No available device administrators</string>
|
<string name="no_device_admins">No available device administrators</string>
|
||||||
<!-- Message displayed when the device admin can only be disabled by deleting the work profile [CHAR_LIMIT=120] -->
|
<!-- Message displayed when the device admin can only be disabled by deleting the work profile [CHAR_LIMIT=120] -->
|
||||||
<string name="managed_profile_device_admin_info">To stop <xliff:g id="app_name">%1$s</xliff:g> from accessing your work profile, remove the profile under Settings > Accounts</string>
|
|
||||||
<!-- Title for personal device admins on the list [CHAR_LIMIT=25] -->
|
<!-- Title for personal device admins on the list [CHAR_LIMIT=25] -->
|
||||||
<string name="personal_device_admin_title">Personal</string>
|
<string name="personal_device_admin_title">Personal</string>
|
||||||
<!-- Title for managed device admins on the list [CHAR_LIMIT=25] -->
|
<!-- Title for managed device admins on the list [CHAR_LIMIT=25] -->
|
||||||
@@ -6712,11 +6711,18 @@
|
|||||||
<string name="about_summary">Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
|
<string name="about_summary">Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
|
||||||
|
|
||||||
<!-- TODO: Update these strings with the finalized ones. -->
|
<!-- TODO: Update these strings with the finalized ones. -->
|
||||||
|
<!-- Title for dialog displayed when user clicks on a setting locked by an admin [CHAR LIMIT=30] -->
|
||||||
<string name="disabled_by_policy_title">Disabled by policy</string>
|
<string name="disabled_by_policy_title">Disabled by policy</string>
|
||||||
<string name="disabled_by_admin_msg">Disabled by your <xliff:g id="organisation_name" example="organisation">%s</xliff:g>\'s administrator.</string>
|
<!-- Shown when the user tries to change a settings locked by an admin [CHAR LIMIT=200] -->
|
||||||
<string name="default_organisation_name">organisation</string>
|
<string name="default_admin_support_msg">Disabled by your organisation\'s administrator.\nContact them to learn more.</string>
|
||||||
<string name="default_admin_support_msg">Contact them to learn more.</string>
|
<!-- Shown in dialog to allow user to see more information about the device admin [CHAR LIMIT=30] -->
|
||||||
<string name="list_of_administrators">List of administrators</string>
|
<string name="admin_support_more_info">More details</string>
|
||||||
|
<!-- Shown in admin details page to warn user about policies the admin can set in a work profile. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="admin_profile_owner_message">Your administrator has the ability to monitor and manage settings, corporate access, apps, permissions, and data associated with the profile, including network activity and your device\'s location information.</string>
|
||||||
|
<!-- Shown in admin details page to warn user about policies the admin can set on a user. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="admin_profile_owner_user_message">Your administrator has the ability to monitor and manage settings, corporate access, apps, permissions, and data associated with this user, including network activity and your device\'s location information.</string>
|
||||||
|
<!-- Shown in admin details page to warn user about policies the admin can set on a device. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="admin_device_owner_message">Your administrator has the ability to monitor and manage settings, corporate access, apps, permissions, and data associated with this device, including network activity and your device\'s location information.</string>
|
||||||
|
|
||||||
<!-- Turn off a conditional state of the device (e.g. airplane mode, or hotspot) [CHAR LIMIT=30] -->
|
<!-- Turn off a conditional state of the device (e.g. airplane mode, or hotspot) [CHAR LIMIT=30] -->
|
||||||
<string name="condition_turn_off">Turn off</string>
|
<string name="condition_turn_off">Turn off</string>
|
||||||
|
@@ -34,6 +34,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -42,6 +43,7 @@ import android.os.RemoteCallback;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.TextUtils.TruncateAt;
|
import android.text.TextUtils.TruncateAt;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -55,6 +57,8 @@ import android.widget.Button;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.settings.users.UserDialogs;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -86,6 +90,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
ImageView mAddMsgExpander;
|
ImageView mAddMsgExpander;
|
||||||
boolean mAddMsgEllipsized = true;
|
boolean mAddMsgEllipsized = true;
|
||||||
TextView mAdminWarning;
|
TextView mAdminWarning;
|
||||||
|
TextView mSupportMessage;
|
||||||
ViewGroup mAdminPolicies;
|
ViewGroup mAdminPolicies;
|
||||||
Button mActionButton;
|
Button mActionButton;
|
||||||
Button mCancelButton;
|
Button mCancelButton;
|
||||||
@@ -279,6 +284,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
|
|
||||||
mAdminWarning = (TextView) findViewById(R.id.admin_warning);
|
mAdminWarning = (TextView) findViewById(R.id.admin_warning);
|
||||||
mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
|
mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
|
||||||
|
mSupportMessage = (TextView) findViewById(R.id.admin_support_message);
|
||||||
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
||||||
mCancelButton.setFilterTouchesWhenObscured(true);
|
mCancelButton.setFilterTouchesWhenObscured(true);
|
||||||
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -294,6 +300,19 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mAdding) {
|
if (mAdding) {
|
||||||
addAndFinish();
|
addAndFinish();
|
||||||
|
} else if (isManagedProfile(mDeviceAdmin)
|
||||||
|
&& mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner())) {
|
||||||
|
final int userId = UserHandle.myUserId();
|
||||||
|
UserDialogs.createRemoveDialog(DeviceAdminAdd.this, userId,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
UserManager um = UserManager.get(DeviceAdminAdd.this);
|
||||||
|
um.removeUser(userId);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).show();
|
||||||
} else if (!mWaitingForRemoveMsg) {
|
} else if (!mWaitingForRemoveMsg) {
|
||||||
try {
|
try {
|
||||||
// Don't allow the admin to put a dialog up in front
|
// Don't allow the admin to put a dialog up in front
|
||||||
@@ -451,12 +470,42 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
}
|
}
|
||||||
if (!mRefreshing && !mAddingProfileOwner
|
if (!mRefreshing && !mAddingProfileOwner
|
||||||
&& mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
|
&& mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
|
||||||
addDeviceAdminPolicies(false /* showDescription */);
|
|
||||||
mAdminWarning.setText(getString(R.string.device_admin_status,
|
|
||||||
mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
|
|
||||||
setTitle(getText(R.string.active_device_admin_msg));
|
|
||||||
mActionButton.setText(getText(R.string.remove_device_admin));
|
|
||||||
mAdding = false;
|
mAdding = false;
|
||||||
|
final boolean isProfileOwner =
|
||||||
|
mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner());
|
||||||
|
final boolean isManagedProfile = isManagedProfile(mDeviceAdmin);
|
||||||
|
if (isProfileOwner && isManagedProfile) {
|
||||||
|
// Profile owner in a managed profile, user can remove profile to disable admin.
|
||||||
|
mAdminWarning.setText(R.string.admin_profile_owner_message);
|
||||||
|
mActionButton.setText(R.string.remove_managed_profile_label);
|
||||||
|
} else if (isProfileOwner || mDeviceAdmin.getComponent().equals(
|
||||||
|
mDPM.getDeviceOwnerComponentOnCallingUser())) {
|
||||||
|
// Profile owner in a user or device owner, user can't disable admin.
|
||||||
|
if (isProfileOwner) {
|
||||||
|
// Show profile owner in a user description.
|
||||||
|
mAdminWarning.setText(R.string.admin_profile_owner_user_message);
|
||||||
|
} else {
|
||||||
|
// Show device owner description.
|
||||||
|
mAdminWarning.setText(R.string.admin_device_owner_message);
|
||||||
|
}
|
||||||
|
mActionButton.setText(R.string.remove_device_admin);
|
||||||
|
mActionButton.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
addDeviceAdminPolicies(false /* showDescription */);
|
||||||
|
mAdminWarning.setText(getString(R.string.device_admin_status,
|
||||||
|
mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(
|
||||||
|
getPackageManager())));
|
||||||
|
setTitle(R.string.active_device_admin_msg);
|
||||||
|
mActionButton.setText(R.string.remove_device_admin);
|
||||||
|
}
|
||||||
|
String supportMessage = mDPM.getLongSupportMessageForUser(
|
||||||
|
mDeviceAdmin.getComponent(), UserHandle.myUserId());
|
||||||
|
if (!TextUtils.isEmpty(supportMessage)) {
|
||||||
|
mSupportMessage.setText(supportMessage);
|
||||||
|
mSupportMessage.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mSupportMessage.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addDeviceAdminPolicies(true /* showDescription */);
|
addDeviceAdminPolicies(true /* showDescription */);
|
||||||
mAdminWarning.setText(getString(R.string.device_admin_warning,
|
mAdminWarning.setText(getString(R.string.device_admin_warning,
|
||||||
@@ -467,6 +516,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
setTitle(getText(R.string.add_device_admin_msg));
|
setTitle(getText(R.string.add_device_admin_msg));
|
||||||
}
|
}
|
||||||
mActionButton.setText(getText(R.string.add_device_admin));
|
mActionButton.setText(getText(R.string.add_device_admin));
|
||||||
|
mSupportMessage.setVisibility(View.GONE);
|
||||||
mAdding = true;
|
mAdding = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -505,4 +555,13 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
MAX_ADD_MSG_LINES_PORTRAIT : MAX_ADD_MSG_LINES_LANDSCAPE;
|
MAX_ADD_MSG_LINES_PORTRAIT : MAX_ADD_MSG_LINES_LANDSCAPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if adminInfo is running in a managed profile.
|
||||||
|
*/
|
||||||
|
private boolean isManagedProfile(DeviceAdminInfo adminInfo) {
|
||||||
|
UserManager um = UserManager.get(this);
|
||||||
|
UserInfo info = um.getUserInfo(
|
||||||
|
UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid));
|
||||||
|
return info != null ? info.isManagedProfile() : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -59,12 +59,29 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
private DevicePolicyManager mDPM;
|
private DevicePolicyManager mDPM;
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
|
|
||||||
|
|
||||||
|
private static class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
|
||||||
|
public DeviceAdminInfo info;
|
||||||
|
|
||||||
|
// These aren't updated so they keep a stable sort order if user activates / de-activates
|
||||||
|
// an admin.
|
||||||
|
public String name;
|
||||||
|
public boolean active;
|
||||||
|
|
||||||
|
public int compareTo(DeviceAdminListItem other) {
|
||||||
|
// Sort active admins first, then by name.
|
||||||
|
if (this.active != other.active) {
|
||||||
|
return this.active ? -1 : 1;
|
||||||
|
}
|
||||||
|
return this.name.compareTo(other.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Internal collection of device admin info objects for all profiles associated with the current
|
* Internal collection of device admin info objects for all profiles associated with the current
|
||||||
* user.
|
* user.
|
||||||
*/
|
*/
|
||||||
private final SparseArray<ArrayList<DeviceAdminInfo>>
|
private final ArrayList<DeviceAdminListItem>
|
||||||
mAdminsByProfile = new SparseArray<ArrayList<DeviceAdminInfo>>();
|
mAdmins = new ArrayList<DeviceAdminListItem>();
|
||||||
|
|
||||||
private String mDeviceOwnerPkg;
|
private String mDeviceOwnerPkg;
|
||||||
private SparseArray<ComponentName> mProfileOwnerComponents = new SparseArray<ComponentName>();
|
private SparseArray<ComponentName> mProfileOwnerComponents = new SparseArray<ComponentName>();
|
||||||
@@ -133,7 +150,7 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
* current user.
|
* current user.
|
||||||
*/
|
*/
|
||||||
void updateList() {
|
void updateList() {
|
||||||
mAdminsByProfile.clear();
|
mAdmins.clear();
|
||||||
|
|
||||||
final List<UserHandle> profiles = mUm.getUserProfiles();
|
final List<UserHandle> profiles = mUm.getUserProfiles();
|
||||||
final int profilesSize = profiles.size();
|
final int profilesSize = profiles.size();
|
||||||
@@ -141,6 +158,7 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
final int profileId = profiles.get(i).getIdentifier();
|
final int profileId = profiles.get(i).getIdentifier();
|
||||||
updateAvailableAdminsForProfile(profileId);
|
updateAvailableAdminsForProfile(profileId);
|
||||||
}
|
}
|
||||||
|
Collections.sort(mAdmins);
|
||||||
|
|
||||||
getListView().setAdapter(new PolicyListAdapter());
|
getListView().setAdapter(new PolicyListAdapter());
|
||||||
}
|
}
|
||||||
@@ -148,25 +166,12 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
Object o = l.getAdapter().getItem(position);
|
Object o = l.getAdapter().getItem(position);
|
||||||
if (!(o instanceof DeviceAdminInfo)) {
|
|
||||||
// race conditions may cause this
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DeviceAdminInfo dpi = (DeviceAdminInfo) o;
|
DeviceAdminInfo dpi = (DeviceAdminInfo) o;
|
||||||
|
final UserHandle user = new UserHandle(getUserId(dpi));
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
final int userId = getUserId(dpi);
|
Intent intent = new Intent(activity, DeviceAdminAdd.class);
|
||||||
if (userId == UserHandle.myUserId() || !isProfileOwner(dpi)) {
|
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
|
||||||
Intent intent = new Intent();
|
activity.startActivityAsUser(intent, user);
|
||||||
intent.setClass(activity, DeviceAdminAdd.class);
|
|
||||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
|
|
||||||
activity.startActivityAsUser(intent, new UserHandle(userId));
|
|
||||||
} else {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
||||||
builder.setMessage(getString(R.string.managed_profile_device_admin_info,
|
|
||||||
dpi.loadLabel(activity.getPackageManager())));
|
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder {
|
static class ViewHolder {
|
||||||
@@ -191,55 +196,17 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
int adminCount = 0;
|
return mAdmins.size();
|
||||||
final int profileCount = mAdminsByProfile.size();
|
|
||||||
for (int i = 0; i < profileCount; ++i) {
|
|
||||||
adminCount += mAdminsByProfile.valueAt(i).size();
|
|
||||||
}
|
|
||||||
// Add 'profileCount' for title items.
|
|
||||||
return adminCount + profileCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item for the given position in the list.
|
* The item for the given position in the list.
|
||||||
*
|
*
|
||||||
* @return a String object for title items and a DeviceAdminInfo object for actual device
|
* @return DeviceAdminInfo object for actual device admins.
|
||||||
* admins.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
if (position < 0) {
|
return ((DeviceAdminListItem) (mAdmins.get(position))).info;
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
// The position of the item in the list of admins.
|
|
||||||
// We start from the given position and discount the length of the upper lists until we
|
|
||||||
// get the one for the right profile
|
|
||||||
int adminPosition = position;
|
|
||||||
final int n = mAdminsByProfile.size();
|
|
||||||
int i = 0;
|
|
||||||
for (; i < n; ++i) {
|
|
||||||
// The elements in that section including the title item (that's why adding one).
|
|
||||||
final int listSize = mAdminsByProfile.valueAt(i).size() + 1;
|
|
||||||
if (adminPosition < listSize) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
adminPosition -= listSize;
|
|
||||||
}
|
|
||||||
if (i == n) {
|
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
// If countdown == 0 that means the title item
|
|
||||||
if (adminPosition == 0) {
|
|
||||||
Resources res = getActivity().getResources();
|
|
||||||
if (mAdminsByProfile.keyAt(i) == UserHandle.myUserId()) {
|
|
||||||
return res.getString(R.string.personal_device_admin_title);
|
|
||||||
} else {
|
|
||||||
return res.getString(R.string.managed_device_admin_title);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Subtracting one for the title.
|
|
||||||
return mAdminsByProfile.valueAt(i).get(adminPosition - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -257,16 +224,15 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getViewTypeCount() {
|
public int getViewTypeCount() {
|
||||||
return 2;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns 1 for title items and 0 for anything else.
|
* Returns 0 for all types.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
Object o = getItem(position);
|
return 0;
|
||||||
return (o instanceof String) ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -276,15 +242,7 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEnabled(Object o) {
|
private boolean isEnabled(Object o) {
|
||||||
if (!(o instanceof DeviceAdminInfo)) {
|
|
||||||
// Title item
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DeviceAdminInfo info = (DeviceAdminInfo) o;
|
DeviceAdminInfo info = (DeviceAdminInfo) o;
|
||||||
if (isActiveAdmin(info) && getUserId(info) == UserHandle.myUserId()
|
|
||||||
&& (isDeviceOwner(info) || isProfileOwner(info))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Disable item if admin is being removed
|
// Disable item if admin is being removed
|
||||||
if (isRemovingAdmin(info)) {
|
if (isRemovingAdmin(info)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -295,28 +253,20 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
Object o = getItem(position);
|
Object o = getItem(position);
|
||||||
if (o instanceof DeviceAdminInfo) {
|
if (convertView == null) {
|
||||||
if (convertView == null) {
|
convertView = newDeviceAdminView(parent);
|
||||||
convertView = newDeviceAdminView(parent);
|
|
||||||
}
|
|
||||||
bindView(convertView, (DeviceAdminInfo) o);
|
|
||||||
} else {
|
|
||||||
if (convertView == null) {
|
|
||||||
convertView = Utils.inflateCategoryHeader(mInflater, parent);
|
|
||||||
}
|
|
||||||
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
|
|
||||||
title.setText((String)o);
|
|
||||||
}
|
}
|
||||||
|
bindView(convertView, (DeviceAdminInfo) o);
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private View newDeviceAdminView(ViewGroup parent) {
|
private View newDeviceAdminView(ViewGroup parent) {
|
||||||
View v = mInflater.inflate(R.layout.device_admin_item, parent, false);
|
View v = mInflater.inflate(R.layout.device_admin_item, parent, false);
|
||||||
ViewHolder h = new ViewHolder();
|
ViewHolder h = new ViewHolder();
|
||||||
h.icon = (ImageView)v.findViewById(R.id.icon);
|
h.icon = (ImageView) v.findViewById(R.id.icon);
|
||||||
h.name = (TextView)v.findViewById(R.id.name);
|
h.name = (TextView) v.findViewById(R.id.name);
|
||||||
h.checkbox = (CheckBox)v.findViewById(R.id.checkbox);
|
h.checkbox = (CheckBox) v.findViewById(R.id.checkbox);
|
||||||
h.description = (TextView)v.findViewById(R.id.description);
|
h.description = (TextView) v.findViewById(R.id.description);
|
||||||
v.setTag(h);
|
v.setTag(h);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -399,10 +349,6 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
enabledForProfile = Collections.emptyList();
|
enabledForProfile = Collections.emptyList();
|
||||||
}
|
}
|
||||||
final int n = enabledForProfile.size();
|
final int n = enabledForProfile.size();
|
||||||
ArrayList<DeviceAdminInfo> deviceAdmins = mAdminsByProfile.get(profileId);
|
|
||||||
if (deviceAdmins == null) {
|
|
||||||
deviceAdmins = new ArrayList<DeviceAdminInfo>(n);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
ResolveInfo resolveInfo = enabledForProfile.get(i);
|
ResolveInfo resolveInfo = enabledForProfile.get(i);
|
||||||
ComponentName riComponentName =
|
ComponentName riComponentName =
|
||||||
@@ -410,16 +356,18 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
resolveInfo.activityInfo.name);
|
resolveInfo.activityInfo.name);
|
||||||
if (alreadyAddedComponents == null
|
if (alreadyAddedComponents == null
|
||||||
|| !alreadyAddedComponents.contains(riComponentName)) {
|
|| !alreadyAddedComponents.contains(riComponentName)) {
|
||||||
DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(resolveInfo);
|
DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(resolveInfo);
|
||||||
// add only visible ones (note: active admins are added regardless of visibility)
|
// add only visible ones (note: active admins are added regardless of visibility)
|
||||||
if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
|
if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
|
||||||
deviceAdmins.add(deviceAdminInfo);
|
DeviceAdminListItem item = new DeviceAdminListItem();
|
||||||
|
item.info = deviceAdminInfo;
|
||||||
|
item.name = deviceAdminInfo.loadLabel(pm).toString();
|
||||||
|
// Active ones already added.
|
||||||
|
item.active = false;
|
||||||
|
mAdmins.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!deviceAdmins.isEmpty()) {
|
|
||||||
mAdminsByProfile.put(profileId, deviceAdmins);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,7 +381,6 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
if (activeAdmins != null) {
|
if (activeAdmins != null) {
|
||||||
final PackageManager packageManager = getActivity().getPackageManager();
|
final PackageManager packageManager = getActivity().getPackageManager();
|
||||||
final int n = activeAdmins.size();
|
final int n = activeAdmins.size();
|
||||||
ArrayList<DeviceAdminInfo> deviceAdmins = new ArrayList<DeviceAdminInfo>(n);
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
ComponentName activeAdmin = activeAdmins.get(i);
|
ComponentName activeAdmin = activeAdmins.get(i);
|
||||||
List<ResolveInfo> resolved = packageManager.queryBroadcastReceivers(
|
List<ResolveInfo> resolved = packageManager.queryBroadcastReceivers(
|
||||||
@@ -444,14 +391,15 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
for (int j = 0; j < resolvedMax; ++j) {
|
for (int j = 0; j < resolvedMax; ++j) {
|
||||||
DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(resolved.get(j));
|
DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(resolved.get(j));
|
||||||
if (deviceAdminInfo != null) {
|
if (deviceAdminInfo != null) {
|
||||||
deviceAdmins.add(deviceAdminInfo);
|
DeviceAdminListItem item = new DeviceAdminListItem();
|
||||||
|
item.info = deviceAdminInfo;
|
||||||
|
item.name = deviceAdminInfo.loadLabel(packageManager).toString();
|
||||||
|
item.active = true;
|
||||||
|
mAdmins.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!deviceAdmins.isEmpty()) {
|
|
||||||
mAdminsByProfile.put(profileId, deviceAdmins);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,10 +53,7 @@ public class RestrictedPreferenceHelper {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mPreference = preference;
|
mPreference = preference;
|
||||||
|
|
||||||
mRestrictedPadlock = mContext.getDrawable(R.drawable.ic_settings_lock_outline);
|
mRestrictedPadlock = getRestrictedPadlock(mContext);
|
||||||
final int iconSize = mContext.getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.restricted_lock_icon_size);
|
|
||||||
mRestrictedPadlock.setBounds(0, 0, iconSize, iconSize);
|
|
||||||
mRestrictedPadlockPadding = mContext.getResources().getDimensionPixelSize(
|
mRestrictedPadlockPadding = mContext.getResources().getDimensionPixelSize(
|
||||||
R.dimen.restricted_lock_icon_padding);
|
R.dimen.restricted_lock_icon_padding);
|
||||||
|
|
||||||
@@ -192,4 +189,15 @@ public class RestrictedPreferenceHelper {
|
|||||||
public boolean isDisabledByAdmin() {
|
public boolean isDisabledByAdmin() {
|
||||||
return mDisabledByAdmin;
|
return mDisabledByAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return drawables for displaying with settings that are locked by a device admin.
|
||||||
|
*/
|
||||||
|
public static Drawable getRestrictedPadlock(Context context) {
|
||||||
|
Drawable restrictedPadlock = context.getDrawable(R.drawable.ic_settings_lock_outline);
|
||||||
|
final int iconSize = context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.restricted_lock_icon_size);
|
||||||
|
restrictedPadlock.setBounds(0, 0, iconSize, iconSize);
|
||||||
|
return restrictedPadlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,24 +17,57 @@
|
|||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManagerNative;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.AppGlobals;
|
||||||
|
import android.app.IActivityManager;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class ShowAdminSupportDetailsDialog extends Activity
|
public class ShowAdminSupportDetailsDialog extends Activity
|
||||||
implements DialogInterface.OnDismissListener {
|
implements DialogInterface.OnDismissListener {
|
||||||
|
|
||||||
|
private final String TAG = "AdminSupportDialog";
|
||||||
|
|
||||||
|
private DevicePolicyManager mDpm;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
mDpm = getSystemService(DevicePolicyManager.class);
|
||||||
|
ComponentName admin = null;
|
||||||
|
int userId = UserHandle.myUserId();
|
||||||
|
Intent intent = getIntent();
|
||||||
|
if (intent != null) {
|
||||||
|
IActivityManager am = ActivityManagerNative.getDefault();
|
||||||
|
try {
|
||||||
|
int uid = am.getLaunchedFromUid(getActivityToken());
|
||||||
|
// Only allow system to specify admin and user.
|
||||||
|
if (UserHandle.isSameApp(uid, android.os.Process.myUid())) {
|
||||||
|
admin = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
||||||
|
userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Could not talk to activity manager.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
View rootView = LayoutInflater.from(this).inflate(
|
View rootView = LayoutInflater.from(this).inflate(
|
||||||
R.layout.admin_support_details_dialog, null);
|
R.layout.admin_support_details_dialog, null);
|
||||||
setAdminSupportDetails(rootView);
|
setAdminSupportDetails(rootView, admin, userId);
|
||||||
|
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setView(rootView)
|
.setView(rootView)
|
||||||
@@ -43,24 +76,47 @@ public class ShowAdminSupportDetailsDialog extends Activity
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAdminSupportDetails(View root) {
|
private void setAdminSupportDetails(View root, final ComponentName admin, final int userId) {
|
||||||
CharSequence adminDisabledMsg = getString(R.string.disabled_by_admin_msg,
|
if (admin != null) {
|
||||||
getString(R.string.default_organisation_name));
|
CharSequence supportMessage = mDpm.getShortSupportMessageForUser(admin, userId);
|
||||||
TextView textView = (TextView) root.findViewById(R.id.disabled_by_admin_msg);
|
if (supportMessage != null) {
|
||||||
textView.setText(adminDisabledMsg);
|
TextView textView = (TextView) root.findViewById(R.id.admin_support_msg);
|
||||||
|
textView.setText(supportMessage);
|
||||||
|
}
|
||||||
|
|
||||||
CharSequence adminSupportDetails = getString(R.string.default_admin_support_msg);
|
ActivityInfo ai = null;
|
||||||
textView = (TextView) root.findViewById(R.id.admin_support_msg);
|
try {
|
||||||
textView.setText(adminSupportDetails);
|
ai = AppGlobals.getPackageManager().getReceiverInfo(admin, 0 /* flags */, userId);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Missing reciever info" , e);
|
||||||
|
}
|
||||||
|
if (ai != null) {
|
||||||
|
Drawable icon = ai.loadIcon(getPackageManager());
|
||||||
|
Drawable badgedIcon = getPackageManager().getUserBadgedIcon(
|
||||||
|
icon, new UserHandle(userId));
|
||||||
|
((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(
|
||||||
|
badgedIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
root.findViewById(R.id.admins_policies_list).setOnClickListener(
|
root.findViewById(R.id.admins_policies_list).setOnClickListener(
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClass(ShowAdminSupportDetailsDialog.this,
|
if (admin != null) {
|
||||||
Settings.DeviceAdminSettingsActivity.class);
|
intent.setClass(ShowAdminSupportDetailsDialog.this,
|
||||||
startActivity(intent);
|
DeviceAdminAdd.class);
|
||||||
|
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin);
|
||||||
|
// DeviceAdminAdd class may need to run as managed profile.
|
||||||
|
startActivityAsUser(intent, new UserHandle(userId));
|
||||||
|
} else {
|
||||||
|
intent.setClass(ShowAdminSupportDetailsDialog.this,
|
||||||
|
Settings.DeviceAdminSettingsActivity.class);
|
||||||
|
// Activity merges both managed profile and parent users
|
||||||
|
// admins so show as same user as this activity.
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -70,4 +126,4 @@ public class ShowAdminSupportDetailsDialog extends Activity
|
|||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,13 +55,7 @@ public final class UserDialogs {
|
|||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
.setPositiveButton(R.string.user_delete_button, onConfirmListener)
|
.setPositiveButton(R.string.user_delete_button, onConfirmListener)
|
||||||
.setNegativeButton(android.R.string.cancel, null);
|
.setNegativeButton(android.R.string.cancel, null);
|
||||||
if (UserHandle.myUserId() == removingUserId) {
|
if (userInfo.isManagedProfile()) {
|
||||||
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);
|
builder.setTitle(R.string.work_profile_confirm_remove_title);
|
||||||
View view = createRemoveManagedUserDialogView(context, removingUserId);
|
View view = createRemoveManagedUserDialogView(context, removingUserId);
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
@@ -69,6 +63,12 @@ public final class UserDialogs {
|
|||||||
} else {
|
} else {
|
||||||
builder.setMessage(R.string.work_profile_confirm_remove_message);
|
builder.setMessage(R.string.work_profile_confirm_remove_message);
|
||||||
}
|
}
|
||||||
|
} else 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 {
|
} else {
|
||||||
builder.setTitle(R.string.user_confirm_remove_title);
|
builder.setTitle(R.string.user_confirm_remove_title);
|
||||||
builder.setMessage(R.string.user_confirm_remove_message);
|
builder.setMessage(R.string.user_confirm_remove_message);
|
||||||
|
Reference in New Issue
Block a user