Merge "Update hardware acceleration doc"
diff --git a/api/current.txt b/api/current.txt
index be296b2..a66ed73 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -17560,6 +17560,7 @@
     field public static final java.lang.String RADIO_NFC = "nfc";
     field public static final java.lang.String RADIO_WIFI = "wifi";
     field public static final java.lang.String RINGTONE = "ringtone";
+    field public static final java.lang.String SCREEN_AUTO_BRIGHTNESS_ADJ = "screen_auto_brightness_adj";
     field public static final java.lang.String SCREEN_BRIGHTNESS = "screen_brightness";
     field public static final java.lang.String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode";
     field public static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1; // 0x1
diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl
index 9a53d76..270e9be 100644
--- a/core/java/android/os/IPowerManager.aidl
+++ b/core/java/android/os/IPowerManager.aidl
@@ -45,4 +45,5 @@
     // sets the brightness of the backlights (screen, keyboard, button) 0-255
     void setBacklightBrightness(int brightness);
     void setAttentionLight(boolean on, int color);
+    void setAutoBrightnessAdjustment(float adj);
 }
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 0202c47..ba9046c 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1401,6 +1401,12 @@
         public static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode";
 
         /**
+         * Adjustment to auto-brightness to make it generally more (>0.0 <1.0)
+         * or less (<0.0 >-1.0) bright.
+         */
+        public static final String SCREEN_AUTO_BRIGHTNESS_ADJ = "screen_auto_brightness_adj";
+
+        /**
          * SCREEN_BRIGHTNESS_MODE value for manual mode.
          */
         public static final int SCREEN_BRIGHTNESS_MODE_MANUAL = 0;
@@ -1927,6 +1933,7 @@
             SCREEN_OFF_TIMEOUT,
             SCREEN_BRIGHTNESS,
             SCREEN_BRIGHTNESS_MODE,
+            SCREEN_AUTO_BRIGHTNESS_ADJ,
             VIBRATE_ON,
             MODE_RINGER,
             MODE_RINGER_STREAMS_AFFECTED,
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index baeb0ed..fe5c04c 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -1742,6 +1742,7 @@
                             Rect rect = (Rect) msg.obj;
                             nativeScrollLayer(mNativeClass, nativeLayer,
                                     rect);
+                            break;
 
                         case DELETE_TEXT: {
                             int[] handles = (int[]) msg.obj;
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index f78c247..04f4a83 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -342,6 +342,7 @@
     private int mTextEditSuggestionItemLayout;
     private SuggestionsPopupWindow mSuggestionsPopupWindow;
     private SuggestionRangeSpan mSuggestionRangeSpan;
+    private Runnable mShowSuggestionRunnable;
 
     private int mCursorDrawableRes;
     private final Drawable[] mCursorDrawable = new Drawable[2];
@@ -4513,6 +4514,10 @@
             mSelectionModifierCursorController.onDetached();
         }
 
+        if (mShowSuggestionRunnable != null) {
+            removeCallbacks(mShowSuggestionRunnable);
+        }
+
         hideControllers();
 
         resetResolvedDrawables();
@@ -8330,6 +8335,10 @@
             getSelectionController().onTouchEvent(event);
         }
 
