Fix some bugs.

Bug #2376231: Apps lose window focus (and back key causes ANR) if the
lock screen is dismissed while the phone is in landscape mode

This is another case where we weren't recomputing the focused window
after changing the visibility policy.

bug #2479958: Investigate source of "Resources don't contain package
for resource number 0x7f0a0000"

Um, okay, so it turns out there were bugs all over the place where
we would load an XML resource from a another application, but not
use the Resources for that application to retrieve its resources...!
I think the only reason any of this stuff was working at all was
because it typically only cared about retrieving the resource
identifiers of the items (it would look up the values later).

Bug #2401082: Passion ERE26 monkey crash - InputMethodManagerService

Add some null checks.
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 8781263..f5d3e8e 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -9516,6 +9516,9 @@
 
                         if (mPolicy.doesForceHide(w, attrs)) {
                             if (!wasAnimating && animating) {
+                                if (DEBUG_VISIBILITY) Slog.v(TAG,
+                                        "Animation done that could impact force hide: "
+                                        + w);
                                 wallpaperForceHidingChanged = true;
                                 mFocusMayChange = true;
                             } else if (w.isReadyForDisplay() && w.mAnimation == null) {
@@ -9525,19 +9528,31 @@
                             boolean changed;
                             if (forceHiding) {
                                 changed = w.hideLw(false, false);
+                                if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
+                                        "Now policy hidden: " + w);
                             } else {
                                 changed = w.showLw(false, false);
-                                if (changed && wallpaperForceHidingChanged
-                                        && w.isReadyForDisplay()) {
-                                    // Assume we will need to animate.  If
-                                    // we don't (because the wallpaper will
-                                    // stay with the lock screen), then we will
-                                    // clean up later.
-                                    Animation a = mPolicy.createForceHideEnterAnimation();
-                                    if (a != null) {
-                                        w.setAnimation(a);
+                                if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
+                                        "Now policy shown: " + w);
+                                if (changed) {
+                                    if (wallpaperForceHidingChanged
+                                            && w.isReadyForDisplay()) {
+                                        // Assume we will need to animate.  If
+                                        // we don't (because the wallpaper will
+                                        // stay with the lock screen), then we will
+                                        // clean up later.
+                                        Animation a = mPolicy.createForceHideEnterAnimation();
+                                        if (a != null) {
+                                            w.setAnimation(a);
+                                        }
                                     }
-                                    mFocusMayChange = true;
+                                    if (mCurrentFocus == null ||
+                                            mCurrentFocus.mLayer < w.mLayer) {
+                                        // We are showing on to of the current
+                                        // focus, so re-evaluate focus to make
+                                        // sure it is correct.
+                                        mFocusMayChange = true;
+                                    }
                                 }
                             }
                             if (changed && (attrs.flags