Update settings UI to support multiple device admins.
diff --git a/res/layout/device_admin_add.xml b/res/layout/device_admin_add.xml
index 4845fca..3ff190b 100644
--- a/res/layout/device_admin_add.xml
+++ b/res/layout/device_admin_add.xml
@@ -35,10 +35,9 @@
                 android:layout_height="wrap_content"
                 android:orientation="horizontal"
                 android:background="@*android:drawable/title_bar_medium">
-                <TextView
+                <TextView android:id="@+id/title"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
-                    android:text="@string/add_device_admin_msg"
                     android:gravity="center"
                     android:textAppearance="?android:attr/textAppearanceLarge"
                     android:textColor="?android:attr/textColorPrimary"
@@ -49,14 +48,14 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal">
-                <ImageView android:id="@+id/active_icon"
+                <ImageView android:id="@+id/admin_icon"
                     android:layout_width="@android:dimen/app_icon_size"
                     android:layout_height="@android:dimen/app_icon_size"
                     android:layout_marginLeft="5dip"
                     android:layout_marginRight="11dip"
                     android:layout_gravity="center_vertical"
                     android:scaleType="fitCenter"/>
-                <TextView android:id="@+id/active_name"
+                <TextView android:id="@+id/admin_name"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_weight="1"
@@ -67,7 +66,7 @@
                     android:singleLine="true"
                     android:ellipsize="marquee" />
             </LinearLayout>
-            <TextView android:id="@+id/active_warning"
+            <TextView android:id="@+id/admin_warning"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:padding="10dip" />
@@ -77,7 +76,7 @@
                 android:orientation="vertical"
                 android:paddingLeft="16dip"
                 android:paddingRight="12dip" />
-            <TextView android:id="@+id/active_description"
+            <TextView android:id="@+id/admin_description"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
@@ -97,11 +96,10 @@
            android:layout_width="0dip"
            android:layout_height="0dip"
            android:layout_weight="1" />
-        <Button android:id="@+id/add_button"
+        <Button android:id="@+id/action_button"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:text="@string/add_device_admin" />
+            android:layout_weight="1" />
         <View
            android:layout_width="0dip"
            android:layout_height="0dip"
diff --git a/res/layout/device_admin_item.xml b/res/layout/device_admin_item.xml
index d17ff24..49cbc61 100644
--- a/res/layout/device_admin_item.xml
+++ b/res/layout/device_admin_item.xml
@@ -21,27 +21,49 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
-    android:orientation="horizontal"
+    android:orientation="vertical"
     android:paddingRight="6dip"
     android:paddingLeft="6dip"
     android:gravity="fill" >
 
-    <ImageView android:id="@+id/icon"
-        android:layout_width="@android:dimen/app_icon_size"
-        android:layout_height="@android:dimen/app_icon_size"
-        android:layout_marginLeft="5dip"
-        android:layout_marginRight="11dip"
-        android:layout_gravity="center_vertical"
-        android:scaleType="fitCenter"/>
-
-    <TextView android:id="@+id/name"
-        android:layout_width="wrap_content"
+    <LinearLayout
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_weight="1"
-        android:layout_gravity="center_vertical"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textStyle="bold"
+        android:orientation="horizontal">
+    
+        <ImageView android:id="@+id/icon"
+            android:layout_width="@android:dimen/app_icon_size"
+            android:layout_height="@android:dimen/app_icon_size"
+            android:layout_marginLeft="5dip"
+            android:layout_marginRight="11dip"
+            android:layout_gravity="center_vertical"
+            android:scaleType="fitCenter"/>
+    
+        <TextView android:id="@+id/name"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:layout_gravity="center_vertical"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textStyle="bold"
+            android:singleLine="true"
+            android:ellipsize="marquee"
+            android:layout_marginBottom="2dip" />
+            
+        <CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
+            android:id="@+id/checkbox" 
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:focusable="false"
+            android:clickable="false" />
+    </LinearLayout>
+    
+    <TextView android:id="@+id/description"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceSmall"
         android:singleLine="true"
-        android:ellipsize="marquee"
-        android:layout_marginBottom="2dip" />
+        android:ellipsize="end" />
+            
 </LinearLayout>