+        if (mShowSuggestionRunnable != null) {
+            removeCallbacks(mShowSuggestionRunnable);
+        }
+
         if (action == MotionEvent.ACTION_DOWN) {
             mLastDownPositionX = event.getX();
             mLastDownPositionY = event.getY();
@@ -8370,7 +8379,7 @@
                 ClickableSpan[] links = ((Spannable) mText).getSpans(getSelectionStart(),
                         getSelectionEnd(), ClickableSpan.class);
 
-                if (links.length != 0) {
+                if (links.length > 0) {
                     links[0].onClick(this);
                     handled = true;
                 }
@@ -8397,7 +8406,15 @@
                     }
                     if (!extractedTextModeWillBeStarted()) {
                         if (isCursorInsideEasyCorrectionSpan()) {
-                            showSuggestions();
+                            if (mShowSuggestionRunnable == null) {
+                                mShowSuggestionRunnable = new Runnable() {
+                                    public void run() {
+                                        showSuggestions();
+                                    }
+                                };
+                            }
+                            postDelayed(mShowSuggestionRunnable,
+                                    ViewConfiguration.getDoubleTapTimeout());
                         } else if (hasInsertionController()) {
                             getInsertionController().show();
                         }
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 9c45dc6..6a99a2b 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -243,7 +243,7 @@
     private static void preloadClasses() {
         final VMRuntime runtime = VMRuntime.getRuntime();
 
-        InputStream is = ZygoteInit.class.getClassLoader().getResourceAsStream(
+        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(
                 PRELOADED_CLASSES);
         if (is == null) {
             Log.e(TAG, "Couldn't find " + PRELOADED_CLASSES + ".");
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index 3e9ab86..c8b725a 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -776,9 +776,6 @@
 
     static void doDrawGlyphs(SkCanvas* canvas, const jchar* glyphArray, int index, int count,
             jfloat x, jfloat y, int flags, SkPaint* paint) {
-        // TODO: need to suppress this code after the GL renderer is modified for not
-        // copying the paint
-
         // Beware: this needs Glyph encoding (already done on the Paint constructor)
         canvas->drawText(glyphArray + index * 2, count * 2, x, y, *paint);
     }
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 9f3238ab..9bcfa5f 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -466,7 +466,8 @@
         jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL);
 
         TextLayoutCacheValue value(contextCount);
-        TextLayoutEngine::getInstance().computeValues(&value, paint, text, start, count, contextCount, flags);
+        TextLayoutEngine::getInstance().computeValues(&value, paint, text, start, count,
+                contextCount, flags);
         const jchar* shapedGlyphs = value.getGlyphs();
         size_t glyphsCount = value.getGlyphsCount();
         memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount);
@@ -673,13 +674,25 @@
         }
     }
 
-    static int breakText(JNIEnv* env, const SkPaint& paint, const jchar text[],
+    static int breakText(JNIEnv* env, SkPaint& paint, const jchar text[],
                          int count, float maxWidth, jfloatArray jmeasured,
                          SkPaint::TextBufferDirection tbd) {
-        SkASSERT(paint.getTextEncoding() == SkPaint::kUTF16_TextEncoding);
+        sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+        value = TextLayoutCache::getInstance().getValue(&paint, text, 0, count,
+                count, paint.getFlags());
+        if (value == NULL) {
+            ALOGE("Cannot get TextLayoutCache value for text = '%s'",
+                    String8(text, count).string());
+        }
+#else
+        value = new TextLayoutCacheValue(count);
+        TextLayoutEngine::getInstance().computeValues(value.get(), &paint,
+                reinterpret_cast<const UChar*>(text), 0, count, count, paint.getFlags());
+#endif
 
         SkScalar     measured;
-        size_t       bytes = paint.breakText(text, count << 1,
+        size_t       bytes = paint.breakText(value->getGlyphs(), value->getGlyphsCount() << 1,
                                    SkFloatToScalar(maxWidth), &measured, tbd);
         SkASSERT((bytes & 1) == 0);
 
@@ -743,7 +756,20 @@
         SkRect  r;
         SkIRect ir;
 
-        paint.measureText(text, count << 1, &r);
+        sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+        value = TextLayoutCache::getInstance().getValue(&paint, text, 0, count,
+                count, paint.getFlags());
+        if (value == NULL) {
+            ALOGE("Cannot get TextLayoutCache value for text = '%s'",
+                    String8(text, count).string());
+        }
+#else
+        value = new TextLayoutCacheValue(count);
+        TextLayoutEngine::getInstance().computeValues(value.get(), &paint,
+                reinterpret_cast<const UChar*>(text), 0, count, count, paint.getFlags());
+#endif
+        paint.measureText(value->getGlyphs(), value->getGlyphsCount() << 1, &r);
         r.roundOut(&ir);
         GraphicsJNI::irect_to_jrect(ir, env, bounds);
     }
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index d26f563..71c283a 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -93,7 +93,7 @@
 /*
  * Caching
  */
-sp<TextLayoutCacheValue> TextLayoutCache::getValue(SkPaint* paint,
+sp<TextLayoutCacheValue> TextLayoutCache::getValue(const SkPaint* paint,
             const jchar* text, jint start, jint count, jint contextCount, jint dirFlags) {
     AutoMutex _l(mLock);
     nsecs_t startTime = 0;
@@ -360,7 +360,7 @@
     // we don't bother at the moment
 }
 
-void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, SkPaint* paint, const UChar* chars,
+void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, const SkPaint* paint, const UChar* chars,
         size_t start, size_t count, size_t contextCount, int dirFlags) {
 
     computeValues(paint, chars, start, count, contextCount, dirFlags,
@@ -371,7 +371,7 @@
 #endif
 }
 
-void TextLayoutEngine::computeValues(SkPaint* paint, const UChar* chars,
+void TextLayoutEngine::computeValues(const SkPaint* paint, const UChar* chars,
         size_t start, size_t count, size_t contextCount, int dirFlags,
         Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
         Vector<jchar>* const outGlyphs) {
@@ -513,7 +513,7 @@
     }
 }
 
-void TextLayoutEngine::computeRunValues(SkPaint* paint, const UChar* chars,
+void TextLayoutEngine::computeRunValues(const SkPaint* paint, const UChar* chars,
         size_t count, bool isRTL,
         Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
         Vector<jchar>* const outGlyphs) {
@@ -719,7 +719,7 @@
 }
 
 
-size_t TextLayoutEngine::shapeFontRun(SkPaint* paint, bool isRTL) {
+size_t TextLayoutEngine::shapeFontRun(const SkPaint* paint, bool isRTL) {
     // Reset kerning
     mShaperItem.kerning_applied = false;
 
diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h
index 510aa18..956e8ca 100644
--- a/core/jni/android/graphics/TextLayoutCache.h
+++ b/core/jni/android/graphics/TextLayoutCache.h
@@ -179,7 +179,7 @@
      */
     void operator()(TextLayoutCacheKey& text, sp<TextLayoutCacheValue>& desc);
 
-    sp<TextLayoutCacheValue> getValue(SkPaint* paint, const jchar* text, jint start, jint count,
+    sp<TextLayoutCacheValue> getValue(const SkPaint* paint, const jchar* text, jint start, jint count,
             jint contextCount, jint dirFlags);
 
     /**
@@ -224,7 +224,7 @@
     TextLayoutEngine();
     virtual ~TextLayoutEngine();
 
-    void computeValues(TextLayoutCacheValue* value, SkPaint* paint, const UChar* chars,
+    void computeValues(TextLayoutCacheValue* value, const SkPaint* paint, const UChar* chars,
             size_t start, size_t count, size_t contextCount, int dirFlags);
 
 private:
@@ -273,14 +273,14 @@
      */
     UnicodeString mBuffer;
 
-    size_t shapeFontRun(SkPaint* paint, bool isRTL);
+    size_t shapeFontRun(const SkPaint* paint, bool isRTL);
 
-    void computeValues(SkPaint* paint, const UChar* chars,
+    void computeValues(const SkPaint* paint, const UChar* chars,
             size_t start, size_t count, size_t contextCount, int dirFlags,
             Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
             Vector<jchar>* const outGlyphs);
 
-    void computeRunValues(SkPaint* paint, const UChar* chars,
+    void computeRunValues(const SkPaint* paint, const UChar* chars,
             size_t count, bool isRTL,
             Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
             Vector<jchar>* const outGlyphs);
diff --git a/core/res/res/anim/screen_rotate_180_enter.xml b/core/res/res/anim/screen_rotate_180_enter.xml
index 95cc562..470416b 100644
--- a/core/res/res/anim/screen_rotate_180_enter.xml
+++ b/core/res/res/anim/screen_rotate_180_enter.xml
@@ -19,16 +19,10 @@
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
-    <scale android:fromXScale="1.0" android:toXScale="1.0"
-            android:fromYScale=".9" android:toYScale="1.0"
-            android:pivotX="50%p" android:pivotY="50%p"
-            android:fillEnabled="true" android:fillBefore="true"
+    <rotate android:fromDegrees="180" android:toDegrees="0"
+            android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
-            android:startOffset="160"
-            android:duration="300" />
-    <alpha android:fromAlpha="0" android:toAlpha="1.0"
-            android:fillEnabled="true" android:fillBefore="true"
-            android:interpolator="@interpolator/decelerate_quint"
-            android:startOffset="160"
-            android:duration="300"/>
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
 </set>
\ No newline at end of file
diff --git a/core/res/res/anim/screen_rotate_180_exit.xml b/core/res/res/anim/screen_rotate_180_exit.xml
index d3dd4c0..58a1868 100644
--- a/core/res/res/anim/screen_rotate_180_exit.xml
+++ b/core/res/res/anim/screen_rotate_180_exit.xml
@@ -19,12 +19,10 @@
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
-    <scale android:fromXScale="1.0" android:toXScale="1.0"
-            android:fromYScale="1.0" android:toYScale="0.0"
-            android:pivotX="50%p" android:pivotY="50%p"
-            android:interpolator="@interpolator/accelerate_cubic"
-            android:duration="160" />
-    <alpha android:fromAlpha="1.0" android:toAlpha="0"
-            android:interpolator="@interpolator/decelerate_cubic"
-            android:duration="160"/>
+    <rotate android:fromDegrees="0" android:toDegrees="-180"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
 </set>
\ No newline at end of file
diff --git a/core/res/res/anim/screen_rotate_finish_enter.xml b/core/res/res/anim/screen_rotate_finish_enter.xml
new file mode 100644
index 0000000..849aa66
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_finish_enter.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+        android:shareInterpolator="false">
+    <scale android:fromXScale="1.0" android:toXScale="1.25"
+            android:fromYScale="1.0" android:toYScale="1.25"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="100%p" android:toXScale="100%"
+            android:fromYScale="100%p" android:toYScale="100%"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
+</set>
diff --git a/core/res/res/anim/screen_rotate_finish_exit.xml b/core/res/res/anim/screen_rotate_finish_exit.xml
new file mode 100644
index 0000000..7f70dbc
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_finish_exit.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+        android:shareInterpolator="false">
+    <scale android:fromXScale="1.0" android:toXScale="1.25"
+            android:fromYScale="1.0" android:toYScale="1.25"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <!--
+    <scale android:fromXScale="100%" android:toXScale="100%p"
+            android:fromYScale="100%" android:toYScale="100%p"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
+    <alpha android:fromAlpha="1.0" android:toAlpha="0"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
+</set>
diff --git a/core/res/res/anim/screen_rotate_minus_90_enter.xml b/core/res/res/anim/screen_rotate_minus_90_enter.xml
index 61aa72a..d2aebc9 100644
--- a/core/res/res/anim/screen_rotate_minus_90_enter.xml
+++ b/core/res/res/anim/screen_rotate_minus_90_enter.xml
@@ -19,8 +19,44 @@
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
+    <!--
+    <scale android:fromXScale="1.0" android:toXScale="0.565"
+            android:fromYScale="1.0" android:toYScale="0.565"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="1.0" android:toXScale="1.777777777"
+            android:fromYScale="1.0" android:toYScale="1.777777777"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:startOffset="@android:integer/config_longAnimTime"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="100%p" android:toXScale="100%"
+            android:fromYScale="100%p" android:toYScale="100%"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:startOffset="@android:integer/config_longAnimTime"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
+    <!--
+    <scale android:fromXScale="100%p" android:toXScale="100%"
+            android:fromYScale="100%p" android:toYScale="100%"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
     <rotate android:fromDegrees="-90" android:toDegrees="0"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
             android:duration="@android:integer/config_mediumAnimTime" />
 </set>
diff --git a/core/res/res/anim/screen_rotate_minus_90_exit.xml b/core/res/res/anim/screen_rotate_minus_90_exit.xml
index 65294f6..c7c38cd 100644
--- a/core/res/res/anim/screen_rotate_minus_90_exit.xml
+++ b/core/res/res/anim/screen_rotate_minus_90_exit.xml
@@ -19,16 +19,51 @@
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
+    <!--
+    <scale android:fromXScale="1.0" android:toXScale="0.565"
+            android:fromYScale="1.0" android:toYScale="0.565"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="1.0" android:toXScale="1.777777777"
+            android:fromYScale="1.0" android:toYScale="1.777777777"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:startOffset="@android:integer/config_longAnimTime"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="100%" android:toXScale="100%p"
+            android:fromYScale="100%" android:toYScale="100%p"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:startOffset="@android:integer/config_longAnimTime"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    <alpha android:fromAlpha="1.0" android:toAlpha="0"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:startOffset="@android:integer/config_longAnimTime"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
+    <!--
     <scale android:fromXScale="100%" android:toXScale="100%p"
             android:fromYScale="100%" android:toYScale="100%p"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
             android:duration="@android:integer/config_mediumAnimTime" />
+    <alpha android:fromAlpha="1.0" android:toAlpha="0"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
     <rotate android:fromDegrees="0" android:toDegrees="90"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
-            android:duration="@android:integer/config_mediumAnimTime" />
-    <alpha android:fromAlpha="1.0" android:toAlpha="0"
-            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
             android:duration="@android:integer/config_mediumAnimTime" />
 </set>
diff --git a/core/res/res/anim/screen_rotate_plus_90_enter.xml b/core/res/res/anim/screen_rotate_plus_90_enter.xml
index 53b0ccd..63d7043 100644
--- a/core/res/res/anim/screen_rotate_plus_90_enter.xml
+++ b/core/res/res/anim/screen_rotate_plus_90_enter.xml
@@ -19,8 +19,44 @@
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
+    <!--
+    <scale android:fromXScale="1.0" android:toXScale="0.565"
+            android:fromYScale="1.0" android:toYScale="0.565"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="1.0" android:toXScale="1.777777777"
+            android:fromYScale="1.0" android:toYScale="1.777777777"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:startOffset="75"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="100%p" android:toXScale="100%"
+            android:fromYScale="100%p" android:toYScale="100%"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:startOffset="75"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
+    <!--
+    <scale android:fromXScale="100%p" android:toXScale="100%"
+            android:fromYScale="100%p" android:toYScale="100%"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
     <rotate android:fromDegrees="90" android:toDegrees="0"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
             android:duration="@android:integer/config_mediumAnimTime" />
 </set>
diff --git a/core/res/res/anim/screen_rotate_plus_90_exit.xml b/core/res/res/anim/screen_rotate_plus_90_exit.xml
index 63c0b09..ea48c81 100644
--- a/core/res/res/anim/screen_rotate_plus_90_exit.xml
+++ b/core/res/res/anim/screen_rotate_plus_90_exit.xml
@@ -19,16 +19,51 @@
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
+    <!--
+    <scale android:fromXScale="1.0" android:toXScale="0.565"
+            android:fromYScale="1.0" android:toYScale="0.565"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="1.0" android:toXScale="1.777777777"
+            android:fromYScale="1.0" android:toYScale="1.777777777"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:startOffset="75"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+    <scale android:fromXScale="100%" android:toXScale="100%p"
+            android:fromYScale="100%" android:toYScale="100%p"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:startOffset="75"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    <alpha android:fromAlpha="1.0" android:toAlpha="0"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:startOffset="75"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
+    <!--
     <scale android:fromXScale="100%" android:toXScale="100%p"
             android:fromYScale="100%" android:toYScale="100%p"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
             android:duration="@android:integer/config_mediumAnimTime" />
+    <alpha android:fromAlpha="1.0" android:toAlpha="0"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="false" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime" />
+    -->
     <rotate android:fromDegrees="0" android:toDegrees="-90"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
-            android:duration="@android:integer/config_mediumAnimTime" />
-    <alpha android:fromAlpha="1.0" android:toAlpha="0"
-            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
             android:duration="@android:integer/config_mediumAnimTime" />
 </set>
diff --git a/core/res/res/anim/screen_rotate_start_enter.xml b/core/res/res/anim/screen_rotate_start_enter.xml
new file mode 100644
index 0000000..e3f48e4d
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_start_enter.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+        android:shareInterpolator="false">
+    <scale android:fromXScale="1.0" android:toXScale="0.8"
+            android:fromYScale="1.0" android:toYScale="0.8"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+</set>
diff --git a/core/res/res/anim/screen_rotate_start_exit.xml b/core/res/res/anim/screen_rotate_start_exit.xml
new file mode 100644
index 0000000..e3f48e4d
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_start_exit.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+        android:shareInterpolator="false">
+    <scale android:fromXScale="1.0" android:toXScale="0.8"
+            android:fromYScale="1.0" android:toYScale="0.8"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_mediumAnimTime"/>
+</set>
diff --git a/docs/html/guide/publishing/preparing.jd b/docs/html/guide/publishing/preparing.jd
index 4d3bffa..83aa5ee 100644
--- a/docs/html/guide/publishing/preparing.jd
+++ b/docs/html/guide/publishing/preparing.jd
@@ -117,6 +117,9 @@
 certificate requirements, see <a href="{@docRoot}guide/publishing/app-signing.html#cert">Obtain a
 suitable private key</a>.</p>
 
+<p class="caution"><strong>Important:</strong> Your application must be signed with a cryptographic
+key whose validity period ends after 22 October 2033.</p>
+
 <p>You may also have to obtain other release keys if your application accesses a service or uses a
 third-party library that requires you to use a key that is based on your private key. For example,
 if your application uses the <a
diff --git a/docs/html/guide/publishing/publishing.jd b/docs/html/guide/publishing/publishing.jd
index fa677e6..49b34d8 100644
--- a/docs/html/guide/publishing/publishing.jd
+++ b/docs/html/guide/publishing/publishing.jd
@@ -7,9 +7,9 @@
 <h2>Quickview</h2>
 
 <ul>
-<li>You can publish your application using a hosted service such as Android Market or through a web server.</li>
-<li>Before you publish, make sure you have prepared your application properly.</li>
-<li>Android Market makes it easy for users of Android-powered devices to see and download your application.</li>
+<li>Learn how to publish and update apps on Android Market.</li>
+<li>Find out how to create links to apps that are published on Android Market.</li>
+<li>Learn about Android Market features.</li>
 </ul>
 
 
@@ -17,97 +17,201 @@
 
 <ol>
 <li><a href="#overview">About Android Market</a>
+<li><A href="#marketpublish">Publishing Apps on Android Market</a></li>
 <li><a href="#marketupgrade">Publishing Updates on Android Market</a></li>
 <li><a href="#marketLicensing">Using Android Market Licensing Service</a></li>
+<li><a href="#marketinappbilling">Using Android Market In-app Billing</a></li>
 <li><a href="#marketintent">Linking to Your Apps on Android Market</a>
   <ol>
     <li><a href="#OpeningDetails">Opening an app's details page</a></li>
     <li><a href="#PerformingSearch">Performing a search</a></li>
     <li><a href="#BuildaButton">Build an Android Market button</a></li>
     <li><a href="#UriSummary">Summary of URI formats</a></li>
-  </ol>  
+  </ol>
 </li>
 </ol>
 
 <h2>See also</h2>
 
 <ol>
-<li><a href="{@docRoot}guide/publishing/licensing.html">Application Licensing</a></li>
-<li><a href="{@docRoot}guide/publishing/preparing.html">Preparing to Publish</a></li>
+<li><a href="{@docRoot}guide/publishing/publishing_overview.html">Publishing Overview</a></li>
+<li><a href="{@docRoot}guide/publishing/preparing.html">Preparing for Release</a></li>
 </ol>
 
 <div id="qv-extra">
   <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png">
   <div id="qv-sub-rule">
     <img src="{@docRoot}assets/images/icon_market.jpg" style="float:left;margin:0;padding:0 5px;">
-    <h2 style="color:#669999;">Interested in publishing your app on Android Market?</h2>
-    <p><a href="http://market.android.com/publish">Go to Android Market</a> to
-create a developer account and upload your application. For more information about the
-required assets, listing details, and options, see <a
-href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading
-applications</a>.</p>
+    <h2 style="color:#669999;">Already know about Android Market and want to get started?</h2>
+    <p>Go to <a href="http://market.android.com/publish">Android Market</a>, create a developer
+account, and upload your application. For more information about required assets, listing details,
+and publishing options, see <a
+href="http://market.android.com/support/bin/answer.py?answer=113469">Upload
+Applications</a>.</p>
   </div>
 </div>
 
 </div>
 </div>
 
-<p>If you've followed the steps outlined in <a
-href="{@docRoot}guide/publishing/preparing.html">Preparing to Publish</a>, the result of the process
-is a compiled {@code .apk} file that is signed with your private release key. Your application is
-now ready to be published publicly so users can install it.</p>
+<p>One of the most effective ways to get your application into users' hands is to
+publish it on an application marketplace like Android Market. Publishing on Android Market is a
+straightforward process that you can do in just a few simple steps&mdash;register, configure,
+upload, and publish. Registration takes only a few minutes and needs to be done only once.
+The configuration and publishing steps can all be done through the Android Market Developer Console
+after you register as an Android Market developer.</p>
 
-<p>You can publish your application and allow users to install it any way you choose, including
-from your own web server. This document provides information about publishing your Android
-application with Android Market.</p>
+<p>To start publishing on Android Market, first read this topic and then go to the <a
+href="https://market.android.com/publish/signup">Android Market publisher site</a> and register as
+an Android Market developer.</p>
 
 
 <h2 id="overview">About Android Market</h2>
 
-<p>Android Market is a service that makes it easy for users to find and download Android
-applications to their Android-powered devices, either from the Android Market application on their
-device or from the Android Market web site (<a
-href="http://market.android.com">market.android.com</a>). As a developer, you can use Android Market
-to distribute your applications to users on all types of Android-powered devices, all around the
-world.</p>
+<p>Android Market is a robust publishing platform that helps you publicize, sell, and distribute
+your Android applications to users around the world. When you release your applications through
+Android Market you have access to a suite of developer tools that let you analyze your sales,
+identify market trends, and control who your applications are being distributed to. You also have
+access to several revenue-enhancing features, such as <a
+href="{@docRoot}guide/market/billing/index.html">in-app billing</a> and
+<a href="{@docRoot}guide/publishing/licensing.html">application licensing</a>.</p>
 
-<p>To publish your application on Android Market, you first need to register
-with the service using a Google account and agree to the terms of service.
-Once you are registered, you can upload your application to the service whenever
-you want, update it as many times as you want, and then publish it when you are ready.
-Once published, users can see your application, download it, and rate it. </p>
+<p>Before you can publish applications on Android Market, you need to <a
+href="http://market.android.com/publish">register</a> as an Android Market developer. During the
+registration process you will need to create a developer profile, pay a registration fee, and agree
+to the <a href="http://www.android.com/us/developer-distribution-agreement.html">Android Market
+Developer Distribution Agreement</a>. After you register you can access the Android Market Developer
+Console, where you can upload applications, configure publishing options, and monitor publishing
+data. If you want to sell your applications or use the in-app billing feature, you will also need
+to set up a Google Checkout merchant account. For more information about the registration process,
+see <a href="https://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=113468">
+Developer Registration</a>.</p>
 
-<p>To register as an Android Market developer and get started with publishing,
-visit the Android Market publisher site: </p>
+<h2 id="marketpublish">Publishing Apps on Android Market</h2>
 
-<p style="margin-left:3em;"><a
-href="http://market.android.com/publish">http://market.android.com/publish</a>
+<p>Publishing your application on Android Market is a simple process that involves three basic
+tasks (see figure 1):</p>
+
+<ul>
+  <li>Creating various graphical assets that
+accompany your app on Android Market.</li>
+  <li>Using the Android Market <a
+href="http://market.android.com/publish">Developer Console</a> to configure publishing options,
+specify listing details, and upload your app and graphical assets to Android Market.</li>
+  <li>Reviewing your publishing settings and changing the release
+status of your app from Unpublished to Published.</li>
+</ul>
+
+<img src="{@docRoot}images/publishing/publishing_android_market.png"
+     alt="Shows the three steps that are required to publish on Android Market"
+     height="168"
+     id="figure1" />
+<p class="img-caption">
+  <strong>Figure 1.</strong> To publish apps on Android Market you must first <a
+href="{@docRoot}guide/publishing/preparing.html">prepare your app for release</a> and then perform
+three simple tasks.
 </p>
 
-<p>If you plan to publish your application on Android Market, you must make sure
-that it meets the requirements listed below, which are enforced by the Market
-server when you upload the application.</p>
+<p class="caution"><strong>Important:</strong> You must <a
+href="{@docRoot}guide/publishing/preparing.html">prepare your application for release</a> before you
+can publish it on Android Market. When you prepare your application for release you configure it for
+release and build it in release mode. Building in release mode signs your application's {@code .apk}
+file with your private release key. You cannot publish an application on Android Market unless it is
+signed with your own private release key.</p>
 
-<div class="special">
-<p>Requirements enforced by the Android Market server:</p>
-<ol>
-<li>Your application must be signed with a cryptographic private key whose
-validity period ends after <span style="color:red">22 October 2033</span>. </li>
-<li>Your application must define both an <code>android:versionCode</code> and an
-<code>android:versionName</code> attribute in the
+<h3>Preparing promotional materials</h3>
+
+<p>To fully leverage the marketing and publicity capabilities of Android Market, you need to create
+several graphical assets that accompany your app on Android Market, such as screenshots, videos,
+promotional graphics, and promotional text. At a minimum you must provide two screenshots of your
+application and a high resolution application icon. The screenshots are displayed on the details
+page for your application in Android Market, and the high resolution application icon is displayed
+in various locations throughout Android Market. The high resolution icon does not replace the
+launcher icon for your application, rather, it serves as a supplemental icon and should look
+the same as your launcher icon. Promotional video,
+graphics, and text are optional, although we strongly recommended that you prepare these for your
+app. For more information about the graphic assets that accompany your application, see <a
+href="http://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=1078870">Graphic
+Assets for your Application</a>.</p>
+
+<h3>Configuring options and uploading assets</h3>
+
+<p>Android Market lets you target your application to a worldwide pool of users and devices. To
+reach these users you can use the Android Market Developer Console to configure various publishing
+options and listing details for your app. For example, you can choose the <a
+href="http://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=138294&topic=
+2365624&ctx=topic">countries</a> you want to reach, the listing languages you want to use, and the
 <a
-href="{@docRoot}guide/topics/manifest/manifest-element.html"><code>&lt;manifest&gt;</code></a>
-element of its manifest file. The server uses the <code>android:versionCode</code> as
-the basis for identifying the application internally and handling updates, and
-it displays the <code>android:versionName</code> to users as the application's
-version.</li>
-<li>Your application must define both an <code>android:icon</code> and an
-<code>android:label</code> attribute in the <a
-href="{@docRoot}guide/topics/manifest/application-element.html"><code>&lt;application&gt;</code></a>
-element of its manifest file.</li>
-</ol>
-</div>
+href="http://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=138412&topic=
+15867&ctx=topic">price</a> you want to charge in each country. You can also configure listing
+details such as the application type, <a
+href="https://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=113475&topic=
+2365760&ctx=topic">category</a>, and <a
+href="http://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=188189&topic=
+2364761&ctx=topic">content rating</a>. In addition, if you want to sell items within your app using
+the in-app billing feature, you can use the Developer Console to <a
+href="http://grendel.sea.corp.google.com:48014/guide/market/billing/billing_admin.html#billing-list
+- setup">create a product list</a> and control which items are available for purchase in your
+app.</p>
 
+<p>When you are finished setting publishing options and listing details, you can upload your assets
+and your application to Android Market. You can also upload your application as a draft
+(unpublished) application, which lets you do final testing before you publish it for final
+release.</p>
+
+<p>To learn more about Android Market publishing settings, see the following resources:</p>
+
+<ul>
+  <li><a
+href="http://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=113469&topic=
+236562&ctx=topic">Upload Applications</a>&mdash;provides a summary of the publishing settings
+you can configure for an app.</li>
+  <li><a
+href="http://support.google.com/androidmarket/developer/bin/topic.py?hl=en&topic=15867">Selling
+Your Apps</a>&mdash;provides guidance about pricing, supported currencies, tax rates, and many
+other topics related to selling apps.</li>
+  <li><a
+href="https://support.google.com/androidmarket/developer/bin/answer.py?hl=en&answer=1169947&topic=
+15867&ctx=topic">Selling Apps in Multiple Currencies</a>&mdash;provides a description of how
+pricing, payouts, and exchange rates work.</li>
+</ul>
+
+<h3>Publishing your application</h3>
+
+<p>When you are satisfied that your publishing settings are correctly configured and your uploaded
+application is ready to be released to the public, you can simply click <strong>Publish</strong> in
+the Developer Console to make your app available for download
+around the world. Keep in mind, it can take several hours for your app to appear on Android
+Market after you click <strong>Publish</strong> in the Developer Console.</p>
+
+<h3>Controlling Distribution to Devices</h3>
+
+<p>If your application targets different device configurations, you can control which Android-powered
+devices have access to your application on Android Market by
+using Android Market filters. Filtering compares device configurations that you declare in your
+app's manifest file to the configuration defined by a device. For example, if you declare the camera
+filter in your manifest, only those devices that have a camera will see your app on Android
+Market. Filters must be configured in your application's manifest file when you are <a
+href="{@docRoot}guide/publishing/preparing.html">preparing your app for release</a> (that is, before
+you upload your app to Android Market). For more information, see <a
+href="{@docRoot}guide/appendix/market-filters.html">Market Filters</a>.</p>
+
+<p>You can also use the multiple APK feature to distribute different {@code .apk} files under the same
+application listing and the same package name; however, you should use this option only as a last
+resort. Android applications usually run on most compatible devices with a single APK, by supplying
+alternative resources for different configurations (for example, different layouts for different screen
+sizes) and the Android system selects the appropriate resources for the device at runtime. In a
+few cases, however, a single APK is unable to support all device configurations, because alternative
+resources make the APK file too big (greater than 50MB) or other technical challenges prevent a
+single APK from working on all devices. Although we encourage you to develop and publish a single
+APK that supports as many device configurations as possible, doing so is sometimes
+not possible. To help you publish your application for as many devices as possible, Android Market
+allows you to publish multiple APKs under the same application listing. Android Market then supplies
+each APK to the appropriate devices based on configuration support you've declared in the manifest
+file of each APK. To use this feature, you need to build your separate {@code .apk} files when you are <a
+href="{@docRoot}guide/publishing/preparing.html">preparing your app for release</a> (that is, before
+you upload your app to Android Market). For more information, see <a
+href="{@docRoot}guide/market/publishing/multiple-apks.html">Multiple APK Support</a>.</p>
 
 <h2 id="marketupgrade">Publishing Updates on Android Market</h2>
 
@@ -128,6 +232,9 @@
 consider it a new application, publish it as such, and will not offer it to existing users as an
 update.</p>
 
+<p>If you plan to publish your application on Android Market, you must make sure
+  that it meets the requirements listed below, which are enforced by the Market
+  server when you upload the application.</p>
 
 <h2 id="marketLicensing">Using Android Market Licensing Service</h2>
 
@@ -136,7 +243,7 @@
 Android Market Licensing, your applications can query Android Market at runtime
 to obtain the licensing status for the current user, then allow or disallow
 further use of the application as appropriate. Using the service, you can apply a flexible
-licensing policy on an application-by-application basis&mdash;each 
+licensing policy on an application-by-application basis&mdash;each
 application can enforce its licensing status in the way most appropriate
 for it. </p>
 
@@ -149,7 +256,31 @@
 use it in your application, read <a
 href="{@docRoot}guide/publishing/licensing.html">Application Licensing</a>.</p>
 
+<h2 id="marketinappbilling">Using Android Market In-app Billing</h2>
 
+<p><a href="{@docRoot}guide/market/billing/billing_overview.html">Android Market In-app Billing</a>
+is an Android Market service that lets you sell digital content in your applications. You can use
+the service to sell a wide range of content, including downloadable  content such as media files or
+photos, and virtual content such as game levels or potions.</p>
+
+<p>When you use Android Market's in-app billing service to sell an item, Android Market handles all
+billing details so your application never has to directly process any financial transactions.
+Android Market uses the same checkout service that is used for application purchases, so your users
+experience a consistent and familiar purchase flow (see figure 1). Also, the transaction fee for
+in-app purchases is the same as the transaction fee for application purchases (30%).</p>
+
+<p>Any application that you publish through Android Market can implement in-app billing. No special
+account or registration is required other than an Android Market publisher account and a Google
+Checkout Merchant account. Also, because the service uses no dedicated framework APIs, you can add
+in-app billing to any application that uses a minimum API level of 4 or higher.</p>
+
+<p>To help you integrate in-app billing into your application, the Android SDK provides a <a
+href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample application</a>
+that demonstrates a simple implementation of in-app billing. The sample application contains
+examples of billing-related classes you can use to implement in-app billing in your application. It
+also contains examples of the database, user interface, and business logic you might use to
+implement in-app billing. For more information about the in-app billing feature, see the
+<a href="{@docRoot}guide/market/billing/index.html">In-app Billing documentation</a>.</p>
 
 <h2 id="marketintent">Linking to Your Apps on Android Market</h2>
 
@@ -337,7 +468,7 @@
 Guidelines</a>.</p>
 
 <style type="text/css">
-  
+
 form.button-form {
   margin-top:2em;
 }
@@ -539,7 +670,7 @@
 
 <tr>
 <td>Display the details screen for a specific application</td>
-<td><code>http://market.android.com/details?id=&lt;package_name&gt;</code> 
+<td><code>http://market.android.com/details?id=&lt;package_name&gt;</code>
 <td><code>market://details?id=&lt;package_name&gt;</code></td>
 </tr>
 
diff --git a/docs/html/guide/publishing/publishing_overview.jd b/docs/html/guide/publishing/publishing_overview.jd
index e30360b..79199c5 100755
--- a/docs/html/guide/publishing/publishing_overview.jd
+++ b/docs/html/guide/publishing/publishing_overview.jd
@@ -134,7 +134,7 @@
 and features, coupled with numerous end-user community features, makes Android Market the premier
 marketplace for selling and buying Android applications.</p>
 
-<p>Releasing your application on Android Market is a simple process that involves four basic
+<p>Releasing your application on Android Market is a simple process that involves three basic
   steps:</p>
 
 <div class="figure" style="width:275px">
@@ -153,21 +153,16 @@
     create promotional materials for your application, such as screenshots, videos, graphics, and
     promotional text.</p>
   </li>
-  <li>Planning publishing options.
+  <li>Configuring options and uploading assets.
     <p>Android Market lets you target your application to a worldwide pool of users and devices.
-    Using various Android Market tools, you can choose the countries you want to reach, the
-    price you want to charge in each country, and the devices you want to target. You can also
-    use Android Market's filtering settings to target specific device features and capabilities.</p>
-  </li>
-  <li>Configuring publishing options and uploading assets.
-    <p>After you create your promotional materials and determine which publishing options are
-    suitable for your application, you can use the Android Market developer console to configure
-    those options and upload the promotional materials. You can also use the developer console to
-    upload your application as a draft (unpublished) application, which lets you do final
-    testing before you publish it for final release.</p>
+    By configuring various Android Market settings, you can choose the countries you want to
+    reach, the listing languages you want to use, and the price you want to charge in each
+    country. You can also configure listing details such as the application type, category, and
+    content rating. When you are done configuring options you can upload your promotional materials
+    and your application as a draft (unpublished) application.</p>
   </li>
   <li>Publishing the release version of your application.
-    <p>When you are satisfied that your publishing settings are correctly configured and your
+    <p>If you are satisfied that your publishing settings are correctly configured and your
     uploaded application is ready to be released to the public, you can simply click
     <strong>Publish</strong > in the developer console and within minutes your application will be
     live and available for download around the world.</p>
@@ -233,4 +228,4 @@
 <p>Releasing applications through email is convenient if you are sending your application to
 only a few trusted users, but it provides few protections from piracy and unauthorized
 distribution; that is, anyone you send your application to can simply forward it to someone else.
-else.
\ No newline at end of file
+else.
diff --git a/docs/html/images/publishing/publishing_android_market.png b/docs/html/images/publishing/publishing_android_market.png
new file mode 100755
index 0000000..aa591ef
--- /dev/null
+++ b/docs/html/images/publishing/publishing_android_market.png
Binary files differ
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 774495a..bb0ac3e 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -51,7 +51,6 @@
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.os.WorkSource;
-import android.provider.Settings.SettingNotFoundException;
 import android.provider.Settings;
 import android.util.EventLog;
 import android.util.Log;
@@ -60,6 +59,7 @@
 import static android.provider.Settings.System.DIM_SCREEN;
 import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
+import static android.provider.Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ;
 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
 import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN;
@@ -106,6 +106,14 @@
     // light sensor events rate in microseconds
     private static final int LIGHT_SENSOR_RATE = 1000000;
 
+    // Expansion of range of light values when applying scale from light
+    // sensor brightness setting, in the [0..255] brightness range.
+    private static final int LIGHT_SENSOR_RANGE_EXPANSION = 20;
+
+    // Scaling factor of the light sensor brightness setting when applying
+    // it to the final brightness.
+    private static final int LIGHT_SENSOR_OFFSET_SCALE = 8;
+
     // For debouncing the proximity sensor in milliseconds
     private static final int PROXIMITY_SENSOR_DELAY = 1000;
 
@@ -118,6 +126,9 @@
     // Default timeout for screen off, if not found in settings database = 15 seconds.
     private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15000;
 
+    // Screen brightness should always have a value, but just in case...
+    private static final int DEFAULT_SCREEN_BRIGHTNESS = 192;
+
     // flags for setPowerState
     private static final int SCREEN_ON_BIT          = 0x00000001;
     private static final int SCREEN_BRIGHT_BIT      = 0x00000002;
@@ -150,6 +161,8 @@
     static final int ANIM_STEPS = 60/4;
     // Slower animation for autobrightness changes
     static final int AUTOBRIGHTNESS_ANIM_STEPS = 60;
+    // Number of steps when performing a more immediate brightness change.
+    static final int IMMEDIATE_ANIM_STEPS = 4;
 
     // These magic numbers are the initial state of the LEDs at boot.  Ideally
     // we should read them from the driver, but our current hardware returns 0
@@ -227,6 +240,7 @@
     private boolean mLightSensorPendingDecrease = false;
     private boolean mLightSensorPendingIncrease = false;
     private float mLightSensorPendingValue = -1;
+    private float mLightSensorAdjustSetting = 0;
     private int mLightSensorScreenBrightness = -1;
     private int mLightSensorButtonBrightness = -1;
     private int mLightSensorKeyboardBrightness = -1;
@@ -240,6 +254,7 @@
     // mLastScreenOnTime is the time the screen was last turned on
     private long mLastScreenOnTime;
     private boolean mPreventScreenOn;
+    private int mScreenBrightnessSetting = DEFAULT_SCREEN_BRIGHTNESS;
     private int mScreenBrightnessOverride = -1;
     private int mButtonBrightnessOverride = -1;
     private int mScreenBrightnessDim;
@@ -460,6 +475,9 @@
                 // DIM_SCREEN
                 //mDimScreen = getInt(DIM_SCREEN) != 0;
 
+                mScreenBrightnessSetting = getInt(SCREEN_BRIGHTNESS, DEFAULT_SCREEN_BRIGHTNESS);
+                mLightSensorAdjustSetting = getFloat(SCREEN_AUTO_BRIGHTNESS_ADJ, 0);
+
                 // SCREEN_BRIGHTNESS_MODE, default to manual
                 setScreenBrightnessMode(getInt(SCREEN_BRIGHTNESS_MODE,
                         Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL));
@@ -624,9 +642,12 @@
                         + Settings.System.NAME + "=?) or ("
                         + Settings.System.NAME + "=?) or ("
                         + Settings.System.NAME + "=?) or ("
+                        + Settings.System.NAME + "=?) or ("
+                        + Settings.System.NAME + "=?) or ("
                         + Settings.System.NAME + "=?)",
-                new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN,
-                        SCREEN_BRIGHTNESS_MODE, WINDOW_ANIMATION_SCALE, TRANSITION_ANIMATION_SCALE},
+                new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN, SCREEN_BRIGHTNESS,
+                        SCREEN_BRIGHTNESS_MODE, SCREEN_AUTO_BRIGHTNESS_ADJ,
+                        WINDOW_ANIMATION_SCALE, TRANSITION_ANIMATION_SCALE},
                 null);
         mSettings = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, mHandler);
         SettingsObserver settingsObserver = new SettingsObserver();
@@ -1163,7 +1184,8 @@
             pw.println("  mProximitySensorActive=" + mProximitySensorActive);
             pw.println("  mProximityPendingValue=" + mProximityPendingValue);
             pw.println("  mLastProximityEventTime=" + mLastProximityEventTime);
-            pw.println("  mLightSensorEnabled=" + mLightSensorEnabled);
+            pw.println("  mLightSensorEnabled=" + mLightSensorEnabled
+                    + " mLightSensorAdjustSetting=" + mLightSensorAdjustSetting);
             pw.println("  mLightSensorValue=" + mLightSensorValue
                     + " mLightSensorPendingValue=" + mLightSensorPendingValue);
             pw.println("  mLightSensorPendingDecrease=" + mLightSensorPendingDecrease
@@ -2230,20 +2252,15 @@
     }
 
     private int getPreferredBrightness() {
-        try {
-            if (mScreenBrightnessOverride >= 0) {
-                return mScreenBrightnessOverride;
-            } else if (mLightSensorScreenBrightness >= 0 && mUseSoftwareAutoBrightness
-                    && mAutoBrightessEnabled) {
-                return mLightSensorScreenBrightness;
-            }
-            final int brightness = Settings.System.getInt(mContext.getContentResolver(),
-                                                          SCREEN_BRIGHTNESS);
-             // Don't let applications turn the screen all the way off
-            return Math.max(brightness, mScreenBrightnessDim);
-        } catch (SettingNotFoundException snfe) {
-            return Power.BRIGHTNESS_ON;
+        if (mScreenBrightnessOverride >= 0) {
+            return mScreenBrightnessOverride;
+        } else if (mLightSensorScreenBrightness >= 0 && mUseSoftwareAutoBrightness
+                && mAutoBrightessEnabled) {
+            return mLightSensorScreenBrightness;
         }
+        final int brightness = mScreenBrightnessSetting;
+         // Don't let applications turn the screen all the way off
+        return Math.max(brightness, mScreenBrightnessDim);
     }
 
     private int applyButtonState(int state) {
@@ -2439,7 +2456,34 @@
                     break;
                 }
             }
-            return values[i];
+            // This is the range of brightness values that we can use.
+            final int minval = values[0];
+            final int maxval = values[mAutoBrightnessLevels.length];
+            // This is the range we will be scaling.  We put some padding
+            // at the low and high end to give the adjustment a little better
+            // impact on the actual observed value.
+            final int range = (maxval-minval) + LIGHT_SENSOR_RANGE_EXPANSION;
+            // This is the desired brightness value from 0.0 to 1.0.
+            float valf = ((values[i]-minval+(LIGHT_SENSOR_RANGE_EXPANSION/2))/(float)range);
+            // Apply a scaling to the value based on the adjustment.
+            if (mLightSensorAdjustSetting > 0 && mLightSensorAdjustSetting <= 1) {
+                float adj = (float)Math.sqrt(1.0f-mLightSensorAdjustSetting);
+                if (adj <= .00001) {
+                    valf = 1;
+                } else {
+                    valf /= adj;
+                }
+            } else if (mLightSensorAdjustSetting < 0 && mLightSensorAdjustSetting >= -1) {
+                float adj = (float)Math.sqrt(1.0f+mLightSensorAdjustSetting);
+                valf *= adj;
+            }
+            // Apply an additional offset to the value based on the adjustment.
+            valf += mLightSensorAdjustSetting/LIGHT_SENSOR_OFFSET_SCALE;
+            // Convert the 0.0-1.0 value back to a brightness integer.
+            int val = (int)((valf*range)+minval) - (LIGHT_SENSOR_RANGE_EXPANSION/2);
+            if (val < minval) val = minval;
+            else if (val > maxval) val = maxval;
+            return val;
         } catch (Exception e) {
             // guard against null pointer or index out of bounds errors
             Slog.e(TAG, "getAutoBrightnessValue", e);
@@ -2468,7 +2512,7 @@
                     int value = (int)mLightSensorPendingValue;
                     mLightSensorPendingDecrease = false;
                     mLightSensorPendingIncrease = false;
-                    lightSensorChangedLocked(value);
+                    lightSensorChangedLocked(value, false);
                 }
             }
         }
@@ -2485,12 +2529,12 @@
                 // force lights recalculation
                 int value = (int)mLightSensorValue;
                 mLightSensorValue = -1;
-                lightSensorChangedLocked(value);
+                lightSensorChangedLocked(value, false);
             }
         }
     }
 
