diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2cb7772331a..5b7fdd1d16c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -374,6 +374,19 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/device_admin_item.xml b/res/layout/device_admin_item.xml
new file mode 100644
index 00000000000..d17ff246ffa
--- /dev/null
+++ b/res/layout/device_admin_item.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/device_admin_settings.xml b/res/layout/device_admin_settings.xml
new file mode 100644
index 00000000000..221e45fef1e
--- /dev/null
+++ b/res/layout/device_admin_settings.xml
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b86950b982d..5a0b589c837 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -528,6 +528,12 @@
PIN must contain only digits 0-9
Password contains an illegal character
+
+ Device administration
+
+ Select device administrators
+
+ Add or remove device administrators
@@ -2304,6 +2310,16 @@ found in the list of installed applications.
Are you sure you want to stop backing up your settings and erase all copies on Google servers?
+
+
+ Device administration settings
+
+ Active device administrator
+
+ Remove
+
+ Select device administrator
+
Untitled
diff --git a/src/com/android/settings/DeviceAdminSettings.java b/src/com/android/settings/DeviceAdminSettings.java
new file mode 100644
index 00000000000..e3d733ef30e
--- /dev/null
+++ b/src/com/android/settings/DeviceAdminSettings.java
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.android.settings;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.app.Activity;
+import android.app.DeviceAdmin;
+import android.app.DeviceAdminInfo;
+import android.app.DevicePolicyManager;
+import android.app.ListActivity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DeviceAdminSettings extends ListActivity {
+ static final String TAG = "DeviceAdminSettings";
+
+ DevicePolicyManager mDPM;
+ DeviceAdminInfo mCurrentAdmin;
+
+ View mActiveLayout;
+ ImageView mActiveIcon;
+ TextView mActiveName;
+ TextView mActiveDescription;
+
+ View mSelectLayout;
+ ArrayList mAvailablePolicies
+ = new ArrayList();
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
+ mCurrentAdmin = mDPM.getActiveAdminInfo();
+
+ 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.removeActiveAdmin(mCurrentAdmin.getComponent());
+ finish();
+ }
+ }
+ });
+
+ mSelectLayout = findViewById(R.id.select_layout);
+ getListView().setDivider(null);
+
+ updateLayout();
+
+ 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();
+ }
+ }
+
+ void updateLayout() {
+ if (mCurrentAdmin != null) {
+ mActiveLayout.setVisibility(View.VISIBLE);
+ mSelectLayout.setVisibility(View.GONE);
+ mActiveIcon.setImageDrawable(mCurrentAdmin.loadIcon(getPackageManager()));
+ mActiveName.setText(mCurrentAdmin.loadLabel(getPackageManager()));
+ } else {
+ mActiveLayout.setVisibility(View.GONE);
+ mSelectLayout.setVisibility(View.VISIBLE);
+ mAvailablePolicies.clear();
+ List avail = getPackageManager().queryBroadcastReceivers(
+ new Intent(DeviceAdmin.ACTION_DEVICE_ADMIN_ENABLED),
+ PackageManager.GET_META_DATA);
+ for (int i=0; i