Dynamically show the menu button on the system bar.

Windows with FLAG_NEEDS_MENU_KEY (or windowNeedsMenuKey=true
in their theme) will cause the system bar to show a menu
icon. (Note that the phone's status bar currently ignores
this, but phones tend to have hardware menu keys anyway.)

Additionally, all windows whose package's SDK version is
pre-Honeycomb will have FLAG_NEEDS_MENU_KEY set by default.

Bug: 3003728

Change-Id: I2d983763a726ea4f32cd1af9b0390e30478b11d1
diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java
index b1baec5..66e02146 100644
--- a/services/java/com/android/server/StatusBarManagerService.java
+++ b/services/java/com/android/server/StatusBarManagerService.java
@@ -72,6 +72,8 @@
     // We usually call it lights out mode, but double negatives are annoying
     boolean mLightsOn = true;
 
+    boolean mMenuVisible = false;
+
     private class DisableRecord implements IBinder.DeathRecipient {
         String pkg;
         int what;
@@ -246,6 +248,32 @@
         }
     }
 
+    /** 
+     * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
+     * response to a window with FLAG_NEEDS_MENU_KEY set.
+     */
+    public void setMenuKeyVisible(final boolean visible) {
+        enforceStatusBar();
+
+        if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
+
+        synchronized(mLock) {
+            if (mMenuVisible != visible) {
+                mMenuVisible = visible;
+                mHandler.post(new Runnable() {
+                        public void run() {
+                            if (mBar != null) {
+                                try {
+                                    mBar.setMenuKeyVisible(visible);
+                                } catch (RemoteException ex) {
+                                }
+                            }
+                        }
+                    });
+            }
+        }
+    }
+
     /**
      * This is used for the automatic version of lights-out mode.  Only call this from
      * the window manager.
@@ -317,7 +345,7 @@
     // ================================================================================
     public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
             List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
-            boolean lightsOn[]) {
+            boolean switches[]) {
         enforceStatusBarService();
 
         Slog.i(TAG, "registerStatusBar bar=" + bar);
@@ -332,7 +360,8 @@
             }
         }
         synchronized (mLock) {
-            lightsOn[0] = mLightsOn;
+            switches[0] = mLightsOn;
+            switches[1] = mMenuVisible;
         }
     }