-    private void lightSensorChangedLocked(int value) {
+    private void lightSensorChangedLocked(int value, boolean immediate) {
         if (mDebugLightSensor) {
             Slog.d(TAG, "lightSensorChangedLocked " + value);
         }
@@ -2536,7 +2580,8 @@
 
                 if (mAutoBrightessEnabled && mScreenBrightnessOverride < 0) {
                     if (!mSkippedScreenOn) {
-                        mScreenBrightness.setTargetLocked(lcdValue, AUTOBRIGHTNESS_ANIM_STEPS,
+                        mScreenBrightness.setTargetLocked(lcdValue,
+                                immediate ? IMMEDIATE_ANIM_STEPS : AUTOBRIGHTNESS_ANIM_STEPS,
                                 INITIAL_SCREEN_BRIGHTNESS, (int)mScreenBrightness.curValue);
                     }
                 }
@@ -2684,7 +2729,7 @@
                         if (mLightSensorValue >= 0) {
                             int value = (int)mLightSensorValue;
                             mLightSensorValue = -1;
-                            lightSensorChangedLocked(value);
+                            lightSensorChangedLocked(value, false);
                         }
                     }
                     userActivity(SystemClock.uptimeMillis(), false, BUTTON_EVENT, true);
@@ -2944,10 +2989,28 @@
                 Binder.restoreCallingIdentity(identity);
             }
 
-            // update our animation state
-            synchronized (mLocks) {
-                mScreenBrightness.targetValue = brightness;
-                mScreenBrightness.jumpToTargetLocked();
+            mScreenBrightness.targetValue = brightness;
+            mScreenBrightness.jumpToTargetLocked();
+        }
+    }
+
+    public void setAutoBrightnessAdjustment(float adj) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
+        synchronized (mLocks) {
+            mLightSensorAdjustSetting = adj;
+            if (mSensorManager != null && mLightSensorEnabled) {
+                // clear calling identity so sensor manager battery stats are accurate
+                long identity = Binder.clearCallingIdentity();
+                try {
+                    // force recompute of backlight values
+                    if (mLightSensorValue >= 0) {
+                        int value = (int)mLightSensorValue;
+                        mLightSensorValue = -1;
+                        handleLightSensorValue(value, true);
+                    }
+                } finally {
+                    Binder.restoreCallingIdentity(identity);
+                }
             }
         }
     }
