Don't destroy+recreate the InCallScreen on docking or undocking.

Add "uiMode" to android:configChanges for the InCallScreen, which will
prevent the InCallScreen from being destroyed and recreated when you dock
or un-dock the device while in-call.  (The InCallScreen is designed to
*never* be destroyed once it's initially created.)

Also add a skeleton onConfigurationChanged() method for future use (like
when we eventually allow landscape mode for the in-call UI -- see bug 2089513.)
It has no effect right now, since *currently* the InCallScreen looks
exactly the same regardless of configuration.

Side note: This fix is peripherally related to
Bug: 3028132
which was an out-of-memory crash in the phone process.  The crash happened
in InCallScreen.onCreate(), and in the logs I noticed that the
InCallScreen was being re-created because of a dock event (which isn't
supposed to happen.)

I don't think this is the root cause of bug 3028132, though, since the
logs on that bug show only a single InCallScreen destroy/create sequence,
which does *not* do enough allocation to run the process out of memory all
by itself.

TESTED: on passion, docked and undocked repeately during a call, confirmed
the activity was not destroyed and recreated, and that the
onConfigurationChanged() method was correctly called.

Change-Id: I26039588878b172607ac4da7130533f0b77f8e93
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 31c91fc..bd31877 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -219,7 +219,7 @@
             android:excludeFromRecents="true"
             android:launchMode="singleInstance"
             android:screenOrientation="portrait"
-            android:configChanges="orientation|keyboardHidden"
+            android:configChanges="orientation|keyboardHidden|uiMode"
             android:exported="false">
         </activity>
 
diff --git a/src/com/android/phone/InCallScreen.java b/src/com/android/phone/InCallScreen.java
index e03914d..3d5e74c 100755
--- a/src/com/android/phone/InCallScreen.java
+++ b/src/com/android/phone/InCallScreen.java
@@ -27,6 +27,7 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.PixelFormat;
 import android.graphics.Typeface;
@@ -4992,6 +4993,46 @@
         return true;
     }
 
+    /**
+     * Manually handle configuration changes.
+     *
+     * We specify android:configChanges="orientation|keyboardHidden|uiMode" in
+     * our manifest to make sure the system doesn't destroy and re-create us
+     * due to the above config changes.  Instead, this method will be called,
+     * and should manually rebuild the onscreen UI to keep it in sync with the
+     * current configuration.
+     *
+     */
+    public void onConfigurationChanged(Configuration newConfig) {
+        if (DBG) log("onConfigurationChanged: newConfig = " + newConfig);
+
+        // Note: At the time this function is called, our Resources object
+        // will have already been updated to return resource values matching
+        // the new configuration.
+
+        // Watch out: we *can* still get destroyed and recreated if a
+        // configuration change occurs that is *not* listed in the
+        // android:configChanges attribute.  TODO: Any others we need to list?
+
+        super.onConfigurationChanged(newConfig);
+
+        // Nothing else to do here, since (currently) the InCallScreen looks
+        // exactly the same regardless of configuration.
+        // (Specifically, we'll never be in landscape mode because we set
+        // android:screenOrientation="portrait" in our manifest, and we don't
+        // change our UI at all based on newConfig.keyboardHidden or
+        // newConfig.uiMode.)
+
+        // TODO: we do eventually want to handle at least some config changes, such as:
+        boolean isKeyboardOpen = (newConfig.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO);
+        if (DBG) log("  - isKeyboardOpen = " + isKeyboardOpen);
+        boolean isLandscape = (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);
+        if (DBG) log("  - isLandscape = " + isLandscape);
+        if (DBG) log("  - uiMode = " + newConfig.uiMode);
+        // See bug 2089513.
+    }
+
+
     private void log(String msg) {
         Log.d(LOG_TAG, msg);
     }