Rework activity lifecycle so onSaveInstanceState() is after onPause().

The goal is to fix a bunch of fragment-related bugs caused by various
things trying to do fragment transactions after onPause()...  which
currently throws an exception, since this is after the activity's state
has been saved so the new fragment state can be lost.

The basic change is relatively simple -- we now consider processes
hosting paused or stopping activities to be unkillable, and the client
code now does the onSaveInstanceState() as part of stopping the
activity.

For compatibility, if an app's targetSdkVersion is < HONEYCOMB, the
client side will still call onSaveInstanceState() prior to onPause()
and just hold on to that state until it needs to report it in once
being stopped.

Also included here is a change to generate thumbnails by taking
screenshots.  The code for generating thumbnails by re-rendering
the view hierarchy is thus removed.

Change-Id: Iac1191646bd3cadbfe65779297795f22edf7e74a
diff --git a/services/java/com/android/server/ScreenRotationAnimation.java b/services/java/com/android/server/ScreenRotationAnimation.java
index a95a6c7..ced7c7b 100644
--- a/services/java/com/android/server/ScreenRotationAnimation.java
+++ b/services/java/com/android/server/ScreenRotationAnimation.java
@@ -152,6 +152,27 @@
         }
     }
 
+    public static void createRotationMatrix(int rotation, int width, int height,
+            Matrix outMatrix) {
+        switch (rotation) {
+            case Surface.ROTATION_0:
+                outMatrix.reset();
+                break;
+            case Surface.ROTATION_90:
+                outMatrix.setRotate(90, 0, 0);
+                outMatrix.postTranslate(height, 0);
+                break;
+            case Surface.ROTATION_180:
+                outMatrix.setRotate(180, 0, 0);
+                outMatrix.postTranslate(width, height);
+                break;
+            case Surface.ROTATION_270:
+                outMatrix.setRotate(270, 0, 0);
+                outMatrix.postTranslate(0, width);
+                break;
+        }
+    }
+
     // Must be called while in a transaction.
     public void setRotation(int rotation) {
         mCurRotation = rotation;
@@ -160,23 +181,7 @@
         // to the snapshot to make it stay in the same original position
         // with the current screen rotation.
         int delta = deltaRotation(rotation, mSnapshotRotation);
-        switch (delta) {
-            case Surface.ROTATION_0:
-                mSnapshotInitialMatrix.reset();
-                break;
-            case Surface.ROTATION_90:
-                mSnapshotInitialMatrix.setRotate(90, 0, 0);
-                mSnapshotInitialMatrix.postTranslate(mHeight, 0);
-                break;
-            case Surface.ROTATION_180:
-                mSnapshotInitialMatrix.setRotate(180, 0, 0);
-                mSnapshotInitialMatrix.postTranslate(mWidth, mHeight);
-                break;
-            case Surface.ROTATION_270:
-                mSnapshotInitialMatrix.setRotate(270, 0, 0);
-                mSnapshotInitialMatrix.postTranslate(0, mWidth);
-                break;
-        }
+        createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
 
         if (DEBUG) Slog.v(TAG, "**** ROTATION: " + delta);
         setSnapshotTransform(mSnapshotInitialMatrix, 1.0f);