Fix issue #4502672: Wrong xml resources used for homescreen widgets.

There was a race in the system process between applying the initial
configuration and executing code in higher-level system services
like the app widget service that relies on the config.  For some
reason it starting showing up more after my code changes; it should
now be completely fixed.

Also fix the activity starting window to run in compatibility mode
if its application is going to be in compatibility mode.

And some various cleanup and small fixes.

Change-Id: I0566933bf1bbb4259c1d99a60c0a3c19af1542e5
diff --git a/services/java/com/android/server/am/CompatModePackages.java b/services/java/com/android/server/am/CompatModePackages.java
index 8949f48..1334bcd 100644
--- a/services/java/com/android/server/am/CompatModePackages.java
+++ b/services/java/com/android/server/am/CompatModePackages.java
@@ -150,9 +150,11 @@
     }
 
     public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
-        return new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
+        CompatibilityInfo ci = new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
                 mService.mConfiguration.smallestScreenWidthDp,
                 (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0);
+        //Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci);
+        return ci;
     }
 
     public int computeCompatModeLocked(ApplicationInfo ai) {