Device Admin Settings changes for Device Owner
Disable the list entry for an active device owner, as it can't be deactivated. Change-Id: I833561f91ae60dff8226f9118c9e3b012e5e194f
This commit is contained in:
@@ -54,6 +54,7 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
|
final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
|
||||||
final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
|
final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
|
||||||
|
String mDeviceOwnerPkg;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -70,6 +71,10 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
mDeviceOwnerPkg = mDPM.getDeviceOwner();
|
||||||
|
if (mDeviceOwnerPkg != null && !mDPM.isDeviceOwner(mDeviceOwnerPkg)) {
|
||||||
|
mDeviceOwnerPkg = null;
|
||||||
|
}
|
||||||
updateList();
|
updateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +90,7 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
mAvailableAdmins.clear();
|
mAvailableAdmins.clear();
|
||||||
List<ResolveInfo> avail = getActivity().getPackageManager().queryBroadcastReceivers(
|
List<ResolveInfo> avail = getActivity().getPackageManager().queryBroadcastReceivers(
|
||||||
new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
|
new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
|
||||||
PackageManager.GET_META_DATA);
|
PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
|
||||||
int count = avail == null ? 0 : avail.size();
|
int count = avail == null ? 0 : avail.size();
|
||||||
for (int i=0; i<count; i++) {
|
for (int i=0; i<count; i++) {
|
||||||
ResolveInfo ri = avail.get(i);
|
ResolveInfo ri = avail.get(i);
|
||||||
@@ -149,7 +154,13 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled(int position) {
|
public boolean isEnabled(int position) {
|
||||||
return true;
|
DeviceAdminInfo info = mAvailableAdmins.get(position);
|
||||||
|
if (mActiveAdmins.contains(info.getComponent())
|
||||||
|
&& info.getPackageName().equals(mDeviceOwnerPkg)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
@@ -181,10 +192,16 @@ public class DeviceAdminSettings extends ListFragment {
|
|||||||
vh.icon.setImageDrawable(item.loadIcon(activity.getPackageManager()));
|
vh.icon.setImageDrawable(item.loadIcon(activity.getPackageManager()));
|
||||||
vh.name.setText(item.loadLabel(activity.getPackageManager()));
|
vh.name.setText(item.loadLabel(activity.getPackageManager()));
|
||||||
vh.checkbox.setChecked(mActiveAdmins.contains(item.getComponent()));
|
vh.checkbox.setChecked(mActiveAdmins.contains(item.getComponent()));
|
||||||
|
final boolean activeOwner = vh.checkbox.isChecked()
|
||||||
|
&& item.getPackageName().equals(mDeviceOwnerPkg);
|
||||||
try {
|
try {
|
||||||
vh.description.setText(item.loadDescription(activity.getPackageManager()));
|
vh.description.setText(item.loadDescription(activity.getPackageManager()));
|
||||||
} catch (Resources.NotFoundException e) {
|
} catch (Resources.NotFoundException e) {
|
||||||
}
|
}
|
||||||
|
vh.checkbox.setEnabled(!activeOwner);
|
||||||
|
vh.name.setEnabled(!activeOwner);
|
||||||
|
vh.description.setEnabled(!activeOwner);
|
||||||
|
vh.icon.setEnabled(!activeOwner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ public class UserRestrictionsActivity extends Activity implements OnClickListene
|
|||||||
if (userId == -1) {
|
if (userId == -1) {
|
||||||
mNewUser = true;
|
mNewUser = true;
|
||||||
mUserInfo = um.createUser(name, UserInfo.FLAG_RESTRICTED);
|
mUserInfo = um.createUser(name, UserInfo.FLAG_RESTRICTED);
|
||||||
um.setUserRestriction(UserManager.ALLOW_MODIFY_ACCOUNTS, false,
|
um.setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true,
|
||||||
new UserHandle(mUserInfo.id));
|
new UserHandle(mUserInfo.id));
|
||||||
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
|
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
|
||||||
|
Reference in New Issue
Block a user