diff --git a/res/layout/device_admin_settings.xml b/res/layout/device_admin_settings.xml
index 40b20e6..eaf42fe 100644
--- a/res/layout/device_admin_settings.xml
+++ b/res/layout/device_admin_settings.xml
@@ -14,105 +14,41 @@
      limitations under the License.
 -->
 
-<FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:orientation="vertical">
     <LinearLayout
-        android:id="@+id/active_layout"
-	    android:layout_width="match_parent"
-	    android:layout_height="match_parent"
-	    android:orientation="vertical"
-	    android:visibility="gone">
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-		    android:background="@*android:drawable/title_bar_medium">
-            <TextView
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-	            android:text="@string/active_device_admin_msg"
-                android:gravity="center"
-                android:textAppearance="?android:attr/textAppearanceLarge"
-                android:textColor="?android:attr/textColorPrimary"
-                android:shadowColor="?android:attr/colorBackground"
-                android:shadowRadius="2" />
-        </LinearLayout>
-        <LinearLayout
-	        android:layout_width="match_parent"
-	        android:layout_height="wrap_content"
-	        android:orientation="horizontal">
-	        <ImageView android:id="@+id/active_icon"
-	            android:layout_width="@android:dimen/app_icon_size"
-	            android:layout_height="@android:dimen/app_icon_size"
-	            android:layout_marginLeft="5dip"
-	            android:layout_marginRight="11dip"
-	            android:layout_gravity="center_vertical"
-	            android:scaleType="fitCenter"/>
-            <TextView android:id="@+id/active_name"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_weight="1"
-                android:layout_marginBottom="2dip"
-                android:layout_gravity="center_vertical"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textStyle="bold"
-                android:singleLine="true"
-                android:ellipsize="marquee" />
-        </LinearLayout>
-        <TextView android:id="@+id/active_description"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:padding="10dip" />
-	    <LinearLayout style="@android:style/ButtonBar"
-	        android:layout_width="match_parent"
-	        android:layout_height="wrap_content"
-	        android:orientation="horizontal">
-            <View
-               android:layout_width="0dip"
-               android:layout_height="0dip"
-               android:layout_weight="1" />
-            <Button android:id="@+id/remove_button"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_weight="1"
-               android:text="@string/remove_device_admin" />
-            <View
-               android:layout_width="0dip"
-               android:layout_height="0dip"
-               android:layout_weight="1" />
-	    </LinearLayout>
-    </LinearLayout>
-    
-    <LinearLayout
-        android:id="@+id/select_layout"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:orientation="vertical"
-        android:visibility="gone">
-        <LinearLayout
-	        android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-	        android:orientation="horizontal"
-            android:background="@*android:drawable/title_bar_medium">
-	        <TextView
-	            android:layout_width="match_parent"
-			    android:layout_height="match_parent"
-	            android:text="@string/select_device_admin_msg"
-	            android:gravity="center"
-	            android:textAppearance="?android:attr/textAppearanceLarge"
-		        android:textColor="?android:attr/textColorPrimary"
-		        android:shadowColor="?android:attr/colorBackground"
-		        android:shadowRadius="2" />
-        </LinearLayout>
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:background="@*android:drawable/title_bar_medium">
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:text="@string/select_device_admin_msg"
+            android:gravity="center"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:textColor="?android:attr/textColorPrimary"
+            android:shadowColor="?android:attr/colorBackground"
+            android:shadowRadius="2" />
+    </LinearLayout>
+    <FrameLayout
+            android:layout_width="match_parent"
+            android:layout_height="0px"
+            android:layout_weight="1"
+            android:paddingTop="10dip"
+            android:paddingBottom="10dip">
         <ListView android:id="@android:id/list"
                 android:layout_width="match_parent" 
                 android:layout_height="match_parent"
-                android:paddingTop="10dip"
-                android:paddingBottom="10dip"
                 android:drawSelectorOnTop="false"
                 android:fastScrollEnabled="true" />
-    </LinearLayout>
-</FrameLayout>
+        <TextView android:id="@android:id/empty"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center"
+                android:text="@string/no_device_admins"
+                android:textAppearance="?android:attr/textAppearanceLarge" />
+    </FrameLayout>
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 98a24e8..ede0eaa 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2347,22 +2347,28 @@
     <!-- Device admin settings activity title -->
     <string name="device_admin_settings_title">Device administration settings</string>
     <!-- Label for screen showing the active device policy -->
