Fix issue #4974633: Block the HOME button using TYPE_KEYGUARD

Applications shouldn't be able to change their window type after
the window is added to the window manager.

Change-Id: Iac63da65f96fb30683f68f8d89c3fd29199a750c
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index f5a5e2e..ce6cbd7 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -2498,6 +2498,10 @@
             int attrChanges = 0;
             int flagChanges = 0;
             if (attrs != null) {
+                if (win.mAttrs.type != attrs.type) {
+                    throw new IllegalArgumentException(
+                            "Window type can not be changed after the window is added.");
+                }
                 flagChanges = win.mAttrs.flags ^= attrs.flags;
                 attrChanges = win.mAttrs.copyFrom(attrs);
             }