merge in jb-mr2-release history after reset to jb-mr2-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1466ca6..dbdec2d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4351,7 +4351,7 @@
     <!-- Summary for add user entry in the choice dialog [CHAR LIMIT=none] -->
     <string name="user_add_user_item_summary">Users have their own apps and content</string>
     <!-- Summary for add restricted profile entry in the choice dialog [CHAR LIMIT=none] -->
-    <string name="user_add_profile_item_summary">Restricted profiles can only access the apps and content from your accounts</string>
+    <string name="user_add_profile_item_summary">You can restrict access to apps and content from your account</string>
     <!-- Button text for adding a regular user [CHAR LIMIT=25] -->
     <string name="user_add_user_item_title">User</string>
     <!-- Button text for adding a restricted profile [CHAR LIMIT=25] -->
@@ -4474,7 +4474,7 @@
     <string name="cell_broadcast_settings_summary">Select the types of emergency alerts to display.</string>
 
     <!-- User app limits screen title [CHAR LIMIT=35] -->
-    <string name="user_restrictions_title">Allow apps and content</string>
+    <string name="user_restrictions_title">Application and content restrictions</string>
     <!-- User limits screen, user name rename text [CHAR LIMIT=15] -->
     <string name="user_rename">RENAME</string>
     <!-- Preference label for custom restrictions [CHAR LIMIT=35] -->
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index b2145b0..27e7a54 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -50,6 +50,8 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
 
 public class DeviceAdminAdd extends Activity {
     static final String TAG = "DeviceAdminAdd";
@@ -104,7 +106,7 @@
             finish();
             return;
         }
-        
+
         ActivityInfo ai;
         try {
             ai = getPackageManager().getReceiverInfo(cn, PackageManager.GET_META_DATA);
@@ -113,7 +115,37 @@
             finish();
             return;
         }
-        
+
+        // Make sure the given component name is actually a valid device admin.
+        List<ResolveInfo> avail = getPackageManager().queryBroadcastReceivers(
+                new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
+                PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
+        int count = avail == null ? 0 : avail.size();
+        boolean found = false;
+        for (int i=0; i<count; i++) {
+            ResolveInfo ri = avail.get(i);
+            if (ai.packageName.equals(ri.activityInfo.packageName)
+                    && ai.name.equals(ri.activityInfo.name)) {
+                try {
+                    // We didn't retrieve the meta data for all possible matches, so
+                    // need to use the activity info of this specific one that was retrieved.
+                    ri.activityInfo = ai;
+                    DeviceAdminInfo dpi = new DeviceAdminInfo(this, ri);
+                    found = true;
+                } catch (XmlPullParserException e) {
+                    Log.w(TAG, "Bad " + ri.activityInfo, e);
+                } catch (IOException e) {
+                    Log.w(TAG, "Bad " + ri.activityInfo, e);
+                }
+                break;
+            }
+        }
+        if (!found) {
+            Log.w(TAG, "Request to add invalid device admin: " + cn);
+            finish();
+            return;
+        }
+
         ResolveInfo ri = new ResolveInfo();
         ri.activityInfo = ai;
         try {
diff --git a/src/com/android/settings/DeviceAdminSettings.java b/src/com/android/settings/DeviceAdminSettings.java
index 9cfb44d..fa1c7f4 100644
--- a/src/com/android/settings/DeviceAdminSettings.java
+++ b/src/com/android/settings/DeviceAdminSettings.java
@@ -43,8 +43,10 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 public class DeviceAdminSettings extends ListFragment {
     static final String TAG = "DeviceAdminSettings";
@@ -91,8 +93,33 @@
         List<ResolveInfo> avail = getActivity().getPackageManager().queryBroadcastReceivers(
                 new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
                 PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
-        int count = avail == null ? 0 : avail.size();
-        for (int i=0; i<count; i++) {
+        if (avail == null) {
+            avail = Collections.emptyList();
+        }
+
+        // Some admins listed in mActiveAdmins may not have been found by the above query.
+        // We thus add them separately.
+        Set<ComponentName> activeAdminsNotInAvail = new HashSet<ComponentName>(mActiveAdmins);
+        for (ResolveInfo ri : avail) {
+            ComponentName riComponentName =
+                    new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name);
+            activeAdminsNotInAvail.remove(riComponentName);
+        }
+        if (!activeAdminsNotInAvail.isEmpty()) {
+            avail = new ArrayList<ResolveInfo>(avail);
+            PackageManager packageManager = getActivity().getPackageManager();
+            for (ComponentName unlistedActiveAdmin : activeAdminsNotInAvail) {
+                List<ResolveInfo> resolved = packageManager.queryBroadcastReceivers(
+                        new Intent().setComponent(unlistedActiveAdmin),
+                        PackageManager.GET_META_DATA
+                                | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
+                if (resolved != null) {
+                    avail.addAll(resolved);
+                }
+            }
+        }
+
+        for (int i = 0, count = avail.size(); i < count; i++) {
             ResolveInfo ri = avail.get(i);
             try {
                 DeviceAdminInfo dpi = new DeviceAdminInfo(getActivity(), ri);
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 8961500..a19158f 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -376,13 +376,9 @@
             Bundle extras = new Bundle();
             extras.putInt(AppRestrictionsFragment.EXTRA_USER_ID, userId);
             extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser);
-            String title = getResources().getString(R.string.user_new_user_name);
-            if (userId > UserHandle.USER_OWNER) {
-                title = mUserManager.getUserInfo(userId).name;
-            }
             ((PreferenceActivity) getActivity()).startPreferencePanel(
                     AppRestrictionsFragment.class.getName(),
-                    extras, 0, title,
+                    extras, R.string.user_restrictions_title, null,
                     null, 0);
         } else if (info.id == UserHandle.myUserId()) {
             // Jump to owner info panel