-    <string name="active_device_admin_msg">Active device administrator</string>
+    <string name="active_device_admin_msg">Device administrator</string>
     <!-- Label for button to remove the active device admin -->
     <string name="remove_device_admin">Deactivate</string>
     <!-- Label for screen showing to select device policy -->
-    <string name="select_device_admin_msg">Select device administrator</string>
+    <string name="select_device_admin_msg">Device administrators</string>
+    <!-- Message when there are no available device admins to display -->
+    <string name="no_device_admins">No available device administrators</string>
 
     <!-- Label for screen showing to add device policy -->
-    <string name="add_device_admin_msg">Activate device administrator</string>
+    <string name="add_device_admin_msg">Activate device administrator?</string>
     <!-- Label for button to set the active device admin -->
     <string name="add_device_admin">Activate</string>
     <!-- Device admin add activity title -->
-    <string name="device_admin_add_title">Activate device administrator</string>
+    <string name="device_admin_add_title">Device administrator</string>
     <!-- Device admin warning message about policies an admin can use -->
     <string name="device_admin_warning">Activating this administrator will allow
         the application <xliff:g id="app_name">%1$s</xliff:g> to perform the
         following operations:</string>
+    <!-- Device admin warning message about policies an admin can use -->
+    <string name="device_admin_status">This administrator is active and allows
+        the application <xliff:g id="app_name">%1$s</xliff:g> to perform the
+        following operations:</string>
     
     <!-- Name to assign to a Network Access Point that was saved without a name -->
     <string name="untitled_apn">Untitled</string>
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index b72a91d..db4263a 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -19,19 +19,26 @@
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.DeviceAdmin;
 import android.app.DeviceAdminInfo;
 import android.app.DevicePolicyManager;
+import android.app.Dialog;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.RemoteCallback;
 import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AppSecurityPermissions;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -41,27 +48,36 @@
 public class DeviceAdminAdd extends Activity {
     static final String TAG = "DeviceAdminAdd";
     
+    static final int DIALOG_WARNING = 1;
+    
+    Handler mHandler;
+    
     DevicePolicyManager mDPM;
     DeviceAdminInfo mDeviceAdmin;
     CharSequence mAddMsgText;
     
-    ImageView mActiveIcon;
-    TextView mActiveName;
-    TextView mActiveDescription;
+    TextView mTitle;
+    ImageView mAdminIcon;
+    TextView mAdminName;
+    TextView mAdminDescription;
     TextView mAddMsg;
-    TextView mActiveWarning;
+    TextView mAdminWarning;
     ViewGroup mAdminPolicies;
+    Button mActionButton;
     
     View mSelectLayout;
     ArrayList<DeviceAdminInfo> mAvailablePolicies
             = new ArrayList<DeviceAdminInfo>();
     
+    boolean mAdding;
+    
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
+        mHandler = new Handler(getMainLooper());
+        
         mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
-        DeviceAdminInfo activeAdmin = mDPM.getActiveAdminInfo();
 
         ComponentName cn = (ComponentName)getIntent().getParcelableExtra(
                 DevicePolicyManager.EXTRA_DEVICE_ADMIN);
@@ -70,15 +86,14 @@
             finish();
             return;
         }