@@ -3062,7 +3125,7 @@
                     if (mLightSensorValue >= 0) {
                         int value = (int)mLightSensorValue;
                         mLightSensorValue = -1;
-                        handleLightSensorValue(value);
+                        handleLightSensorValue(value, true);
                     }
                     mSensorManager.registerListener(mLightListener, mLightSensor,
                             LIGHT_SENSOR_RATE);
@@ -3122,7 +3185,7 @@
         }
     };
 
-    private void handleLightSensorValue(int value) {
+    private void handleLightSensorValue(int value, boolean immediate) {
         long milliseconds = SystemClock.elapsedRealtime();
         if (mLightSensorValue == -1 ||
                 milliseconds < mLastScreenOnTime + mLightSensorWarmupTime) {
@@ -3130,7 +3193,7 @@
             mHandler.removeCallbacks(mAutoBrightnessTask);
             mLightSensorPendingDecrease = false;
             mLightSensorPendingIncrease = false;
-            lightSensorChangedLocked(value);
+            lightSensorChangedLocked(value, immediate);
         } else {
             if ((value > mLightSensorValue && mLightSensorPendingDecrease) ||
                     (value < mLightSensorValue && mLightSensorPendingIncrease) ||
@@ -3160,7 +3223,7 @@
                 if (isScreenTurningOffLocked()) {
                     return;
                 }
-                handleLightSensorValue((int)event.values[0]);
+                handleLightSensorValue((int)event.values[0], false);
             }
         }
 
diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/java/com/android/server/wm/ScreenRotationAnimation.java
index 8fc9a70..55fb038 100644
--- a/services/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -17,13 +17,8 @@
 package com.android.server.wm;
 
 import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
 import android.graphics.Matrix;
-import android.graphics.Paint;
 import android.graphics.PixelFormat;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
 import android.graphics.Rect;
 import android.util.Slog;
 import android.view.Surface;
@@ -34,7 +29,8 @@
 
 class ScreenRotationAnimation {
     static final String TAG = "ScreenRotationAnimation";
-    static final boolean DEBUG = false;
+    static final boolean DEBUG_STATE = false;
+    static final boolean DEBUG_TRANSFORMS = false;
 
     static final int FREEZE_LAYER = WindowManagerService.TYPE_LAYER_MULTIPLIER * 200;
 
@@ -49,11 +45,51 @@
     int mOriginalWidth, mOriginalHeight;
     int mCurRotation;
 
-    Animation mExitAnimation;
+    // For all animations, "exit" is for the UI elements that are going
+    // away (that is the snapshot of the old screen), and "enter" is for
+    // the new UI elements that are appearing (that is the active windows
+    // in their final orientation).
+
+    // The starting animation for the exiting and entering elements.  This
+    // animation applies a transformation while the rotation is in progress.
+    // It is started immediately, before the new entering UI is ready.
+    Animation mStartExitAnimation;
+    final Transformation mStartExitTransformation = new Transformation();
+    Animation mStartEnterAnimation;
+    final Transformation mStartEnterTransformation = new Transformation();
+
+    // The finishing animation for the exiting and entering elements.  This
+    // animation needs to undo the transformation of the starting animation.
+    // It starts running once the new rotation UI elements are ready to be
+    // displayed.
+    Animation mFinishExitAnimation;
+    final Transformation mFinishExitTransformation = new Transformation();
+    Animation mFinishEnterAnimation;
+    final Transformation mFinishEnterTransformation = new Transformation();
+
+    // The current active animation to move from the old to the new rotated
+    // state.  Which animation is run here will depend on the old and new
+    // rotations.
+    Animation mRotateExitAnimation;
+    final Transformation mRotateExitTransformation = new Transformation();
+    Animation mRotateEnterAnimation;
+    final Transformation mRotateEnterTransformation = new Transformation();
+
+    // A previously running rotate animation.  This will be used if we need
+    // to switch to a new rotation before finishing the previous one.
+    Animation mLastRotateExitAnimation;
+    final Transformation mLastRotateExitTransformation = new Transformation();
+    Animation mLastRotateEnterAnimation;
+    final Transformation mLastRotateEnterTransformation = new Transformation();
+
+    // Complete transformations being applied.
     final Transformation mExitTransformation = new Transformation();
-    Animation mEnterAnimation;
     final Transformation mEnterTransformation = new Transformation();
+
     boolean mStarted;
+    boolean mAnimRunning;
+    boolean mFinishAnimReady;
+    long mFinishAnimStartTime;
 
     final Matrix mSnapshotInitialMatrix = new Matrix();
     final Matrix mSnapshotFinalMatrix = new Matrix();
@@ -133,7 +169,7 @@
                     mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
                     mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
             mSurface.setAlpha(alpha);
-            if (DEBUG) {
+            if (DEBUG_TRANSFORMS) {
                 float[] srcPnts = new float[] { 0, 0, mWidth, mHeight };
                 float[] dstPnts = new float[4];
                 matrix.mapPoints(dstPnts, srcPnts);
@@ -167,7 +203,7 @@
     }
 
     // Must be called while in a transaction.
-    public void setRotation(int rotation) {
+    private void setRotation(int rotation) {
         mCurRotation = rotation;
 
         // Compute the transformation matrix that must be applied
@@ -176,46 +212,78 @@
         int delta = deltaRotation(rotation, mSnapshotRotation);
         createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
 
-        if (DEBUG) Slog.v(TAG, "**** ROTATION: " + delta);
+        if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
         setSnapshotTransform(mSnapshotInitialMatrix, 1.0f);
     }
 
+    // Must be called while in a transaction.
+    public boolean setRotation(int rotation, SurfaceSession session,
+            long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
+        setRotation(rotation);
+        return startAnimation(session, maxAnimationDuration, animationScale,
+                finalWidth, finalHeight, false);
+    }
+
     /**
      * Returns true if animating.
      */
-    public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
-            float animationScale, int finalWidth, int finalHeight) {
+    private boolean startAnimation(SurfaceSession session, long maxAnimationDuration,
+            float animationScale, int finalWidth, int finalHeight, boolean dismissing) {
         if (mSurface == null) {
             // Can't do animation.
             return false;
         }
+        if (mStarted) {
+            return true;
+        }
+
+        mStarted = true;
+
+        boolean firstStart = false;
 
         // Figure out how the screen has moved from the original rotation.
         int delta = deltaRotation(mCurRotation, mOriginalRotation);
 
+        if (mFinishExitAnimation == null && (!dismissing || delta != Surface.ROTATION_0)) {
+            if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations");
+            firstStart = true;
+            mStartExitAnimation = AnimationUtils.loadAnimation(mContext,
+                    com.android.internal.R.anim.screen_rotate_start_exit);
+            mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
+                    com.android.internal.R.anim.screen_rotate_start_enter);
+            mFinishExitAnimation = AnimationUtils.loadAnimation(mContext,
+                    com.android.internal.R.anim.screen_rotate_finish_exit);
+            mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext,
+                    com.android.internal.R.anim.screen_rotate_finish_enter);
+        }
+
+        if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
+                + finalWidth + " finalHeight=" + finalHeight
+                + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
+
         switch (delta) {
             case Surface.ROTATION_0:
-                mExitAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_0_exit);
-                mEnterAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_0_enter);
                 break;
             case Surface.ROTATION_90:
-                mExitAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_plus_90_exit);
-                mEnterAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_plus_90_enter);
                 break;
             case Surface.ROTATION_180:
-                mExitAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_180_exit);
-                mEnterAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_180_enter);
                 break;
             case Surface.ROTATION_270:
-                mExitAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_minus_90_exit);
-                mEnterAnimation = AnimationUtils.loadAnimation(mContext,
+                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_minus_90_enter);
                 break;
         }
@@ -224,35 +292,85 @@
         // means to allow supplying the last and next size.  In this definition
         // "%p" is the original (let's call it "previous") size, and "%" is the
         // screen's current/new size.
-        mEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
-        mExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
-        mStarted = false;
+        if (firstStart) {
+            if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
+            mStartEnterAnimation.initialize(finalWidth, finalHeight,
+                    mOriginalWidth, mOriginalHeight);
+            mStartExitAnimation.initialize(finalWidth, finalHeight,
+                    mOriginalWidth, mOriginalHeight);
+            mFinishEnterAnimation.initialize(finalWidth, finalHeight,
+                    mOriginalWidth, mOriginalHeight);
+            mFinishExitAnimation.initialize(finalWidth, finalHeight,
+                    mOriginalWidth, mOriginalHeight);
+        }
+        mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
+        mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
+        mAnimRunning = false;
+        mFinishAnimReady = false;
+        mFinishAnimStartTime = -1;
 
-        mExitAnimation.restrictDuration(maxAnimationDuration);
-        mExitAnimation.scaleCurrentDuration(animationScale);
-        mEnterAnimation.restrictDuration(maxAnimationDuration);
-        mEnterAnimation.scaleCurrentDuration(animationScale);
+        if (firstStart) {
+            mStartExitAnimation.restrictDuration(maxAnimationDuration);
+            mStartExitAnimation.scaleCurrentDuration(animationScale);
+            mStartEnterAnimation.restrictDuration(maxAnimationDuration);
+            mStartEnterAnimation.scaleCurrentDuration(animationScale);
+            mFinishExitAnimation.restrictDuration(maxAnimationDuration);
+            mFinishExitAnimation.scaleCurrentDuration(animationScale);
+            mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
+            mFinishEnterAnimation.scaleCurrentDuration(animationScale);
+        }
+        mRotateExitAnimation.restrictDuration(maxAnimationDuration);
+        mRotateExitAnimation.scaleCurrentDuration(animationScale);
+        mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
+        mRotateEnterAnimation.scaleCurrentDuration(animationScale);
 
