Fix issue #2133206: dialogs/menus should auto-dismiss when screen turns off

Lot of infrastructure for more things to go away when "clear system dialogs"
happens, and now do this when we turn on the lock screen.

Change-Id: I567130296fe47ce82df065ed58ef21b37416ceaf
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index c6937a3..398abf8 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -1610,6 +1610,7 @@
     public final static int DISPATCH_KEY_FROM_IME = 1011;
     public final static int FINISH_INPUT_CONNECTION = 1012;
     public final static int CHECK_FOCUS = 1013;
+    public final static int CLOSE_SYSTEM_DIALOGS = 1014;
 
     @Override
     public void handleMessage(Message msg) {
@@ -1867,6 +1868,11 @@
                 imm.checkFocus();
             }
         } break;
+        case CLOSE_SYSTEM_DIALOGS: {
+            if (mView != null) {
+                mView.onCloseSystemDialogs((String)msg.obj);
+            }
+        } break;
         }
     }
 
@@ -2630,6 +2636,13 @@
         sendMessage(msg);
     }
 
+    public void dispatchCloseSystemDialogs(String reason) {
+        Message msg = Message.obtain();
+        msg.what = CLOSE_SYSTEM_DIALOGS;
+        msg.obj = reason;
+        sendMessage(msg);
+    }
+    
     /**
      * The window is getting focus so if there is anything focused/selected
      * send an {@link AccessibilityEvent} to announce that.
@@ -2869,6 +2882,13 @@
             }
         }
         
+        public void closeSystemDialogs(String reason) {
+            final ViewRoot viewRoot = mViewRoot.get();
+            if (viewRoot != null) {
+                viewRoot.dispatchCloseSystemDialogs(reason);
+            }
+        }
+        
         public void dispatchWallpaperOffsets(float x, float y, boolean sync) {
             if (sync) {
                 try {