-        if (cn.equals(activeAdmin)) {
-            setResult(Activity.RESULT_OK);
-            finish();
-            return;
-        }
-        if (activeAdmin != null) {
-            Log.w(TAG, "Admin already set, can't do " + getIntent().getAction());
-            finish();
-            return;
+        if (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN.equals(getIntent().getAction())) {
+            // If this was an add request, then just exit immediately if the
+            // given component is already added.
+            if (mDPM.isAdminActive(cn)) {
+                setResult(Activity.RESULT_OK);
+                finish();
+                return;
+            }
         }
         
         ActivityInfo ai;
@@ -110,17 +125,38 @@
         
         setContentView(R.layout.device_admin_add);
         
-        mActiveIcon = (ImageView)findViewById(R.id.active_icon);
-        mActiveName = (TextView)findViewById(R.id.active_name);
-        mActiveDescription = (TextView)findViewById(R.id.active_description);
+        mTitle = (TextView)findViewById(R.id.title);
+        mAdminIcon = (ImageView)findViewById(R.id.admin_icon);
+        mAdminName = (TextView)findViewById(R.id.admin_name);
+        mAdminDescription = (TextView)findViewById(R.id.admin_description);
         mAddMsg = (TextView)findViewById(R.id.add_msg);
-        mActiveWarning = (TextView)findViewById(R.id.active_warning);
+        mAdminWarning = (TextView)findViewById(R.id.admin_warning);
         mAdminPolicies = (ViewGroup)findViewById(R.id.admin_policies);
-        findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() {
+        mActionButton = (Button)findViewById(R.id.action_button);
+        mActionButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
-                mDPM.setActiveAdmin(mDeviceAdmin.getComponent());
-                setResult(Activity.RESULT_OK);
-                finish();
+                if (mAdding) {
+                    mDPM.setActiveAdmin(mDeviceAdmin.getComponent());
+                    setResult(Activity.RESULT_OK);
+                    finish();
+                }
+                mDPM.getRemoveWarning(mDeviceAdmin.getComponent(),
+                        new RemoteCallback(mHandler) {
+                    @Override
+                    protected void onResult(Bundle bundle) {
+                        CharSequence msg = bundle != null
+                                ? bundle.getCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING)
+                                : null;
+                        if (msg == null) {
+                            mDPM.removeActiveAdmin(mDeviceAdmin.getComponent());
+                            finish();
+                        } else {
+                            Bundle args = new Bundle();
+                            args.putCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING, msg);
+                            showDialog(DIALOG_WARNING, args);
+                        }
+                    }
+                });
             }
         });
     }
@@ -131,15 +167,39 @@
         updateInterface();
     }
     
