Incorporate home metadata into app details UI

Just as we don't expose disable/uninstall of home applications in this UI,
we now also don't allow disable/uninstall of packages that are proxying
for home apps via the android.app.home.alternate meta-data mechanism.

Also, don't display the 'Home' settings top-level category at all when
there is only a single available home app.

Finally, explicitly note the current user when sending broadcasts,
otherwise API sanity checks get suspicious.

Bug 10749961

Change-Id: I13e11032cb571df19798c4e13c91a572d1ee61a7
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 6b6e704..5c77a97 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -564,7 +564,9 @@
                 int headerIndex = i + 1;
                 i = insertAccountsHeaders(target, headerIndex);
             } else if (id == R.id.home_settings) {
-                updateHomeSettingHeaders(header);
+                if (!updateHomeSettingHeaders(header)) {
+                    target.remove(i);
+                }
             } else if (id == R.id.user_settings) {
                 if (!UserHandle.MU_ENABLED
                         || !UserManager.supportsMultipleUsers()
@@ -669,11 +671,16 @@
         return ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
     }
 
-    private void updateHomeSettingHeaders(Header header) {
+    private boolean updateHomeSettingHeaders(Header header) {
         final PackageManager pm = getPackageManager();
         final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
         try {
             ComponentName currentHome = pm.getHomeActivities(homeApps);
+            if (homeApps.size() < 2) {
+                // When there's only one available home app, omit this settings
+                // category entirely at the top level UI.
+                return false;
+            }
             ResolveInfo iconSource = null;
             if (currentHome == null) {
                 // no current default, so find the system home app and use that
@@ -708,6 +715,7 @@
             // Can't look up the home activity; bail on configuring the icon
             Log.w(LOG_TAG, "Problem looking up home activity!", e);
         }
+        return true;
     }
 
     private void getMetaData() {