Bug 5312828 - Menu button not responding

Increase tolerance for apps calling invalidateOptionsMenu at
inconvenient times.

Change-Id: I712b20002afd0f056c3f05b160c5fa9c2ef0b552
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index de8d41a2..af86ae9 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -349,8 +349,9 @@
         }
 
         // Already prepared (isPrepared will be reset to false later)
-        if (st.isPrepared)
+        if (st.isPrepared) {
             return true;
+        }
         
         if ((mPreparedPanel != null) && (mPreparedPanel != st)) {
             // Another Panel is prepared and possibly open, so close it
@@ -800,14 +801,23 @@
                     closePanel(st, true);
 
                 } else if (st.isPrepared) {
+                    boolean show = true;
+                    if (st.refreshMenuContent) {
+                        // Something may have invalidated the menu since we prepared it.
+                        // Re-prepare it to refresh.
+                        st.isPrepared = false;
+                        show = preparePanel(st, event);
+                    }
 
-                    // Write 'menu opened' to event log
-                    EventLog.writeEvent(50001, 0);
+                    if (show) {
+                        // Write 'menu opened' to event log
+                        EventLog.writeEvent(50001, 0);
 
-                    // Show menu
-                    openPanel(st, event);
+                        // Show menu
+                        openPanel(st, event);
 
-                    playSoundEffect = true;
+                        playSoundEffect = true;
+                    }
                 }
             }