+    @Override
+    protected Dialog onCreateDialog(int id, Bundle args) {
+        switch (id) {
+            case DIALOG_WARNING: {
+                CharSequence msg = args.getCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING);
+                AlertDialog.Builder builder = new AlertDialog.Builder(
+                        DeviceAdminAdd.this);
+                builder.setMessage(msg);
+                builder.setPositiveButton(R.string.dlg_ok,
+                        new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int which) {
+                        mDPM.removeActiveAdmin(mDeviceAdmin.getComponent());
+                        finish();
+                    }
+                });
+                builder.setNegativeButton(R.string.dlg_cancel, null);
+                return builder.create();
+            }
+            default:
+                return super.onCreateDialog(id, args);
+                    
+        }
+    }
+    
     void updateInterface() {
-        mActiveIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
-        mActiveName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
+        mAdminIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
+        mAdminName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
         try {
-            mActiveDescription.setText(
+            mAdminDescription.setText(
                     mDeviceAdmin.loadDescription(getPackageManager()));
-            mActiveDescription.setVisibility(View.VISIBLE);
+            mAdminDescription.setVisibility(View.VISIBLE);
         } catch (Resources.NotFoundException e) {
-            mActiveDescription.setVisibility(View.GONE);
+            mAdminDescription.setVisibility(View.GONE);
         }
         if (mAddMsgText != null) {
             mAddMsg.setText(mAddMsgText);
@@ -147,14 +207,25 @@
         } else {
             mAddMsg.setVisibility(View.GONE);
         }
-        mActiveWarning.setText(getString(R.string.device_admin_warning,
-                mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
         ArrayList<DeviceAdminInfo.PolicyInfo> policies = mDeviceAdmin.getUsedPolicies();
         for (int i=0; i<policies.size(); i++) {
             DeviceAdminInfo.PolicyInfo pi = policies.get(i);
             mAdminPolicies.addView(AppSecurityPermissions.getPermissionItemView(
                     this, getText(pi.label), getText(pi.description), true));
         }
+        if (mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
+            mAdminWarning.setText(getString(R.string.device_admin_status,
+                    mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
+            mTitle.setText(getText(R.string.active_device_admin_msg));
+            mActionButton.setText(getText(R.string.remove_device_admin));
+            mAdding = false;
+        } else {
+            mAdminWarning.setText(getString(R.string.device_admin_warning,
+                    mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
+            mTitle.setText(getText(R.string.add_device_admin_msg));
+            mActionButton.setText(getText(R.string.add_device_admin));
+            mAdding = true;
+        }
     }
     
 }
diff --git a/src/com/android/settings/DeviceAdminSettings.java b/src/com/android/settings/DeviceAdminSettings.java
index e6da8e7..cbf446d 100644
--- a/src/com/android/settings/DeviceAdminSettings.java
+++ b/src/com/android/settings/DeviceAdminSettings.java
@@ -40,12 +40,14 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
+import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 
 public class DeviceAdminSettings extends ListActivity {
@@ -54,155 +56,57 @@
     static final int DIALOG_WARNING = 1;
     
     DevicePolicyManager mDPM;
-    DeviceAdminInfo mCurrentAdmin;
-    Handler mHandler;
-    
-    View mActiveLayout;
-    ImageView mActiveIcon;
-    TextView mActiveName;
-    TextView mActiveDescription;
-    
-    View mSelectLayout;
-    ArrayList<DeviceAdminInfo> mAvailablePolicies
-            = new ArrayList<DeviceAdminInfo>();
+    final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
+    final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
     
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
         mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
-        mCurrentAdmin = mDPM.getActiveAdminInfo();
-        mHandler = new Handler(getMainLooper());
         
         setContentView(R.layout.device_admin_settings);
-        
-        mActiveLayout = findViewById(R.id.active_layout);
-        mActiveIcon = (ImageView)findViewById(R.id.active_icon);
-        mActiveName = (TextView)findViewById(R.id.active_name);
-        mActiveDescription = (TextView)findViewById(R.id.active_description);
-        findViewById(R.id.remove_button).setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) {
-                if (mCurrentAdmin != null) {
-                    mDPM.getRemoveWarning(mCurrentAdmin.getComponent(),
-                            new RemoteCallback(mHandler) {
-                        @Override
-                        protected void onResult(Bundle bundle) {
-                            CharSequence msg = bundle != null
-                                    ? bundle.getCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING)
-                                    : null;
-                            if (msg == null) {
-                                mDPM.removeActiveAdmin(mCurrentAdmin.getComponent());
-                                finish();
-                            } else {
-                                Bundle args = new Bundle();
-                                args.putCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING, msg);
-                                showDialog(DIALOG_WARNING, args);
-                            }
-                        }
-                    });
-                }
-            }
-        });
-        
-        mSelectLayout = findViewById(R.id.select_layout);
-
-        if (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN.equals(getIntent().getAction())) {
-            ComponentName cn = (ComponentName)getIntent().getParcelableExtra(
-                    DevicePolicyManager.EXTRA_DEVICE_ADMIN);
-            if (cn == null) {
-                Log.w(TAG, "No component specified in " + getIntent().getAction());
-                finish();
-                return;
-            }
-            if (cn.equals(mCurrentAdmin)) {
-                setResult(Activity.RESULT_OK);
-                finish();
-                return;
-            }
-            if (mCurrentAdmin != null) {
-                Log.w(TAG, "Admin already set, can't do " + getIntent().getAction());
-                finish();
-                return;
-            }
-            
-            try {
-                mDPM.setActiveAdmin(cn);
-                setResult(Activity.RESULT_OK);
-            } catch (RuntimeException e) {
-                Log.w(TAG, "Unable to set admin " + cn, e);
-                setResult(Activity.RESULT_CANCELED);
-            }
-            finish();
-        }
     }
     
     @Override
     protected void onResume() {
         super.onResume();
-        updateLayout();
+        updateList();
     }
 
-    @Override
-    protected Dialog onCreateDialog(int id, Bundle args) {
-        switch (id) {
-            case DIALOG_WARNING: {
-                CharSequence msg = args.getCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING);
-                AlertDialog.Builder builder = new AlertDialog.Builder(
-                        DeviceAdminSettings.this);
-                builder.setMessage(msg);
-                builder.setPositiveButton(R.string.dlg_ok,
-                        new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog, int which) {
-                        mDPM.removeActiveAdmin(mCurrentAdmin.getComponent());
-                        finish();
-                    }
-                });
-                builder.setNegativeButton(R.string.dlg_cancel, null);
-                return builder.create();
+    void updateList() {
+        mActiveAdmins.clear();
+        List<ComponentName> cur = mDPM.getActiveAdmins();
+        if (cur != null) {
+            for (int i=0; i<cur.size(); i++) {
+                mActiveAdmins.add(cur.get(i));
             }
-            default:
-                return super.onCreateDialog(id, args);
-                    
         }
-    }
-
-    void updateLayout() {
-        if (mCurrentAdmin != null) {
-            mActiveLayout.setVisibility(View.VISIBLE);
-            mSelectLayout.setVisibility(View.GONE);
-            mActiveIcon.setImageDrawable(mCurrentAdmin.loadIcon(getPackageManager()));
-            mActiveName.setText(mCurrentAdmin.loadLabel(getPackageManager()));
+        
+        mAvailableAdmins.clear();
+        List<ResolveInfo> avail = getPackageManager().queryBroadcastReceivers(
+                new Intent(DeviceAdmin.ACTION_DEVICE_ADMIN_ENABLED),
+                PackageManager.GET_META_DATA);
+        for (int i=0; i<avail.size(); i++) {
+            ResolveInfo ri = avail.get(i);
             try {
-                mActiveDescription.setText(
-                        mCurrentAdmin.loadDescription(getPackageManager()));
-            } catch (Resources.NotFoundException e) {
+                DeviceAdminInfo dpi = new DeviceAdminInfo(this, ri);
+                mAvailableAdmins.add(dpi);
+            } catch (XmlPullParserException e) {
+                Log.w(TAG, "Skipping " + ri.activityInfo, e);
+            } catch (IOException e) {
+                Log.w(TAG, "Skipping " + ri.activityInfo, e);
             }
-        } else {
-            mActiveLayout.setVisibility(View.GONE);
-            mSelectLayout.setVisibility(View.VISIBLE);
-            mAvailablePolicies.clear();
-            List<ResolveInfo> avail = getPackageManager().queryBroadcastReceivers(
-                    new Intent(DeviceAdmin.ACTION_DEVICE_ADMIN_ENABLED),
-                    PackageManager.GET_META_DATA);
-            for (int i=0; i<avail.size(); i++) {
-                ResolveInfo ri = avail.get(i);
-                try {
-                    DeviceAdminInfo dpi = new DeviceAdminInfo(this, ri);
-                    mAvailablePolicies.add(dpi);
-                } catch (XmlPullParserException e) {
-                    Log.w(TAG, "Skipping " + ri.activityInfo, e);
-                } catch (IOException e) {
-                    Log.w(TAG, "Skipping " + ri.activityInfo, e);
-                }
-            }
-            getListView().setAdapter(new PolicyListAdapter());
         }
+        
+        getListView().setAdapter(new PolicyListAdapter());
     }
     
     @Override
     protected void onListItemClick(ListView l, View v, int position, long id) {
         DeviceAdminInfo dpi = (DeviceAdminInfo)l.getAdapter().getItem(position);
-        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
+        Intent intent = new Intent();
+        intent.setClass(this, DeviceAdminAdd.class);
         intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
         startActivity(intent);
     }
@@ -210,6 +114,8 @@
     static class ViewHolder {
         ImageView icon;
         TextView name;
+        CheckBox checkbox;
+        TextView description;
     }
     
     class PolicyListAdapter extends BaseAdapter {
@@ -224,11 +130,11 @@
         }
         
         public int getCount() {
-            return mAvailablePolicies.size();
+            return mAvailableAdmins.size();
         }
 
         public Object getItem(int position) {
-            return mAvailablePolicies.get(position);
+            return mAvailableAdmins.get(position);
         }
 
         public long getItemId(int position) {
@@ -259,15 +165,22 @@
             ViewHolder h = new ViewHolder();
             h.icon = (ImageView)v.findViewById(R.id.icon);
             h.name = (TextView)v.findViewById(R.id.name);
+            h.checkbox = (CheckBox)v.findViewById(R.id.checkbox);
+            h.description = (TextView)v.findViewById(R.id.description);
             v.setTag(h);
             return v;
         }
         
         public void bindView(View view, int position) {
             ViewHolder vh = (ViewHolder) view.getTag();
-            DeviceAdminInfo item = mAvailablePolicies.get(position);
+            DeviceAdminInfo item = mAvailableAdmins.get(position);
             vh.icon.setImageDrawable(item.loadIcon(getPackageManager()));
             vh.name.setText(item.loadLabel(getPackageManager()));
+            vh.checkbox.setChecked(mActiveAdmins.contains(item.getComponent()));
+            try {
+                vh.description.setText(item.loadDescription(getPackageManager()));
+            } catch (Resources.NotFoundException e) {
+            }
         }
     }
 }