-        if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
-                ">>> OPEN TRANSACTION ScreenRotationAnimation.dismiss");
-        Surface.openTransaction();
+        if (mBlackFrame == null) {
+            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
+                    WindowManagerService.TAG,
+                    ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
+            Surface.openTransaction();
 
-        try {
-            Rect outer = new Rect(-finalWidth, -finalHeight, finalWidth * 2, finalHeight * 2);
-            Rect inner = new Rect(0, 0, finalWidth, finalHeight);
-            mBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER);
-        } catch (Surface.OutOfResourcesException e) {
-            Slog.w(TAG, "Unable to allocate black surface", e);
-        } finally {
-            Surface.closeTransaction();
-            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
-                    "<<< CLOSE TRANSACTION ScreenRotationAnimation.dismiss");
+            try {
+                Rect outer = new Rect(-finalWidth*1, -finalHeight*1, finalWidth*2, finalHeight*2);
+                Rect inner = new Rect(0, 0, finalWidth, finalHeight);
+                mBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER);
+            } catch (Surface.OutOfResourcesException e) {
+                Slog.w(TAG, "Unable to allocate black surface", e);
+            } finally {
+                Surface.closeTransaction();
+                if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
+                        WindowManagerService.TAG,
+                        "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
+            }
         }
 
         return true;
     }
 
