merge in jb-mr2-zeroday-release history after reset to jb-mr2-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c41c40c..67aa7ee 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1042,8 +1042,7 @@
                 android:theme="@android:style/Theme.Holo.DialogWhenLarge"/>
 
         <activity android:name="ApnEditor"
-                android:label="@string/apn_edit"
-                android:theme="@android:style/Theme.Holo.DialogWhenLarge">
+                android:label="@string/apn_edit">
             <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
                 <action android:name="android.intent.action.EDIT" />
diff --git a/res/values-sw/strings.xml b/res/values-sw/strings.xml
index ea1362f..3741134 100644
--- a/res/values-sw/strings.xml
+++ b/res/values-sw/strings.xml
@@ -1052,7 +1052,7 @@
     <string name="install_all_warning" product="default" msgid="8113734576826384682">"Simu yako na data ya kibinafsi inaweza kushambuliwa na programu kutoka kwa vyanzo visivyojulikana. Unakubali kuwa unawajibika mwenyewe kwa uharibifu wowote kwa simu yako au kupoteza data ambayo inaweza kusababishwa kutokana na kutumiwa na programu hizi."</string>
     <string name="verify_applications" msgid="2959359554974828518">"Thibitisha programu"</string>
     <string name="verify_applications_summary" msgid="6737505521913263792">"Nyima ruhusa au onya kabla ya usakinishaji wa programu ambayo inaweza kusababisha madhara"</string>
-    <string name="advanced_settings" msgid="1777249286757067969">"Mipangilio mahiri"</string>
+    <string name="advanced_settings" msgid="1777249286757067969">"Mipangilio ya kina"</string>
     <string name="advanced_settings_summary" msgid="4016682978071086747">"Wezesha chaguo zaidi ya mipangilio."</string>
     <string name="application_info_label" msgid="5736524913065714880">"Maelezo ya programu"</string>
     <string name="storage_label" msgid="8700867073480107253">"Hifadhi"</string>
@@ -1429,7 +1429,7 @@
     <string name="process_mediaserver_label" msgid="6500382062945689285">"Seva ya media"</string>
     <string name="voice_input_output_settings" msgid="1336135218350444783">"Kiingizaji cha sauti &amp; kutoa nje"</string>
     <string name="voice_input_output_settings_title" msgid="2442850635048676991">"Kiingizaji cha sauti &amp; mipangilio ya kutoa nje"</string>
-    <string name="voice_search_settings_title" msgid="2775469246913196536">"Tafuta sauti"</string>
+    <string name="voice_search_settings_title" msgid="2775469246913196536">"Tafuta kwa kutamka"</string>
     <string name="keyboard_settings_title" msgid="5080115226780201234">"Baobonye la Android"</string>
     <string name="voice_category" msgid="1430370497125803904">"Usemi"</string>
     <string name="recognizer_title" msgid="3231385184559054457">"Kitambulizi cha sauti"</string>
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index 27e7a54..6234038 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -116,34 +116,38 @@
             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);
+        // When activating, make sure the given component name is actually a valid device admin.
+        // No need to check this when deactivating, because it is safe to deactivate an active
+        // invalid device admin.
+        if (!mDPM.isAdminActive(cn)) {
+            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;
                 }
-                break;
             }
-        }
-        if (!found) {
-            Log.w(TAG, "Request to add invalid device admin: " + cn);
-            finish();
-            return;
+            if (!found) {
+                Log.w(TAG, "Request to add invalid device admin: " + cn);
+                finish();
+                return;
+            }
         }
 
         ResolveInfo ri = new ResolveInfo();
diff --git a/src/com/android/settings/applications/RunningState.java b/src/com/android/settings/applications/RunningState.java
index 5797dfa..d373fdd 100644
--- a/src/com/android/settings/applications/RunningState.java
+++ b/src/com/android/settings/applications/RunningState.java
@@ -462,6 +462,12 @@
                     si.mServiceInfo = ActivityThread.getPackageManager().getServiceInfo(
                             service.service, PackageManager.GET_UNINSTALLED_PACKAGES,
                             UserHandle.getUserId(service.uid));
+
+                    if (si.mServiceInfo == null) {
+                        Log.d("RunningService", "getServiceInfo returned null for: "
+                                + service.service);
+                        return false;
+                    }
                 } catch (RemoteException e) {
                 }
                 si.mDisplayLabel = makeLabel(pm,
diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java
index 3d68024..95d3496 100644
--- a/src/com/android/settings/users/AppRestrictionsFragment.java
+++ b/src/com/android/settings/users/AppRestrictionsFragment.java
@@ -513,6 +513,17 @@
                 info.activityName = info.appName;
                 info.icon = app.loadIcon(pm);
                 mVisibleApps.add(info);
+            } else {
+                try {
+                    PackageInfo pi = pm.getPackageInfo(app.packageName, 0);
+                    // If it's a system app that requires an account and doesn't see restricted
+                    // accounts, mark for removal. It might get shown in the UI if it has an icon
+                    // but will still be marked as false and immutable.
+                    if (pi.requiredAccountType != null && pi.restrictedAccountType == null) {
+                        mSelectedPackages.put(app.packageName, false);
+                    }
+                } catch (NameNotFoundException re) {
+                }
             }
         }