Implement SET_PROFILE_OWNER intent

This will be shown when a system priv-app tries to add a profile owner
to a device that's already been through setupwizard.

Refactored the Add Device Admin dialog to also be used for this
purpose with additional warning text.

Also, make sure that profile owners cannot be deactivated.

Bug: 16207721
Change-Id: I25499a22718b2219a5a56b158ca2681243751549
This commit is contained in:
Amith Yamasani
2014-07-28 16:28:36 -07:00
parent 01daaca547
commit b8e0f608cf
5 changed files with 117 additions and 38 deletions

View File

@@ -50,13 +50,14 @@ import java.util.Set;
public class DeviceAdminSettings extends ListFragment {
static final String TAG = "DeviceAdminSettings";
static final int DIALOG_WARNING = 1;
DevicePolicyManager mDPM;
final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
String mDeviceOwnerPkg;
ComponentName mProfileOwnerComponent;
@Override
public void onCreate(Bundle icicle) {
@@ -84,6 +85,7 @@ public class DeviceAdminSettings extends ListFragment {
if (mDeviceOwnerPkg != null && !mDPM.isDeviceOwner(mDeviceOwnerPkg)) {
mDeviceOwnerPkg = null;
}
mProfileOwnerComponent = mDPM.getProfileOwner();
updateList();
}
@@ -139,7 +141,7 @@ public class DeviceAdminSettings extends ListFragment {
Log.w(TAG, "Skipping " + ri.activityInfo, e);
}
}
getListView().setAdapter(new PolicyListAdapter());
}
@@ -158,10 +160,10 @@ public class DeviceAdminSettings extends ListFragment {
CheckBox checkbox;
TextView description;
}
class PolicyListAdapter extends BaseAdapter {
final LayoutInflater mInflater;
PolicyListAdapter() {
mInflater = (LayoutInflater)
getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -170,7 +172,7 @@ public class DeviceAdminSettings extends ListFragment {
public boolean hasStableIds() {
return true;
}
public int getCount() {
return mAvailableAdmins.size();
}
@@ -189,8 +191,11 @@ public class DeviceAdminSettings extends ListFragment {
public boolean isEnabled(int position) {
DeviceAdminInfo info = mAvailableAdmins.get(position);
if (mActiveAdmins.contains(info.getComponent())
&& info.getPackageName().equals(mDeviceOwnerPkg)) {
String packageName = info.getPackageName();
ComponentName component = info.getComponent();
if (mActiveAdmins.contains(component)
&& (packageName.equals(mDeviceOwnerPkg)
|| component.equals(mProfileOwnerComponent))) {
return false;
} else {
return true;
@@ -207,7 +212,7 @@ public class DeviceAdminSettings extends ListFragment {
bindView(v, position);
return v;
}
public View newView(ViewGroup parent) {
View v = mInflater.inflate(R.layout.device_admin_item, parent, false);
ViewHolder h = new ViewHolder();
@@ -218,7 +223,7 @@ public class DeviceAdminSettings extends ListFragment {
v.setTag(h);
return v;
}
public void bindView(View view, int position) {
final Activity activity = getActivity();
ViewHolder vh = (ViewHolder) view.getTag();