+    /**
+     * Returns true if animating.
+     */
+    public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
+            float animationScale, int finalWidth, int finalHeight) {
+        if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
+        if (mSurface == null) {
+            // Can't do animation.
+            return false;
+        }
+        if (!mStarted) {
+            startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight,
+                    true);
+        }
+        if (!mStarted) {
+            return false;
+        }
+        if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true");
+        mFinishAnimReady = true;
+        return true;
+    }
+
     public void kill() {
+        if (DEBUG_STATE) Slog.v(TAG, "Kill!");
         if (mSurface != null) {
             if (WindowManagerService.SHOW_TRANSACTIONS ||
                     WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
@@ -262,74 +380,198 @@
         }
         if (mBlackFrame != null) {
             mBlackFrame.kill();
+            mBlackFrame = null;
         }
-        if (mExitAnimation != null) {
-            mExitAnimation.cancel();
-            mExitAnimation = null;
+        if (mStartExitAnimation != null) {
+            mStartExitAnimation.cancel();
+            mStartExitAnimation = null;
         }
-        if (mEnterAnimation != null) {
-            mEnterAnimation.cancel();
-            mEnterAnimation = null;
+        if (mStartEnterAnimation != null) {
+            mStartEnterAnimation.cancel();
+            mStartEnterAnimation = null;
+        }
+        if (mFinishExitAnimation != null) {
+            mFinishExitAnimation.cancel();
+            mFinishExitAnimation = null;
+        }
+        if (mStartEnterAnimation != null) {
+            mStartEnterAnimation.cancel();
+            mStartEnterAnimation = null;
+        }
+        if (mRotateExitAnimation != null) {
+            mRotateExitAnimation.cancel();
+            mRotateExitAnimation = null;
+        }
+        if (mRotateEnterAnimation != null) {
+            mRotateEnterAnimation.cancel();
+            mRotateEnterAnimation = null;
         }
     }
 
     public boolean isAnimating() {
-        return mEnterAnimation != null || mExitAnimation != null;
+        return mStartEnterAnimation != null || mStartExitAnimation != null
+                && mFinishEnterAnimation != null || mFinishExitAnimation != null
+                && mRotateEnterAnimation != null || mRotateExitAnimation != null;
     }
 
     public boolean stepAnimation(long now) {
-        if (mEnterAnimation == null && mExitAnimation == null) {
+        if (!isAnimating()) {
+            if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
             return false;
         }
 
-        if (!mStarted) {
-            if (mEnterAnimation != null) {
-                mEnterAnimation.setStartTime(now);
+        if (!mAnimRunning) {
+            if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
+            if (mStartEnterAnimation != null) {
+                mStartEnterAnimation.setStartTime(now);
             }
-            if (mExitAnimation != null) {
-                mExitAnimation.setStartTime(now);
+            if (mStartExitAnimation != null) {
+                mStartExitAnimation.setStartTime(now);
             }
-            mStarted = true;
+            if (mFinishEnterAnimation != null) {
+                mFinishEnterAnimation.setStartTime(0);
+            }
+            if (mFinishExitAnimation != null) {
+                mFinishExitAnimation.setStartTime(0);
+            }
+            if (mRotateEnterAnimation != null) {
+                mRotateEnterAnimation.setStartTime(now);
+            }
+            if (mRotateExitAnimation != null) {
+                mRotateExitAnimation.setStartTime(now);
+            }
+            mAnimRunning = true;
         }
 
-        mExitTransformation.clear();
-        boolean moreExit = false;
-        if (mExitAnimation != null) {
-            moreExit = mExitAnimation.getTransformation(now, mExitTransformation);
-            if (DEBUG) Slog.v(TAG, "Stepped exit: " + mExitTransformation);
-            if (!moreExit) {
-                if (DEBUG) Slog.v(TAG, "Exit animation done!");
-                mExitAnimation.cancel();
-                mExitAnimation = null;
-                mExitTransformation.clear();
-                if (mSurface != null) {
-                    mSurface.hide();
-                }
+        if (mFinishAnimReady && mFinishAnimStartTime < 0) {
+            if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
+            mFinishAnimStartTime = now;
+        }
+
+        // If the start animation is no longer running, we want to keep its
+        // transformation intact until the finish animation also completes.
+
+        boolean moreStartExit = false;
+        if (mStartExitAnimation != null) {
+            mStartExitTransformation.clear();
+            moreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
+            if (!moreStartExit) {
+                if (DEBUG_STATE) Slog.v(TAG, "Start exit animation done!");
+                mStartExitAnimation.cancel();
+                mStartExitAnimation = null;
             }
         }
 
-        mEnterTransformation.clear();
-        boolean moreEnter = false;
-        if (mEnterAnimation != null) {
-            moreEnter = mEnterAnimation.getTransformation(now, mEnterTransformation);
-            if (!moreEnter) {
-                mEnterAnimation.cancel();
-                mEnterAnimation = null;
-                mEnterTransformation.clear();
-                if (mBlackFrame != null) {
-                    mBlackFrame.hide();
-                }
-            } else {
-                if (mBlackFrame != null) {
-                    mBlackFrame.setMatrix(mEnterTransformation.getMatrix());
-                }
+        boolean moreStartEnter = false;
+        if (mStartEnterAnimation != null) {
+            mStartEnterTransformation.clear();
+            moreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
+            if (!moreStartEnter) {
+                if (DEBUG_STATE) Slog.v(TAG, "Start enter animation done!");
+                mStartEnterAnimation.cancel();
+                mStartEnterAnimation = null;
+            }
+        }
+
+        long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
+        if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
+
+        mFinishExitTransformation.clear();
+        boolean moreFinishExit = false;
+        if (mFinishExitAnimation != null) {
+            moreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
+            if (!moreStartExit && !moreFinishExit) {
+                if (DEBUG_STATE) Slog.v(TAG, "Finish exit animation done, clearing start/finish anims!");
+                mStartExitTransformation.clear();
+                mFinishExitAnimation.cancel();
+                mFinishExitAnimation = null;
+                mFinishExitTransformation.clear();
+            }
+        }
+
+        mFinishEnterTransformation.clear();
+        boolean moreFinishEnter = false;
+        if (mFinishEnterAnimation != null) {
+            moreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
+            if (!moreStartEnter && !moreFinishEnter) {
+                if (DEBUG_STATE) Slog.v(TAG, "Finish enter animation done, clearing start/finish anims!");
+                mStartEnterTransformation.clear();
+                mFinishEnterAnimation.cancel();
+                mFinishEnterAnimation = null;
+                mFinishEnterTransformation.clear();
+            }
+        }
+
+        mRotateExitTransformation.clear();
+        boolean moreRotateExit = false;
+        if (mRotateExitAnimation != null) {
+            moreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
+        }
+
+        if (!moreFinishExit && !moreRotateExit) {
+            if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
+            mRotateExitAnimation.cancel();
+            mRotateExitAnimation = null;
+            mRotateExitTransformation.clear();
+        }
+
+        mRotateEnterTransformation.clear();
+        boolean moreRotateEnter = false;
+        if (mRotateEnterAnimation != null) {
+            moreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
+        }
+
+        if (!moreFinishEnter && !moreRotateEnter) {
+            if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
+            mRotateEnterAnimation.cancel();
+            mRotateEnterAnimation = null;
+            mRotateEnterTransformation.clear();
+        }
+
+        mExitTransformation.set(mRotateExitTransformation);
+        mExitTransformation.compose(mStartExitTransformation);
+        mExitTransformation.compose(mFinishExitTransformation);
+
+        mEnterTransformation.set(mRotateEnterTransformation);
+        mEnterTransformation.compose(mStartEnterTransformation);
+        mEnterTransformation.compose(mFinishEnterTransformation);
+
+        if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
+        if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
+
+        if (!moreStartExit && !moreFinishExit && !moreRotateExit) {
+            if (mSurface != null) {
+                if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
+                mSurface.hide();
+            }
+        }
+
+        if (!moreStartEnter && !moreFinishEnter && !moreRotateEnter) {
+            if (mBlackFrame != null) {
+                if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, hiding black frame");
+                mBlackFrame.hide();
+            }
+        } else {
+            if (mBlackFrame != null) {
+                mBlackFrame.setMatrix(mEnterTransformation.getMatrix());
             }
         }
 
         mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
         setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
 
-        return moreEnter || moreExit;
+        final boolean more = moreStartEnter || moreStartExit || moreFinishEnter || moreFinishExit
+                || moreRotateEnter || moreRotateExit || !mFinishAnimReady;
+
+        if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
+
+        return more;
     }
 
     public Transformation getEnterTransformation() {
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index a702ce8..24b6064 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -733,7 +733,7 @@
             //Looper.myLooper().setMessageLogging(new LogPrinter(
             //        Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
             android.os.Process.setThreadPriority(
-                    android.os.Process.THREAD_PRIORITY_DISPLAY);
+                    android.os.Process.THREAD_PRIORITY_FOREGROUND);
             android.os.Process.setCanSelfBackground(false);
             mPolicy.init(mContext, mService, mService, mPM);
 
@@ -3446,7 +3446,7 @@
             // the value of the previous configuration.
             mTempConfiguration.setToDefaults();
             mTempConfiguration.fontScale = currentConfig.fontScale;
-            if (computeNewConfigurationLocked(mTempConfiguration)) {
+            if (computeScreenConfigurationLocked(mTempConfiguration)) {
                 if (currentConfig.diff(mTempConfiguration) != 0) {
                     mWaitingForConfig = true;
                     mLayoutNeeded = true;
@@ -5362,6 +5362,14 @@
         startFreezingDisplayLocked(inTransaction);
         mInputManager.setDisplayOrientation(0, rotation);
 
+        // We need to update our screen size information to match the new
+        // rotation.  Note that this is redundant with the later call to
+        // sendNewConfiguration() that must be called after this function
+        // returns...  however we need to do the screen size part of that
+        // before then so we have the correct size to use when initializiation
+        // the rotation animation for the new rotation.
+        computeScreenConfigurationLocked(null);
+
         if (!inTransaction) {
             if (SHOW_TRANSACTIONS)  Slog.i(TAG,
                     ">>> OPEN TRANSACTION setRotationUnchecked");
@@ -5372,7 +5380,11 @@
             //       it doesn't support hardware OpenGL emulation yet.
             if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
                     && mScreenRotationAnimation.hasScreenshot()) {
-                mScreenRotationAnimation.setRotation(rotation);
+                if (mScreenRotationAnimation.setRotation(rotation, mFxSession,
+                        MAX_ANIMATION_DURATION, mTransitionAnimationScale,
+                        mCurDisplayWidth, mCurDisplayHeight)) {
+                    requestAnimationLocked(0);
+                }
             }
             Surface.setOrientation(0, rotation);
         } finally {
@@ -5860,7 +5872,7 @@
     Configuration computeNewConfigurationLocked() {
         Configuration config = new Configuration();
         config.fontScale = 0;
-        if (!computeNewConfigurationLocked(config)) {
+        if (!computeScreenConfigurationLocked(config)) {
             return null;
         }
         return config;
@@ -6011,12 +6023,10 @@
         return sw;
     }
 
-    boolean computeNewConfigurationLocked(Configuration config) {
+    boolean computeScreenConfigurationLocked(Configuration config) {
         if (mDisplay == null) {
             return false;
         }
-        
-        mInputManager.getInputConfiguration(config);
 
         // Use the effective "visual" dimensions based on current rotation
         final boolean rotated = (mRotation == Surface.ROTATION_90
@@ -6050,13 +6060,17 @@
         final int dw = mCurDisplayWidth;
         final int dh = mCurDisplayHeight;
 
-        int orientation = Configuration.ORIENTATION_SQUARE;
-        if (dw < dh) {
-            orientation = Configuration.ORIENTATION_PORTRAIT;
-        } else if (dw > dh) {
-            orientation = Configuration.ORIENTATION_LANDSCAPE;
+        if (config != null) {
+            mInputManager.getInputConfiguration(config);
+
+            int orientation = Configuration.ORIENTATION_SQUARE;
+            if (dw < dh) {
+                orientation = Configuration.ORIENTATION_PORTRAIT;
+            } else if (dw > dh) {
+                orientation = Configuration.ORIENTATION_LANDSCAPE;
+            }
+            config.orientation = orientation;
         }
-        config.orientation = orientation;
 
         // Update real display metrics.
         mDisplay.getMetricsWithSize(mRealDisplayMetrics, mCurDisplayWidth, mCurDisplayHeight);
@@ -6078,36 +6092,39 @@
         mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm,
                 mCompatDisplayMetrics);
 
-        config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation)
-                / dm.density);
-        config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation)
-                / dm.density);
-        computeSmallestWidthAndScreenLayout(rotated, dw, dh, dm.density, config);
+        if (config != null) {
+            config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation)
+                    / dm.density);
+            config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation)
+                    / dm.density);
+            computeSmallestWidthAndScreenLayout(rotated, dw, dh, dm.density, config);
 
-        config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
-        config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
-        config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
+            config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
+            config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
+            config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
 
-        // Determine whether a hard keyboard is available and enabled.
-        boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
-        if (hardKeyboardAvailable != mHardKeyboardAvailable) {
-            mHardKeyboardAvailable = hardKeyboardAvailable;
-            mHardKeyboardEnabled = hardKeyboardAvailable;
+            // Determine whether a hard keyboard is available and enabled.
+            boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
+            if (hardKeyboardAvailable != mHardKeyboardAvailable) {
+                mHardKeyboardAvailable = hardKeyboardAvailable;
+                mHardKeyboardEnabled = hardKeyboardAvailable;
 
-            mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
-            mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
-        }
-        if (!mHardKeyboardEnabled) {
-            config.keyboard = Configuration.KEYBOARD_NOKEYS;
+                mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
+                mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
+            }
+            if (!mHardKeyboardEnabled) {
+                config.keyboard = Configuration.KEYBOARD_NOKEYS;
+            }
+
+            // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
+            // based on whether a hard or soft keyboard is present, whether navigation keys
+            // are present and the lid switch state.
+            config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
+            config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
+            config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
+            mPolicy.adjustConfigurationLw(config);
         }
 
-        // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
-        // based on whether a hard or soft keyboard is present, whether navigation keys
-        // are present and the lid switch state.
-        config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
-        config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
-        config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
-        mPolicy.adjustConfigurationLw(config);
         return true;
     }
 
@@ -7114,7 +7131,7 @@
         boolean configChanged = updateOrientationFromAppTokensLocked(false);
         mTempConfiguration.setToDefaults();
         mTempConfiguration.fontScale = mCurConfiguration.fontScale;
-        if (computeNewConfigurationLocked(mTempConfiguration)) {
+        if (computeScreenConfigurationLocked(mTempConfiguration)) {
             if (mCurConfiguration.diff(mTempConfiguration) != 0) {
                 configChanged = true;
             }
diff --git a/telephony/java/com/android/internal/telephony/cat/CatService.java b/telephony/java/com/android/internal/telephony/cat/CatService.java
index 97fb73d..2b37072 100644
--- a/telephony/java/com/android/internal/telephony/cat/CatService.java
+++ b/telephony/java/com/android/internal/telephony/cat/CatService.java
@@ -427,11 +427,11 @@
                     }
                     break;
                 default:
-                    CatLog.d(this, "encodeOptionalTags() Unsupported Cmd:" + cmdDet.typeOfCommand);
+                    CatLog.d(this, "encodeOptionalTags() Unsupported Cmd details=" + cmdDet);
                     break;
             }
         } else {
-            CatLog.d(this, "encodeOptionalTags() bad Cmd:" + cmdDet.typeOfCommand);
+            CatLog.d(this, "encodeOptionalTags() bad Cmd details=" + cmdDet);
         }
     }
 
diff --git a/telephony/java/com/android/internal/telephony/cat/ComprehensionTlv.java b/telephony/java/com/android/internal/telephony/cat/ComprehensionTlv.java
index bd6b7d1..22cd5a4 100644
--- a/telephony/java/com/android/internal/telephony/cat/ComprehensionTlv.java
+++ b/telephony/java/com/android/internal/telephony/cat/ComprehensionTlv.java
@@ -96,7 +96,6 @@
                 startIndex = ctlv.mValueIndex + ctlv.mLength;
             } else {
                 CatLog.d(LOG_TAG, "decodeMany: ctlv is null, stop decoding");
-                items.clear();
                 break;
             }
         }