Fix issue #2547337: switching night modes

Dumb.

Change-Id: Iaa72eaac54422f7fd95cf1050f6b7b6da55af0c3
diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java
index a83af95..c40650a 100644
--- a/services/java/com/android/server/UiModeManagerService.java
+++ b/services/java/com/android/server/UiModeManagerService.java
@@ -484,6 +484,7 @@
                     Intent intent = new Intent(Intent.ACTION_MAIN);
                     intent.addCategory(Intent.CATEGORY_HOME);
                     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    mHoldingConfiguration = false;
                     updateConfigurationLocked(false);
                     ActivityManagerNative.getDefault().startActivityWithConfig(
                             null, intent, null, null, 0, null, null, 0, false, false,
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 3bd65cb..d59dd21 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -3670,6 +3670,8 @@
             }
             
             mConfigWillChange = config != null && mConfiguration.diff(config) != 0;
+            if (DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Starting activity when config will change = " + mConfigWillChange);
             
             final long origId = Binder.clearCallingIdentity();
             
@@ -3678,13 +3680,16 @@
                     resultTo, resultWho, requestCode, callingPid, callingUid,
                     onlyIfNeeded, componentSpecified);
             
-            if (config != null && mConfigWillChange) {
+            if (mConfigWillChange) {
                 // If the caller also wants to switch to a new configuration,
                 // do so now.  This allows a clean switch, as we are waiting
                 // for the current activity to pause (so we will not destroy
                 // it), and have not yet started the next activity.
                 enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
                         "updateConfiguration()");
+                mConfigWillChange = false;
+                if (DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Updating to new configuration after starting activity.");
                 updateConfigurationLocked(config, null);
             }
             
@@ -13493,7 +13498,7 @@
      */
     private final boolean ensureActivityConfigurationLocked(HistoryRecord r,
             int globalChanges) {
-        if (!mConfigWillChange) {
+        if (mConfigWillChange) {
             if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
                     "Skipping config check (will change): " + r);
             return true;