Merge "Add channel mask in AudioSink"
diff --git a/api/16.txt b/api/16.txt
index 357d618..6543ab0 100644
--- a/api/16.txt
+++ b/api/16.txt
@@ -7144,7 +7144,7 @@
     method public abstract void setBindArguments(java.lang.String[]);
   }
 
-  public class SQLiteDatabase extends android.database.sqlite.SQLiteClosable {
+  public final class SQLiteDatabase extends android.database.sqlite.SQLiteClosable {
     method public void beginTransaction();
     method public void beginTransactionNonExclusive();
     method public void beginTransactionWithListener(android.database.sqlite.SQLiteTransactionListener);
diff --git a/api/current.txt b/api/current.txt
index c67c403..30df086 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -414,7 +414,7 @@
     field public static final int ems = 16843096; // 0x1010158
     field public static final deprecated int enabled = 16842766; // 0x101000e
     field public static final int endColor = 16843166; // 0x101019e
-    field public static final int endYear = 16843133; // 0x101017d
+    field public static final deprecated int endYear = 16843133; // 0x101017d
     field public static final int enterFadeDuration = 16843532; // 0x101030c
     field public static final int entries = 16842930; // 0x10100b2
     field public static final int entryValues = 16843256; // 0x10101f8
@@ -888,7 +888,7 @@
     field public static final int starStyle = 16842882; // 0x1010082
     field public static final int startColor = 16843165; // 0x101019d
     field public static final int startOffset = 16843198; // 0x10101be
-    field public static final int startYear = 16843132; // 0x101017c
+    field public static final deprecated int startYear = 16843132; // 0x101017c
     field public static final int stateNotNeeded = 16842774; // 0x1010016
     field public static final int state_above_anchor = 16842922; // 0x10100aa
     field public static final int state_accelerated = 16843547; // 0x101031b
@@ -7267,7 +7267,7 @@
     method public abstract void setBindArguments(java.lang.String[]);
   }
 
-  public class SQLiteDatabase extends android.database.sqlite.SQLiteClosable {
+  public final class SQLiteDatabase extends android.database.sqlite.SQLiteClosable {
     method public void beginTransaction();
     method public void beginTransactionNonExclusive();
     method public void beginTransactionWithListener(android.database.sqlite.SQLiteTransactionListener);
@@ -15092,7 +15092,7 @@
     field public static final android.os.Parcelable.Creator STRING_CREATOR;
   }
 
-  public class ParcelFileDescriptor implements android.os.Parcelable {
+  public class ParcelFileDescriptor implements java.io.Closeable android.os.Parcelable {
     ctor public ParcelFileDescriptor(android.os.ParcelFileDescriptor);
     method public static android.os.ParcelFileDescriptor adoptFd(int);
     method public void close() throws java.io.IOException;
@@ -15326,6 +15326,7 @@
     method public android.os.StrictMode.VmPolicy.Builder detectActivityLeaks();
     method public android.os.StrictMode.VmPolicy.Builder detectAll();
     method public android.os.StrictMode.VmPolicy.Builder detectLeakedClosableObjects();
+    method public android.os.StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects();
     method public android.os.StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects();
     method public android.os.StrictMode.VmPolicy.Builder penaltyDeath();
     method public android.os.StrictMode.VmPolicy.Builder penaltyDropBox();
@@ -26113,17 +26114,36 @@
     ctor public CalendarView(android.content.Context, android.util.AttributeSet);
     ctor public CalendarView(android.content.Context, android.util.AttributeSet, int);
     method public long getDate();
+    method public int getDateTextAppearance();
     method public int getFirstDayOfWeek();
+    method public int getFocusedMonthDateColor();
     method public long getMaxDate();
     method public long getMinDate();
+    method public android.graphics.drawable.Drawable getSelectedDateVerticalBar();
+    method public int getSelectedWeekBackgroundColor();
     method public boolean getShowWeekNumber();
+    method public int getShownWeekCount();
+    method public int getUnfocusedMonthDateColor();
+    method public int getWeekDayTextAppearance();
+    method public int getWeekNumberColor();
+    method public int getWeekSeparatorLineColor();
     method public void setDate(long);
     method public void setDate(long, boolean, boolean);
+    method public void setDateTextAppearance(int);
     method public void setFirstDayOfWeek(int);
+    method public void setFocusedMonthDateColor(int);
     method public void setMaxDate(long);
     method public void setMinDate(long);
     method public void setOnDateChangeListener(android.widget.CalendarView.OnDateChangeListener);
+    method public void setSelectedDateVerticalBar(int);
+    method public void setSelectedDateVerticalBar(android.graphics.drawable.Drawable);
+    method public void setSelectedWeekBackgroundColor(int);
     method public void setShowWeekNumber(boolean);
+    method public void setShownWeekCount(int);
+    method public void setUnfocusedMonthDateColor(int);
+    method public void setWeekDayTextAppearance(int);
+    method public void setWeekNumberColor(int);
+    method public void setWeekSeparatorLineColor(int);
   }
 
   public static abstract interface CalendarView.OnDateChangeListener {
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index f10bf03..aa15f39 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -102,6 +102,8 @@
 import java.util.TimeZone;
 import java.util.regex.Pattern;
 
+import libcore.io.IoUtils;
+
 import dalvik.system.CloseGuard;
 
 final class SuperNotCalledException extends AndroidRuntimeException {
@@ -2357,41 +2359,47 @@
     }
 
     private void handleDumpService(DumpComponentInfo info) {
-        Service s = mServices.get(info.token);
-        if (s != null) {
-            PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
-            s.dump(info.fd.getFileDescriptor(), pw, info.args);
-            pw.flush();
-            try {
-                info.fd.close();
-            } catch (IOException e) {
+        final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
+        try {
+            Service s = mServices.get(info.token);
+            if (s != null) {
+                PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
+                s.dump(info.fd.getFileDescriptor(), pw, info.args);
+                pw.flush();
             }
+        } finally {
+            IoUtils.closeQuietly(info.fd);
+            StrictMode.setThreadPolicy(oldPolicy);
         }
     }
 
     private void handleDumpActivity(DumpComponentInfo info) {
-        ActivityClientRecord r = mActivities.get(info.token);
-        if (r != null && r.activity != null) {
-            PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
-            r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
-            pw.flush();
-            try {
-                info.fd.close();
-            } catch (IOException e) {
+        final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
+        try {
+            ActivityClientRecord r = mActivities.get(info.token);
+            if (r != null && r.activity != null) {
+                PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
+                r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
+                pw.flush();
             }
+        } finally {
+            IoUtils.closeQuietly(info.fd);
+            StrictMode.setThreadPolicy(oldPolicy);
         }
     }
 
     private void handleDumpProvider(DumpComponentInfo info) {
-        ProviderClientRecord r = mLocalProviders.get(info.token);
-        if (r != null && r.mLocalProvider != null) {
-            PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
-            r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args);
-            pw.flush();
-            try {
-                info.fd.close();
-            } catch (IOException e) {
+        final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
+        try {
+            ProviderClientRecord r = mLocalProviders.get(info.token);
+            if (r != null && r.mLocalProvider != null) {
+                PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
+                r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args);
+                pw.flush();
             }
+        } finally {
+            IoUtils.closeQuietly(info.fd);
+            StrictMode.setThreadPolicy(oldPolicy);
         }
     }
 
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index d9bbb4a..de9470e 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -512,6 +512,7 @@
 
     public void removeContextRegistrations(Context context,
             String who, String what) {
+        final boolean reportRegistrationLeaks = StrictMode.vmRegistrationLeaksEnabled();
         HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> rmap =
             mReceivers.remove(context);
         if (rmap != null) {
@@ -525,6 +526,9 @@
                         "call to unregisterReceiver()?");
                 leak.setStackTrace(rd.getLocation().getStackTrace());
                 Slog.e(ActivityThread.TAG, leak.getMessage(), leak);
+                if (reportRegistrationLeaks) {
+                    StrictMode.onIntentReceiverLeaked(leak);
+                }
                 try {
                     ActivityManagerNative.getDefault().unregisterReceiver(
                             rd.getIIntentReceiver());
@@ -546,6 +550,9 @@
                         + sd.getServiceConnection() + " that was originally bound here");
                 leak.setStackTrace(sd.getLocation().getStackTrace());
                 Slog.e(ActivityThread.TAG, leak.getMessage(), leak);
+                if (reportRegistrationLeaks) {
+                    StrictMode.onServiceConnectionLeaked(leak);
+                }
                 try {
                     ActivityManagerNative.getDefault().unbindService(
                             sd.getIServiceConnection());
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 04ee142..604247e 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -19,7 +19,6 @@
 import android.content.CancellationSignal;
 import android.content.ContentValues;
 import android.content.OperationCanceledException;
-import android.content.res.Resources;
 import android.database.Cursor;
 import android.database.DatabaseErrorHandler;
 import android.database.DatabaseUtils;
@@ -65,7 +64,7 @@
  * to the current locale.
  * </p>
  */
-public class SQLiteDatabase extends SQLiteClosable {
+public final class SQLiteDatabase extends SQLiteClosable {
     private static final String TAG = "SQLiteDatabase";
 
     private static final int EVENT_DB_CORRUPT = 75004;
diff --git a/core/java/android/database/sqlite/SQLiteDebug.java b/core/java/android/database/sqlite/SQLiteDebug.java
index 10ce991..1197331 100644
--- a/core/java/android/database/sqlite/SQLiteDebug.java
+++ b/core/java/android/database/sqlite/SQLiteDebug.java
@@ -62,6 +62,9 @@
      */
     public static final boolean DEBUG_LOG_SLOW_QUERIES = Build.IS_DEBUGGABLE;
 
+    private SQLiteDebug() {
+    }
+
     /**
      * Determines whether a query should be logged.
      *
diff --git a/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java b/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java
index 3375e74..294edc4 100644
--- a/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java
+++ b/core/java/android/database/sqlite/SQLiteDirectCursorDriver.java
@@ -25,7 +25,7 @@
  * 
  * @hide
  */
-public class SQLiteDirectCursorDriver implements SQLiteCursorDriver {
+public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver {
     private final SQLiteDatabase mDatabase;
     private final String mEditTable; 
     private final String mSql;
diff --git a/core/java/android/os/ParcelFileDescriptor.java b/core/java/android/os/ParcelFileDescriptor.java
index ac15d9c..3e90dfc 100644
--- a/core/java/android/os/ParcelFileDescriptor.java
+++ b/core/java/android/os/ParcelFileDescriptor.java
@@ -15,6 +15,7 @@
  */
 
 package android.os;
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
@@ -28,7 +29,7 @@
  * The FileDescriptor returned by {@link Parcel#readFileDescriptor}, allowing
  * you to close it when done with it.
  */
-public class ParcelFileDescriptor implements Parcelable {
+public class ParcelFileDescriptor implements Parcelable, Closeable {
     private final FileDescriptor mFileDescriptor;
     private boolean mClosed;
     //this field is to create wrapper for ParcelFileDescriptor using another
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 99f58a0..a0ad9c0 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -20,7 +20,10 @@
 import android.app.ActivityThread;
 import android.app.ApplicationErrorReport;
 import android.app.IActivityManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.content.Intent;
+import android.content.ServiceConnection;
 import android.util.Log;
 import android.util.Printer;
 import android.util.Singleton;
@@ -195,9 +198,15 @@
      */
     private static final int DETECT_VM_INSTANCE_LEAKS = 0x1000;  // for VmPolicy
 
+    /**
+     * @hide
+     */
+    public static final int DETECT_VM_REGISTRATION_LEAKS = 0x2000;  // for VmPolicy
+
     private static final int ALL_VM_DETECT_BITS =
             DETECT_VM_CURSOR_LEAKS | DETECT_VM_CLOSABLE_LEAKS |
-            DETECT_VM_ACTIVITY_LEAKS | DETECT_VM_INSTANCE_LEAKS;
+            DETECT_VM_ACTIVITY_LEAKS | DETECT_VM_INSTANCE_LEAKS |
+            DETECT_VM_REGISTRATION_LEAKS;
 
     /**
      * @hide
@@ -618,8 +627,8 @@
              * but will likely expand in future releases.
              */
             public Builder detectAll() {
-                return enable(DETECT_VM_ACTIVITY_LEAKS |
-                        DETECT_VM_CURSOR_LEAKS | DETECT_VM_CLOSABLE_LEAKS);
+                return enable(DETECT_VM_ACTIVITY_LEAKS | DETECT_VM_CURSOR_LEAKS
+                        | DETECT_VM_CLOSABLE_LEAKS | DETECT_VM_REGISTRATION_LEAKS);
             }
 
             /**
@@ -648,6 +657,15 @@
             }
 
             /**
+             * Detect when a {@link BroadcastReceiver} or
+             * {@link ServiceConnection} is leaked during {@link Context}
+             * teardown.
+             */
+            public Builder detectLeakedRegistrationObjects() {
+                return enable(DETECT_VM_REGISTRATION_LEAKS);
+            }
+
+            /**
              * Crashes the whole process on violation.  This penalty runs at
              * the end of all enabled penalties so yo you'll still get
              * your logging or other violations before the process dies.
@@ -1499,6 +1517,13 @@
     /**
      * @hide
      */
+    public static boolean vmRegistrationLeaksEnabled() {
+        return (sVmPolicyMask & DETECT_VM_REGISTRATION_LEAKS) != 0;
+    }
+
+    /**
+     * @hide
+     */
     public static void onSqliteObjectLeaked(String message, Throwable originStack) {
         onVmPolicyViolation(message, originStack);
     }
@@ -1510,6 +1535,20 @@
         onVmPolicyViolation(null, originStack);
     }
 
+    /**
+     * @hide
+     */
+    public static void onIntentReceiverLeaked(Throwable originStack) {
+        onVmPolicyViolation(null, originStack);
+    }
+
+    /**
+     * @hide
+     */
+    public static void onServiceConnectionLeaked(Throwable originStack) {
+        onVmPolicyViolation(null, originStack);
+    }
+
     // Map from VM violation fingerprint to uptime millis.
     private static final HashMap<Integer, Long> sLastVmViolationTime = new HashMap<Integer, Long>();
 
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index d3ad63d..6c6b118 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -1833,19 +1833,19 @@
             public static final String LANGUAGE = "language";
 
             /**
-             * The latitude where the image was captured.
+             * The latitude where the video was captured.
              * <P>Type: DOUBLE</P>
              */
             public static final String LATITUDE = "latitude";
 
             /**
-             * The longitude where the image was captured.
+             * The longitude where the video was captured.
              * <P>Type: DOUBLE</P>
              */
             public static final String LONGITUDE = "longitude";
 
             /**
-             * The date & time that the image was taken in units
+             * The date & time that the video was taken in units
              * of milliseconds since jan 1, 1970.
              * <P>Type: INTEGER</P>
              */
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index ee0fa86..1f75e70 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -157,6 +157,8 @@
     static native void nDestroyLayer(int layerId);
     static native void nDestroyLayerDeferred(int layerId);
     static native void nFlushLayer(int layerId);
+    static native void nUpdateRenderLayer(int layerId, int renderer, int displayList,
+            int left, int top, int right, int bottom);
     static native boolean nCopyLayer(int layerId, int bitmap);
 
     ///////////////////////////////////////////////////////////////////////////
@@ -191,6 +193,13 @@
     private static native int nGetMaximumTextureWidth();
     private static native int nGetMaximumTextureHeight();
 
+    /**
+     * Returns the native OpenGLRenderer object.
+     */
+    int getRenderer() {
+        return mRenderer;
+    }
+
     ///////////////////////////////////////////////////////////////////////////
     // Setup
     ///////////////////////////////////////////////////////////////////////////
diff --git a/core/java/android/view/GLES20RenderLayer.java b/core/java/android/view/GLES20RenderLayer.java
index 23a7166..c727a36 100644
--- a/core/java/android/view/GLES20RenderLayer.java
+++ b/core/java/android/view/GLES20RenderLayer.java
@@ -18,6 +18,7 @@
 
 import android.graphics.Canvas;
 import android.graphics.Matrix;
+import android.graphics.Rect;
 
 /**
  * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. This
@@ -95,4 +96,11 @@
     @Override
     void setTransform(Matrix matrix) {
     }
+
+    @Override
+    void redraw(DisplayList displayList, Rect dirtyRect) {
+        GLES20Canvas.nUpdateRenderLayer(mLayer, mCanvas.getRenderer(),
+                ((GLES20DisplayList) displayList).getNativeDisplayList(),
+                dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);
+    }
 }
diff --git a/core/java/android/view/GLES20TextureLayer.java b/core/java/android/view/GLES20TextureLayer.java
index 6c41023..cbb908b 100644
--- a/core/java/android/view/GLES20TextureLayer.java
+++ b/core/java/android/view/GLES20TextureLayer.java
@@ -18,6 +18,7 @@
 
 import android.graphics.Canvas;
 import android.graphics.Matrix;
+import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
 
 /**
@@ -81,4 +82,8 @@
     void setTransform(Matrix matrix) {
         GLES20Canvas.nSetTextureLayerTransform(mLayer, matrix.native_instance);
     }
+
+    @Override
+    void redraw(DisplayList displayList, Rect dirtyRect) {
+    }
 }
diff --git a/core/java/android/view/HardwareLayer.java b/core/java/android/view/HardwareLayer.java
index d5666f3..49450bd 100644
--- a/core/java/android/view/HardwareLayer.java
+++ b/core/java/android/view/HardwareLayer.java
@@ -19,6 +19,7 @@
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Matrix;
+import android.graphics.Rect;
 
 /**
  * A hardware layer can be used to render graphics operations into a hardware
@@ -163,4 +164,13 @@
      * @param matrix The transform to apply to the layer.
      */
     abstract void setTransform(Matrix matrix);
+
+    /**
+     * Specifies the display list to use to refresh the layer.
+     * 
+     * @param displayList The display list containing the drawing commands to
+     *                    execute in this layer
+     * @param dirtyRect The dirty region of the layer that needs to be redrawn
+     */
+    abstract void redraw(DisplayList displayList, Rect dirtyRect);
 }
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index 9628d6b..3c0ee12 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -34,8 +34,8 @@
 import java.util.HashMap;
 
 /**
- * This class is used to instantiate layout XML file into its corresponding View
- * objects. It is never be used directly -- use
+ * Instantiates a layout XML file into its corresponding {@link android.view.View}
+ * objects. It is never used directly. Instead, use
  * {@link android.app.Activity#getLayoutInflater()} or
  * {@link Context#getSystemService} to retrieve a standard LayoutInflater instance
  * that is already hooked up to the current context and correctly configured
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 74916f0..865f9d2 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -315,7 +315,7 @@
     }
 
     @Override
-    HardwareLayer getHardwareLayer() {
+    HardwareLayer getHardwareLayer(boolean immediateRefresh) {
         if (mLayer == null) {
             if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) {
                 return null;
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index f7dc73c..1ddc51f 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -9660,6 +9660,8 @@
      *
      * @param layoutDirection the direction of the layout
      *
+     * {@link #LAYOUT_DIRECTION_LTR}
+     * {@link #LAYOUT_DIRECTION_RTL}
      */
     public void onPaddingChanged(int layoutDirection) {
     }
@@ -10123,7 +10125,7 @@
      * dynamic.
      */
     boolean hasStaticLayer() {
-        return mLayerType == LAYER_TYPE_NONE;
+        return true;
     }
 
     /**
@@ -10170,7 +10172,7 @@
                 if (mAttachInfo.mHardwareRenderer != null &&
                         mAttachInfo.mHardwareRenderer.isEnabled() &&
                         mAttachInfo.mHardwareRenderer.validate()) {
-                    getHardwareLayer();
+                    getHardwareLayer(true);
                 }
                 break;
             case LAYER_TYPE_SOFTWARE:
@@ -10192,7 +10194,7 @@
      *
      * @return A HardwareLayer ready to render, or null if an error occurred.
      */
-    HardwareLayer getHardwareLayer() {
+    HardwareLayer getHardwareLayer(boolean immediateRefresh) {
         if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null ||
                 !mAttachInfo.mHardwareRenderer.isEnabled()) {
             return null;
@@ -10222,41 +10224,32 @@
                 return null;
             }
 
-            HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas;
-            final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas);
-
-            // Make sure all the GPU resources have been properly allocated
-            if (canvas == null) {
-                mHardwareLayer.end(currentCanvas);
-                return null;
-            }
-
-            mAttachInfo.mHardwareCanvas = canvas;
-            try {
-                canvas.setViewport(width, height);
-                canvas.onPreDraw(mLocalDirtyRect);
+            if (!immediateRefresh) {
+                mHardwareLayer.redraw(getDisplayList(), mLocalDirtyRect);
                 mLocalDirtyRect.setEmpty();
-
-                final int restoreCount = canvas.save();
-
-                computeScroll();
-                canvas.translate(-mScrollX, -mScrollY);
-
-                mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID;
-
-                // Fast path for layouts with no backgrounds
-                if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) {
-                    mPrivateFlags &= ~DIRTY_MASK;
-                    dispatchDraw(canvas);
-                } else {
-                    draw(canvas);
+            } else {
+                HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas;
+                final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas);
+    
+                // Make sure all the GPU resources have been properly allocated
+                if (canvas == null) {
+                    mHardwareLayer.end(currentCanvas);
+                    return null;
                 }
-
-                canvas.restoreToCount(restoreCount);
-            } finally {
-                canvas.onPostDraw();
-                mHardwareLayer.end(currentCanvas);
-                mAttachInfo.mHardwareCanvas = currentCanvas;
+    
+                mAttachInfo.mHardwareCanvas = canvas;
+                try {
+                    canvas.setViewport(width, height);
+                    canvas.onPreDraw(mLocalDirtyRect);
+                    mLocalDirtyRect.setEmpty();
+                    
+                    canvas.drawDisplayList(getDisplayList(), mRight - mLeft, mBottom - mTop, null,
+                            DisplayList.FLAG_CLIP_CHILDREN);
+                } finally {
+                    canvas.onPostDraw();
+                    mHardwareLayer.end(currentCanvas);
+                    mAttachInfo.mHardwareCanvas = currentCanvas;
+                }
             }
         }
 
@@ -11224,7 +11217,7 @@
         if (hasNoCache) {
             boolean layerRendered = false;
             if (layerType == LAYER_TYPE_HARDWARE) {
-                final HardwareLayer layer = getHardwareLayer();
+                final HardwareLayer layer = getHardwareLayer(false);
                 if (layer != null && layer.isValid()) {
                     mLayerPaint.setAlpha((int) (alpha * 255));
                     ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint);
diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java
index 484c449..2afb841 100644
--- a/core/java/android/webkit/CallbackProxy.java
+++ b/core/java/android/webkit/CallbackProxy.java
@@ -155,6 +155,12 @@
         mBackForwardList = new WebBackForwardList(this);
     }
 
+    protected void shutdown() {
+        setWebViewClient(null);
+        setWebChromeClient(null);
+        removeCallbacksAndMessages(null);
+    }
+
     /**
      * Set the WebViewClient.
      * @param client An implementation of WebViewClient.
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index a01c42d..911073d 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -16,148 +16,15 @@
 
 package android.webkit;
 
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.ColorFilter;
-import android.graphics.Paint;
-import android.graphics.Paint.Style;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.ResultReceiver;
-import android.text.BoringLayout.Metrics;
-import android.text.DynamicLayout;
-import android.text.Editable;
-import android.text.InputFilter;
-import android.text.InputType;
-import android.text.Layout;
-import android.text.Selection;
-import android.text.Spannable;
-import android.text.TextPaint;
-import android.text.TextUtils;
-import android.text.method.MovementMethod;
-import android.text.method.Touch;
 import android.util.Log;
-import android.util.TypedValue;
-import android.view.Gravity;
-import android.view.KeyCharacterMap;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.ViewGroup;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputConnection;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.AbsoluteLayout.LayoutParams;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.AutoCompleteTextView;
-import android.widget.TextView;
-
-import junit.framework.Assert;
 
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.ArrayList;
 
-/**
- * WebTextView is a specialized version of EditText used by WebView
- * to overlay html textfields (and textareas) to use our standard
- * text editing.
- */
-/* package */ class WebTextView extends AutoCompleteTextView
-        implements AdapterView.OnItemClickListener {
+// TODO: Move these to a better place.
+/* package */ abstract class WebTextView {
 
-    static final String LOGTAG = "webtextview";
-
-    private int mRingInset;
-
-    private WebViewClassic  mWebView;
-    private boolean         mSingle;
-    private int             mWidthSpec;
-    private int             mHeightSpec;
-    private int             mNodePointer;
-    // FIXME: This is a hack for blocking unmatched key ups, in particular
-    // on the enter key.  The method for blocking unmatched key ups prevents
-    // the shift key from working properly.
-    private boolean         mGotEnterDown;
-    private int             mMaxLength;
-    // Keep track of the text before the change so we know whether we actually
-    // need to send down the DOM events.
-    private String          mPreChange;
-    // Variables for keeping track of the touch down, to send to the WebView
-    // when a drag starts
-    private float           mDragStartX;
-    private float           mDragStartY;
-    private long            mDragStartTime;
-    private boolean         mDragSent;
-    // True if the most recent drag event has caused either the TextView to
-    // scroll or the web page to scroll.  Gets reset after a touch down.
-    private boolean         mScrolled;
-    // Whether or not a selection change was generated from webkit.  If it was,
-    // we do not need to pass the selection back to webkit.
-    private boolean         mFromWebKit;
-    // Whether or not a selection change was generated from the WebTextView
-    // gaining focus.  If it is, we do not want to pass it to webkit.  This
-    // selection comes from the MovementMethod, but we behave differently.  If
-    // WebTextView gained focus from a touch, webkit will determine the
-    // selection.
-    private boolean         mFromFocusChange;
-    // Whether or not a selection change was generated from setInputType.  We
-    // do not want to pass this change to webkit.
-    private boolean         mFromSetInputType;
-    private boolean         mGotTouchDown;
-    // Keep track of whether a long press has happened.  Only meaningful after
-    // an ACTION_DOWN MotionEvent
-    private boolean         mHasPerformedLongClick;
-    private boolean         mInSetTextAndKeepSelection;
-    // Array to store the final character added in onTextChanged, so that its
-    // KeyEvents may be determined.
-    private char[]          mCharacter = new char[1];
-    // This is used to reset the length filter when on a textfield
-    // with no max length.
-    // FIXME: This can be replaced with TextView.NO_FILTERS if that
-    // is made public/protected.
-    private static final InputFilter[] NO_FILTERS = new InputFilter[0];
-    // For keeping track of the fact that the delete key was pressed, so
-    // we can simply pass a delete key instead of calling deleteSelection.
-    private boolean mGotDelete;
-    private int mDelSelStart;
-    private int mDelSelEnd;
-
-    // Keep in sync with native constant in
-    // external/webkit/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
-    /* package */ static final int FORM_NOT_AUTOFILLABLE = -1;
-
-    private boolean mAutoFillable; // Is this textview part of an autofillable form?
-    private int mQueryId;
-    private boolean mAutoFillProfileIsSet;
-    // Used to determine whether onFocusChanged was called as a result of
-    // calling remove().
-    private boolean mInsideRemove;
-    private class MyResultReceiver extends ResultReceiver {
-        @Override
-        protected void onReceiveResult(int resultCode, Bundle resultData) {
-            if (resultCode == InputMethodManager.RESULT_SHOWN
-                    && mWebView != null) {
-                mWebView.revealSelection();
-            }
-        }
-
-        /**
-         * @param handler
-         */
-        public MyResultReceiver(Handler handler) {
-            super(handler);
-        }
-    }
-    private MyResultReceiver mReceiver;
+    private static final String LOGTAG = "WebTextView";
 
     // Types used with setType.  Keep in sync with CachedInput.h
     static final int NORMAL_TEXT_FIELD = 0;
@@ -169,1006 +36,7 @@
     static final int TELEPHONE = 6;
     static final int URL = 7;
 
-    private static final int AUTOFILL_FORM = 100;
-    private Handler mHandler;
-
-    /**
-     * Create a new WebTextView.
-     * @param   context The Context for this WebTextView.
-     * @param   webView The WebView that created this.
-     */
-    /* package */ WebTextView(Context context, WebViewClassic webView, int autoFillQueryId) {
-        super(context, null, com.android.internal.R.attr.webTextViewStyle);
-        mWebView = webView;
-        mMaxLength = -1;
-        setAutoFillable(autoFillQueryId);
-        // Turn on subpixel text, and turn off kerning, so it better matches
-        // the text in webkit.
-        TextPaint paint = getPaint();
-        int flags = paint.getFlags() & ~Paint.DEV_KERN_TEXT_FLAG
-                | Paint.SUBPIXEL_TEXT_FLAG | Paint.DITHER_FLAG;
-        paint.setFlags(flags);
-
-        // Set the text color to black, regardless of the theme.  This ensures
-        // that other applications that use embedded WebViews will properly
-        // display the text in password textfields.
-        setTextColor(DebugFlags.DRAW_WEBTEXTVIEW ? Color.RED : Color.BLACK);
-        setBackgroundDrawable(DebugFlags.DRAW_WEBTEXTVIEW ? null : new ColorDrawable(Color.WHITE));
-
-        // This helps to align the text better with the text in the web page.
-        setIncludeFontPadding(false);
-
-        mHandler = new Handler() {
-            @Override
-            public void handleMessage(Message msg) {
-                switch (msg.what) {
-                case AUTOFILL_FORM:
-                    mWebView.autoFillForm(mQueryId);
-                    break;
-                }
-            }
-        };
-        mReceiver = new MyResultReceiver(mHandler);
-        float ringWidth = 2f * context.getResources().getDisplayMetrics().density;
-        mRingInset = (int) ringWidth;
-        setBackgroundDrawable(new BackgroundDrawable(mRingInset));
-        setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
-                getPaddingBottom());
-    }
-
-    private static class BackgroundDrawable extends Drawable {
-
-        private Paint mPaint = new Paint();
-        private int mBorderWidth;
-        private Rect mInsetRect = new Rect();
-
-        public BackgroundDrawable(int width) {
-            mPaint = new Paint();
-            mPaint.setStrokeWidth(width);
-            mBorderWidth = width;
-        }
-
-        @Override
-        public void draw(Canvas canvas) {
-            mPaint.setColor(0x6633b5e5);
-            canvas.drawRect(getBounds(), mPaint);
-            mInsetRect.left = getBounds().left + mBorderWidth;
-            mInsetRect.top = getBounds().top + mBorderWidth;
-            mInsetRect.right = getBounds().right - mBorderWidth;
-            mInsetRect.bottom = getBounds().bottom - mBorderWidth;
-            mPaint.setColor(Color.WHITE);
-            canvas.drawRect(mInsetRect, mPaint);
-        }
-
-        @Override
-        public void setAlpha(int alpha) {
-        }
-
-        @Override
-        public void setColorFilter(ColorFilter cf) {
-        }
-
-        @Override
-        public int getOpacity() {
-            return PixelFormat.TRANSLUCENT;
-        }
-
-    }
-
-    public void setAutoFillable(int queryId) {
-        mAutoFillable = mWebView.getSettings().getAutoFillEnabled()
-                && (queryId != FORM_NOT_AUTOFILLABLE);
-        mQueryId = queryId;
-    }
-
-    @Override
-    public void setPadding(int left, int top, int right, int bottom) {
-        super.setPadding(left + mRingInset, top + mRingInset,
-                right + mRingInset, bottom + mRingInset);
-    }
-
-    @Override
-    public boolean dispatchKeyEvent(KeyEvent event) {
-        if (event.isSystem()) {
-            return super.dispatchKeyEvent(event);
-        }
-        // Treat ACTION_DOWN and ACTION MULTIPLE the same
-        boolean down = event.getAction() != KeyEvent.ACTION_UP;
-        int keyCode = event.getKeyCode();
-
-        boolean isArrowKey = false;
-        switch(keyCode) {
-            case KeyEvent.KEYCODE_DPAD_LEFT:
-            case KeyEvent.KEYCODE_DPAD_RIGHT:
-            case KeyEvent.KEYCODE_DPAD_UP:
-            case KeyEvent.KEYCODE_DPAD_DOWN:
-                isArrowKey = true;
-                break;
-        }
-
-        if (KeyEvent.KEYCODE_TAB == keyCode) {
-            if (down) {
-                onEditorAction(EditorInfo.IME_ACTION_NEXT);
-            }
-            return true;
-        }
-        Spannable text = (Spannable) getText();
-        int oldStart = Selection.getSelectionStart(text);
-        int oldEnd = Selection.getSelectionEnd(text);
-        // Normally the delete key's dom events are sent via onTextChanged.
-        // However, if the cursor is at the beginning of the field, which
-        // includes the case where it has zero length, then the text is not
-        // changed, so send the events immediately.
-        if (KeyEvent.KEYCODE_DEL == keyCode) {
-            if (oldStart == 0 && oldEnd == 0) {
-                sendDomEvent(event);
-                return true;
-            }
-            if (down) {
-                mGotDelete = true;
-                mDelSelStart = oldStart;
-                mDelSelEnd = oldEnd;
-            }
-        }
-
-        if (mSingle && (KeyEvent.KEYCODE_ENTER == keyCode
-                    || KeyEvent.KEYCODE_NUMPAD_ENTER == keyCode)) {
-            if (isPopupShowing()) {
-                return super.dispatchKeyEvent(event);
-            }
-            if (!down) {
-                // Hide the keyboard, since the user has just submitted this
-                // form.  The submission happens thanks to the two calls
-                // to sendDomEvent.
-                InputMethodManager.getInstance(mContext)
-                        .hideSoftInputFromWindow(getWindowToken(), 0);
-                sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
-                sendDomEvent(event);
-            }
-            return super.dispatchKeyEvent(event);
-        } else if (KeyEvent.KEYCODE_DPAD_CENTER == keyCode) {
-            // Note that this handles center key and trackball.
-            if (isPopupShowing()) {
-                return super.dispatchKeyEvent(event);
-            }
-            // Center key should be passed to a potential onClick
-            if (!down) {
-                mWebView.centerKeyPressOnTextField();
-            }
-            // Pass to super to handle longpress.
-            return super.dispatchKeyEvent(event);
-        }
-
-        // Ensure there is a layout so arrow keys are handled properly.
-        if (getLayout() == null) {
-            measure(mWidthSpec, mHeightSpec);
-        }
-
-        int oldLength = text.length();
-        boolean maxedOut = mMaxLength != -1 && oldLength == mMaxLength;
-        // If we are at max length, and there is a selection rather than a
-        // cursor, we need to store the text to compare later, since the key
-        // may have changed the string.
-        String oldText;
-        if (maxedOut && oldEnd != oldStart) {
-            oldText = text.toString();
-        } else {
-            oldText = "";
-        }
-        if (super.dispatchKeyEvent(event)) {
-            // If the WebTextView handled the key it was either an alphanumeric
-            // key, a delete, or a movement within the text. All of those are
-            // ok to pass to javascript.
-
-            // UNLESS there is a max length determined by the html.  In that
-            // case, if the string was already at the max length, an
-            // alphanumeric key will be erased by the LengthFilter,
-            // so do not pass down to javascript, and instead
-            // return true.  If it is an arrow key or a delete key, we can go
-            // ahead and pass it down.
-            if (KeyEvent.KEYCODE_ENTER == keyCode
-                        || KeyEvent.KEYCODE_NUMPAD_ENTER == keyCode) {
-                // For multi-line text boxes, newlines will
-                // trigger onTextChanged for key down (which will send both
-                // key up and key down) but not key up.
-                mGotEnterDown = true;
-            }
-            if (maxedOut && !isArrowKey && keyCode != KeyEvent.KEYCODE_DEL) {
-                if (oldEnd == oldStart) {
-                    // Return true so the key gets dropped.
-                    return true;
-                } else if (!oldText.equals(getText().toString())) {
-                    // FIXME: This makes the text work properly, but it
-                    // does not pass down the key event, so it may not
-                    // work for a textfield that has the type of
-                    // behavior of GoogleSuggest.  That said, it is
-                    // unlikely that a site would combine the two in
-                    // one textfield.
-                    Spannable span = (Spannable) getText();
-                    int newStart = Selection.getSelectionStart(span);
-                    int newEnd = Selection.getSelectionEnd(span);
-                    mWebView.replaceTextfieldText(0, oldLength, span.toString(),
-                            newStart, newEnd);
-                    return true;
-                }
-            }
-            /* FIXME:
-             * In theory, we would like to send the events for the arrow keys.
-             * However, the TextView can arbitrarily change the selection (i.e.
-             * long press followed by using the trackball).  Therefore, we keep
-             * in sync with the TextView via onSelectionChanged.  If we also
-             * send the DOM event, we lose the correct selection.
-            if (isArrowKey) {
-                // Arrow key does not change the text, but we still want to send
-                // the DOM events.
-                sendDomEvent(event);
-            }
-             */
-            return true;
-        }
-        // Ignore the key up event for newlines. This prevents
-        // multiple newlines in the native textarea.
-        if (mGotEnterDown && !down) {
-            return true;
-        }
-        // if it is a navigation key, pass it to WebView
-        if (isArrowKey) {
-            // WebView check the trackballtime in onKeyDown to avoid calling
-            // native from both trackball and key handling. As this is called
-            // from WebTextView, we always want WebView to check with native.
-            // Reset trackballtime to ensure it.
-            mWebView.resetTrackballTime();
-            return down ? mWebView.onKeyDown(keyCode, event) : mWebView
-                    .onKeyUp(keyCode, event);
-        }
-        return false;
-    }
-
-    void ensureLayout() {
-        if (getLayout() == null) {
-            // Ensure we have a Layout
-            measure(mWidthSpec, mHeightSpec);
-            LayoutParams params = (LayoutParams) getLayoutParams();
-            if (params != null) {
-                layout(params.x, params.y, params.x + params.width,
-                        params.y + params.height);
-            }
-        }
-    }
-
-    /* package */ ResultReceiver getResultReceiver() { return mReceiver; }
-
-    /**
-     *  Determine whether this WebTextView currently represents the node
-     *  represented by ptr.
-     *  @param  ptr Pointer to a node to compare to.
-     *  @return boolean Whether this WebTextView already represents the node
-     *          pointed to by ptr.
-     */
-    /* package */ boolean isSameTextField(int ptr) {
-        return ptr == mNodePointer;
-    }
-
-    /**
-     * Ensure that the underlying text field/area is lined up with the WebTextView.
-     */
-    private void lineUpScroll() {
-        Layout layout = getLayout();
-        if (mWebView != null && layout != null) {
-            if (mSingle) {
-                // textfields only need to be lined up horizontally.
-                float maxScrollX = layout.getLineRight(0) - getWidth();
-                if (DebugFlags.WEB_TEXT_VIEW) {
-                    Log.v(LOGTAG, "onTouchEvent x=" + mScrollX + " y="
-                            + mScrollY + " maxX=" + maxScrollX);
-                }
-                mWebView.scrollFocusedTextInputX(maxScrollX > 0 ?
-                        mScrollX / maxScrollX : 0);
-            } else {
-                // textareas only need to be lined up vertically.
-                mWebView.scrollFocusedTextInputY(mScrollY);
-            }
-        }
-    }
-
-    @Override
-    protected void makeNewLayout(int w, int hintWidth, Metrics boring,
-            Metrics hintBoring, int ellipsisWidth, boolean bringIntoView) {
-        // Necessary to get a Layout to work with, and to do the other work that
-        // makeNewLayout does.
-        super.makeNewLayout(w, hintWidth, boring, hintBoring, ellipsisWidth,
-                bringIntoView);
-        lineUpScroll();
-    }
-
-    /**
-     * Custom layout which figures out its line spacing.  If -1 is passed in for
-     * the height, it will use the ascent and descent from the paint to
-     * determine the line spacing.  Otherwise it will use the spacing provided.
-     */
-    private static class WebTextViewLayout extends DynamicLayout {
-        private float mLineHeight;
-        private float mDifference;
-        public WebTextViewLayout(CharSequence base, CharSequence display,
-                TextPaint paint,
-                int width, Alignment align,
-                float spacingMult, float spacingAdd,
-                boolean includepad,
-                TextUtils.TruncateAt ellipsize, int ellipsizedWidth,
-                float lineHeight) {
-            super(base, display, paint, width, align, spacingMult, spacingAdd,
-                    includepad, ellipsize, ellipsizedWidth);
-            float paintLineHeight = paint.descent() - paint.ascent();
-            if (lineHeight == -1f) {
-                mLineHeight = paintLineHeight;
-                mDifference = 0f;
-            } else {
-                mLineHeight = lineHeight;
-                // Through trial and error, I found this calculation to improve
-                // the accuracy of line placement.
-                mDifference = (lineHeight - paintLineHeight) / 2;
-            }
-        }
-
-        @Override
-        public int getLineTop(int line) {
-            return Math.round(mLineHeight * line - mDifference);
-        }
-    }
-
-    @Override public InputConnection onCreateInputConnection(
-            EditorInfo outAttrs) {
-        InputConnection connection = super.onCreateInputConnection(outAttrs);
-        if (mWebView != null) {
-            // Use the name of the textfield + the url.  Use backslash as an
-            // arbitrary separator.
-            outAttrs.fieldName = mWebView.nativeFocusCandidateName() + "\\"
-                    + mWebView.getUrl();
-        }
-        return connection;
-    }
-
-    @Override
-    public void onEditorAction(int actionCode) {
-        switch (actionCode) {
-        case EditorInfo.IME_ACTION_NEXT:
-            if (mWebView.nativeMoveCursorToNextTextInput()) {
-                // Preemptively rebuild the WebTextView, so that the action will
-                // be set properly.
-                mWebView.rebuildWebTextView();
-                setDefaultSelection();
-                mWebView.invalidate();
-            }
-            break;
-        case EditorInfo.IME_ACTION_DONE:
-            super.onEditorAction(actionCode);
-            break;
-        case EditorInfo.IME_ACTION_GO:
-        case EditorInfo.IME_ACTION_SEARCH:
-            // Send an enter and hide the soft keyboard
-            InputMethodManager.getInstance(mContext)
-                    .hideSoftInputFromWindow(getWindowToken(), 0);
-            sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
-                    KeyEvent.KEYCODE_ENTER));
-            sendDomEvent(new KeyEvent(KeyEvent.ACTION_UP,
-                    KeyEvent.KEYCODE_ENTER));
-
-        default:
-            break;
-        }
-    }
-
-    @Override
-    protected void onFocusChanged(boolean focused, int direction,
-            Rect previouslyFocusedRect) {
-        mFromFocusChange = true;
-        super.onFocusChanged(focused, direction, previouslyFocusedRect);
-        if (focused) {
-            mWebView.setActive(true);
-        } else if (!mInsideRemove) {
-            mWebView.setActive(false);
-        }
-        mFromFocusChange = false;
-    }
-
-    // AdapterView.OnItemClickListener implementation
-
-    @Override
-    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-        if (id == 0 && position == 0) {
-            // Blank out the text box while we wait for WebCore to fill the form.
-            replaceText("");
-            WebSettings settings = mWebView.getSettings();
-            if (mAutoFillProfileIsSet) {
-                // Call a webview method to tell WebCore to autofill the form.
-                mWebView.autoFillForm(mQueryId);
-            } else {
-                // There is no autofill profile setup yet and the user has
-                // elected to try and set one up. Call through to the
-                // embedder to action that.
-                mWebView.getWebChromeClient().setupAutoFill(
-                        mHandler.obtainMessage(AUTOFILL_FORM));
-            }
-        }
-    }
-
-    @Override
-    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
-        super.onScrollChanged(l, t, oldl, oldt);
-        lineUpScroll();
-    }
-
-    @Override
-    protected void onSelectionChanged(int selStart, int selEnd) {
-        if (!mFromWebKit && !mFromFocusChange && !mFromSetInputType
-                && mWebView != null && !mInSetTextAndKeepSelection) {
-            if (DebugFlags.WEB_TEXT_VIEW) {
-                Log.v(LOGTAG, "onSelectionChanged selStart=" + selStart
-                        + " selEnd=" + selEnd);
-            }
-            mWebView.setSelection(selStart, selEnd);
-            lineUpScroll();
-        }
-    }
-
-    @Override
-    protected void onTextChanged(CharSequence s,int start,int before,int count){
-        super.onTextChanged(s, start, before, count);
-        String postChange = s.toString();
-        // Prevent calls to setText from invoking onTextChanged (since this will
-        // mean we are on a different textfield).  Also prevent the change when
-        // going from a textfield with a string of text to one with a smaller
-        // limit on text length from registering the onTextChanged event.
-        if (mPreChange == null || mPreChange.equals(postChange) ||
-                (mMaxLength > -1 && mPreChange.length() > mMaxLength &&
-                mPreChange.substring(0, mMaxLength).equals(postChange))) {
-            return;
-        }
-        if (0 == count) {
-            if (before > 0) {
-                // For this and all changes to the text, update our cache
-                updateCachedTextfield();
-                if (mGotDelete) {
-                    mGotDelete = false;
-                    int oldEnd = start + before;
-                    if (mDelSelEnd == oldEnd
-                            && (mDelSelStart == start
-                            || (mDelSelStart == oldEnd && before == 1))) {
-                        // If the selection is set up properly before the
-                        // delete, send the DOM events.
-                        sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
-                                KeyEvent.KEYCODE_DEL));
-                        sendDomEvent(new KeyEvent(KeyEvent.ACTION_UP,
-                                KeyEvent.KEYCODE_DEL));
-                        return;
-                    }
-                }
-                // This was simply a delete or a cut, so just delete the
-                // selection.
-                mWebView.deleteSelection(start, start + before);
-            }
-            mGotDelete = false;
-            // before should never be negative, so whether it was a cut
-            // (handled above), or before is 0, in which case nothing has
-            // changed, we should return.
-            return;
-        }
-        // Ensure that this flag gets cleared, since with autocorrect on, a
-        // delete key press may have a more complex result than deleting one
-        // character or the existing selection, so it will not get cleared
-        // above.
-        mGotDelete = false;
-        // Prefer sending javascript events, so when adding one character,
-        // don't replace the unchanged text.
-        if (count > 1 && before == count - 1) {
-            String replaceButOne =  mPreChange.subSequence(start,
-                    start + before).toString();
-            String replacedString = s.subSequence(start,
-                    start + before).toString();
-            if (replaceButOne.equals(replacedString)) {
-                // we're just adding one character
-                start += before;
-                before = 0;
-                count = 1;
-            }
-        }
-        mPreChange = postChange;
-        // Find the last character being replaced.  If it can be represented by
-        // events, we will pass them to native so we can see javascript events.
-        // Otherwise, replace the text being changed in the textfield.
-        KeyEvent[] events = null;
-        if (count == 1) {
-            TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
-            KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
-            events = kmap.getEvents(mCharacter);
-        }
-        boolean useKeyEvents = (events != null);
-        if (useKeyEvents) {
-            // This corrects the selection which may have been affected by the
-            // trackball or auto-correct.
-            if (DebugFlags.WEB_TEXT_VIEW) {
-                Log.v(LOGTAG, "onTextChanged start=" + start
-                        + " start + before=" + (start + before));
-            }
-            if (!mInSetTextAndKeepSelection) {
-                mWebView.setSelection(start, start + before);
-            }
-            int length = events.length;
-            for (int i = 0; i < length; i++) {
-                // We never send modifier keys to native code so don't send them
-                // here either.
-                if (!KeyEvent.isModifierKey(events[i].getKeyCode())) {
-                    sendDomEvent(events[i]);
-                }
-            }
-        } else {
-            String replace = s.subSequence(start,
-                    start + count).toString();
-            mWebView.replaceTextfieldText(start, start + before, replace,
-                    start + count,
-                    start + count);
-        }
-        updateCachedTextfield();
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent event) {
-        switch (event.getAction()) {
-        case MotionEvent.ACTION_DOWN:
-            super.onTouchEvent(event);
-            // This event may be the start of a drag, so store it to pass to the
-            // WebView if it is.
-            mDragStartX = event.getX();
-            mDragStartY = event.getY();
-            mDragStartTime = event.getEventTime();
-            mDragSent = false;
-            mScrolled = false;
-            mGotTouchDown = true;
-            mHasPerformedLongClick = false;
-            break;
-        case MotionEvent.ACTION_MOVE:
-            if (mHasPerformedLongClick) {
-                mGotTouchDown = false;
-                return false;
-            }
-            int slop = ViewConfiguration.get(mContext).getScaledTouchSlop();
-            Spannable buffer = getText();
-            int initialScrollX = Touch.getInitialScrollX(this, buffer);
-            int initialScrollY = Touch.getInitialScrollY(this, buffer);
-            super.onTouchEvent(event);
-            int dx = Math.abs(mScrollX - initialScrollX);
-            int dy = Math.abs(mScrollY - initialScrollY);
-            // Use a smaller slop when checking to see if we've moved far enough
-            // to scroll the text, because experimentally, slop has shown to be
-            // to big for the case of a small textfield.
-            int smallerSlop = slop/2;
-            if (dx > smallerSlop || dy > smallerSlop) {
-                // Scrolling is handled in onScrollChanged.
-                mScrolled = true;
-                cancelLongPress();
-                return true;
-            }
-            if (Math.abs((int) event.getX() - mDragStartX) < slop
-                    && Math.abs((int) event.getY() - mDragStartY) < slop) {
-                // If the user has not scrolled further than slop, we should not
-                // send the drag.  Instead, do nothing, and when the user lifts
-                // their finger, we will change the selection.
-                return true;
-            }
-            if (mWebView != null) {
-                // Only want to set the initial state once.
-                if (!mDragSent) {
-                    mWebView.initiateTextFieldDrag(mDragStartX, mDragStartY,
-                            mDragStartTime);
-                    mDragSent = true;
-                }
-                boolean scrolled = mWebView.textFieldDrag(event);
-                if (scrolled) {
-                    mScrolled = true;
-                    cancelLongPress();
-                    return true;
-                }
-            }
-            return false;
-        case MotionEvent.ACTION_UP:
-        case MotionEvent.ACTION_CANCEL:
-            super.onTouchEvent(event);
-            if (mHasPerformedLongClick) {
-                mGotTouchDown = false;
-                return false;
-            }
-            if (!mScrolled) {
-                // If the page scrolled, or the TextView scrolled, we do not
-                // want to change the selection
-                cancelLongPress();
-                if (mGotTouchDown && mWebView != null) {
-                    mWebView.touchUpOnTextField(event);
-                }
-            }
-            // Necessary for the WebView to reset its state
-            if (mWebView != null && mDragSent) {
-                mWebView.onTouchEvent(event);
-            }
-            mGotTouchDown = false;
-            break;
-        default:
-            break;
-        }
-        return true;
-    }
-
-    @Override
-    public boolean onTrackballEvent(MotionEvent event) {
-        if (isPopupShowing()) {
-            return super.onTrackballEvent(event);
-        }
-        if (event.getAction() != MotionEvent.ACTION_MOVE) {
-            return false;
-        }
-        Spannable text = getText();
-        MovementMethod move = getMovementMethod();
-        if (move != null && getLayout() != null &&
-            move.onTrackballEvent(this, text, event)) {
-            // Selection is changed in onSelectionChanged
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public boolean performLongClick() {
-        mHasPerformedLongClick = true;
-        return super.performLongClick();
-    }
-
-    /**
-     * Remove this WebTextView from its host WebView, and return
-     * focus to the host.
-     */
-    /* package */ void remove() {
-        // hide the soft keyboard when the edit text is out of focus
-        InputMethodManager imm = InputMethodManager.getInstance(mContext);
-        if (imm.isActive(this)) {
-            imm.hideSoftInputFromWindow(getWindowToken(), 0);
-        }
-        mInsideRemove = true;
-        boolean isFocused = hasFocus();
-        mWebView.getWebView().removeView(this);
-        if (isFocused) {
-            mWebView.getWebView().requestFocus();
-        }
-        mInsideRemove = false;
-        mHandler.removeCallbacksAndMessages(null);
-    }
-
-    @Override
-    public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
-        // Do nothing, since webkit will put the textfield on screen.
-        return true;
-    }
-
-    /**
-     *  Send the DOM events for the specified event.
-     *  @param event    KeyEvent to be translated into a DOM event.
-     */
-    private void sendDomEvent(KeyEvent event) {
-        mWebView.passToJavaScript(getText().toString(), event);
-    }
-
-    /**
-     *  Always use this instead of setAdapter, as this has features specific to
-     *  the WebTextView.
-     */
-    public void setAdapterCustom(AutoCompleteAdapter adapter) {
-        if (adapter != null) {
-            setInputType(getInputType()
-                    | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
-            adapter.setTextView(this);
-            if (mAutoFillable) {
-                setOnItemClickListener(this);
-            } else {
-                setOnItemClickListener(null);
-            }
-            showDropDown();
-        } else {
-            dismissDropDown();
-        }
-        super.setAdapter(adapter);
-    }
-
-    /**
-     *  This is a special version of ArrayAdapter which changes its text size
-     *  to match the text size of its host TextView.
-     */
-    public static class AutoCompleteAdapter extends ArrayAdapter<String> {
-        private TextView mTextView;
-
-        public AutoCompleteAdapter(Context context, ArrayList<String> entries) {
-            super(context, com.android.internal.R.layout
-                    .web_text_view_dropdown, entries);
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        @Override
-        public View getView(int position, View convertView, ViewGroup parent) {
-            TextView tv =
-                    (TextView) super.getView(position, convertView, parent);
-            if (tv != null && mTextView != null) {
-                tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextView.getTextSize());
-            }
-            return tv;
-        }
-
-        /**
-         * Set the TextView so we can match its text size.
-         */
-        private void setTextView(TextView tv) {
-            mTextView = tv;
-        }
-    }
-
-    /**
-     * Sets the selection when the user clicks on a textfield or textarea with
-     * the trackball or center key, or starts typing into it without clicking on
-     * it.
-     */
-    /* package */ void setDefaultSelection() {
-        Spannable text = (Spannable) getText();
-        int selection = mSingle ? text.length() : 0;
-        if (Selection.getSelectionStart(text) == selection
-                && Selection.getSelectionEnd(text) == selection) {
-            // The selection of the UI copy is set correctly, but the
-            // WebTextView still needs to inform the webkit thread to set the
-            // selection.  Normally that is done in onSelectionChanged, but
-            // onSelectionChanged will not be called because the UI copy is not
-            // changing.  (This can happen when the WebTextView takes focus.
-            // That onSelectionChanged was blocked because the selection set
-            // when focusing is not necessarily the desirable selection for
-            // WebTextView.)
-            if (mWebView != null) {
-                mWebView.setSelection(selection, selection);
-            }
-        } else {
-            Selection.setSelection(text, selection, selection);
-        }
-        if (mWebView != null) mWebView.incrementTextGeneration();
-    }
-
-    @Override
-    public void setInputType(int type) {
-        mFromSetInputType = true;
-        super.setInputType(type);
-        mFromSetInputType = false;
-    }
-
-    private void setMaxLength(int maxLength) {
-        mMaxLength = maxLength;
-        if (-1 == maxLength) {
-            setFilters(NO_FILTERS);
-        } else {
-            setFilters(new InputFilter[] {
-                new InputFilter.LengthFilter(maxLength) });
-        }
-    }
-
-    /**
-     *  Set the pointer for this node so it can be determined which node this
-     *  WebTextView represents.
-     *  @param  ptr Integer representing the pointer to the node which this
-     *          WebTextView represents.
-     */
-    /* package */ void setNodePointer(int ptr) {
-        if (ptr != mNodePointer) {
-            mNodePointer = ptr;
-            setAdapterCustom(null);
-        }
-    }
-
-    /**
-     * Determine the position and size of WebTextView, and add it to the
-     * WebView's view heirarchy.  All parameters are presumed to be in
-     * view coordinates.  Also requests Focus and sets the cursor to not
-     * request to be in view.
-     * @param x         x-position of the textfield.
-     * @param y         y-position of the textfield.
-     * @param width     width of the textfield.
-     * @param height    height of the textfield.
-     */
-    /* package */ void setRect(int x, int y, int width, int height) {
-        LayoutParams lp = (LayoutParams) getLayoutParams();
-        x -= mRingInset;
-        y -= mRingInset;
-        width += 2 * mRingInset;
-        height += 2 * mRingInset;
-        boolean needsUpdate = false;
-        if (null == lp) {
-            lp = new LayoutParams(width, height, x, y);
-        } else {
-            if ((lp.x != x) || (lp.y != y) || (lp.width != width)
-                    || (lp.height != height)) {
-                needsUpdate = true;
-                lp.x = x;
-                lp.y = y;
-                lp.width = width;
-                lp.height = height;
-            }
-        }
-        if (getParent() == null) {
-            // Insert the view so that it's drawn first (at index 0)
-            mWebView.getWebView().addView(this, 0, lp);
-        } else if (needsUpdate) {
-            setLayoutParams(lp);
-        }
-        // Set up a measure spec so a layout can always be recreated.
-        mWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
-        mHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
-    }
-
-    /**
-     * Set the selection, and disable our onSelectionChanged action.
-     */
-    /* package */ void setSelectionFromWebKit(int start, int end) {
-        if (start < 0 || end < 0) return;
-        Spannable text = (Spannable) getText();
-        int length = text.length();
-        if (start > length || end > length) return;
-        mFromWebKit = true;
-        Selection.setSelection(text, start, end);
-        mFromWebKit = false;
-    }
-
-    /**
-     * Update the text size according to the size of the focus candidate's text
-     * size in mWebView.  Should only be called from mWebView.
-     */
-    /* package */ void updateTextSize() {
-        Assert.assertNotNull("updateTextSize should only be called from "
-                + "mWebView, so mWebView should never be null!", mWebView);
-        // Note that this is approximately WebView.contentToViewDimension,
-        // without being rounded.
-        float size = mWebView.nativeFocusCandidateTextSize()
-                * mWebView.getScale();
-        setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
-    }
-
-    /**
-     * Set the text to the new string, but use the old selection, making sure
-     * to keep it within the new string.
-     * @param   text    The new text to place in the textfield.
-     */
-    /* package */ void setTextAndKeepSelection(String text) {
-        Editable edit = getText();
-        mPreChange = text;
-        if (edit.toString().equals(text)) {
-            return;
-        }
-        int selStart = Selection.getSelectionStart(edit);
-        int selEnd = Selection.getSelectionEnd(edit);
-        mInSetTextAndKeepSelection = true;
-        edit.replace(0, edit.length(), text);
-        int newLength = edit.length();
-        if (selStart > newLength) selStart = newLength;
-        if (selEnd > newLength) selEnd = newLength;
-        Selection.setSelection(edit, selStart, selEnd);
-        mInSetTextAndKeepSelection = false;
-        InputMethodManager imm = InputMethodManager.peekInstance();
-        if (imm != null && imm.isActive(this)) {
-            // Since the text has changed, do not allow the IME to replace the
-            // existing text as though it were a completion.
-            imm.restartInput(this);
-        }
-        updateCachedTextfield();
-    }
-
-    /**
-     * Called by WebView.rebuildWebTextView().  Based on the type of the <input>
-     * element, set up the WebTextView, its InputType, and IME Options properly.
-     * @param type int corresponding to enum "Type" defined in CachedInput.h.
-     *              Does not correspond to HTMLInputElement::InputType so this
-     *              is unaffected if that changes, and also because that has no
-     *              type corresponding to textarea (which is its own tag).
-     */
-    /* package */ void setType(int type) {
-        if (mWebView == null) return;
-        boolean single = true;
-        int maxLength = -1;
-        int inputType = InputType.TYPE_CLASS_TEXT
-                | InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
-        int imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
-                | EditorInfo.IME_FLAG_NO_FULLSCREEN;
-        if (!mWebView.nativeFocusCandidateIsSpellcheck()) {
-            inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
-        }
-        if (TEXT_AREA != type
-                && mWebView.nativeFocusCandidateHasNextTextfield()) {
-            imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_NEXT;
-        }
-        switch (type) {
-            case NORMAL_TEXT_FIELD:
-                imeOptions |= EditorInfo.IME_ACTION_GO;
-                break;
-            case TEXT_AREA:
-                single = false;
-                inputType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE
-                        | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
-                        | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
-                imeOptions |= EditorInfo.IME_ACTION_NONE;
-                break;
-            case PASSWORD:
-                inputType |= EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD;
-                imeOptions |= EditorInfo.IME_ACTION_GO;
-                break;
-            case SEARCH:
-                imeOptions |= EditorInfo.IME_ACTION_SEARCH;
-                break;
-            case EMAIL:
-                // inputType needs to be overwritten because of the different text variation.
-                inputType = InputType.TYPE_CLASS_TEXT
-                        | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
-                imeOptions |= EditorInfo.IME_ACTION_GO;
-                break;
-            case NUMBER:
-                // inputType needs to be overwritten because of the different class.
-                inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL
-                        | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
-                // Number and telephone do not have both a Tab key and an
-                // action, so set the action to NEXT
-                imeOptions |= EditorInfo.IME_ACTION_NEXT;
-                break;
-            case TELEPHONE:
-                // inputType needs to be overwritten because of the different class.
-                inputType = InputType.TYPE_CLASS_PHONE;
-                imeOptions |= EditorInfo.IME_ACTION_NEXT;
-                break;
-            case URL:
-                // TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so
-                // exclude it for now.
-                imeOptions |= EditorInfo.IME_ACTION_GO;
-                break;
-            default:
-                imeOptions |= EditorInfo.IME_ACTION_GO;
-                break;
-        }
-        setHint(null);
-        setThreshold(1);
-        boolean autoComplete = false;
-        if (single) {
-            mWebView.requestLabel(mWebView.nativeFocusCandidateFramePointer(),
-                    mNodePointer);
-            maxLength = mWebView.nativeFocusCandidateMaxLength();
-            autoComplete = mWebView.nativeFocusCandidateIsAutoComplete();
-            if (type != PASSWORD && (mAutoFillable || autoComplete)) {
-                String name = mWebView.nativeFocusCandidateName();
-                if (name != null && name.length() > 0) {
-                    mWebView.requestFormData(name, mNodePointer, mAutoFillable,
-                            autoComplete);
-                }
-            }
-        }
-        mSingle = single;
-        setMaxLength(maxLength);
-        setHorizontallyScrolling(single);
-        setInputType(inputType);
-        clearComposingText();
-        setImeOptions(imeOptions);
-        setVisibility(VISIBLE);
-        if (!autoComplete) {
-            setAdapterCustom(null);
-        }
-    }
-
-    /**
-     *  Update the cache to reflect the current text.
-     */
-    /* package */ void updateCachedTextfield() {
-        mWebView.updateCachedTextfield(getText().toString());
-    }
-
-    /* package */ void setAutoFillProfileIsSet(boolean autoFillProfileIsSet) {
-        mAutoFillProfileIsSet = autoFillProfileIsSet;
-    }
+    static final int FORM_NOT_AUTOFILLABLE = -1;
 
     static String urlForAutoCompleteData(String urlString) {
         // Remove any fragment or query string.
@@ -1182,10 +50,4 @@
         return url != null ? url.getProtocol() + "://" + url.getHost() + url.getPath() : null;
     }
 
-    public void setGravityForRtl(boolean rtl) {
-        int gravity = rtl ? Gravity.RIGHT : Gravity.LEFT;
-        gravity |= mSingle ? Gravity.CENTER_VERTICAL : Gravity.TOP;
-        setGravity(gravity);
-    }
-
 }
diff --git a/core/java/android/webkit/WebViewClassic.java b/core/java/android/webkit/WebViewClassic.java
index 76fc8f4..c9a3ff1 100644
--- a/core/java/android/webkit/WebViewClassic.java
+++ b/core/java/android/webkit/WebViewClassic.java
@@ -67,7 +67,6 @@
 import android.text.InputType;
 import android.text.Selection;
 import android.text.TextUtils;
-import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
 import android.util.Log;
@@ -97,8 +96,6 @@
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
 import android.view.inputmethod.InputMethodManager;
-import android.webkit.HTML5VideoInline;
-import android.webkit.WebTextView.AutoCompleteAdapter;
 import android.webkit.WebView.HitTestResult;
 import android.webkit.WebView.PictureListener;
 import android.webkit.WebViewCore.DrawData;
@@ -353,6 +350,7 @@
 // TODO: Check if any WebView published API methods are called from within here, and if so
 // we should bounce the call out via the proxy to enable any sub-class to override it.
 @Widget
+@SuppressWarnings("deprecation")
 public final class WebViewClassic implements WebViewProvider, WebViewProvider.ScrollDelegate,
         WebViewProvider.ViewDelegate {
     private class InnerGlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
@@ -852,7 +850,6 @@
     private WebViewCore mWebViewCore;
     // Handler for dispatching UI messages.
     /* package */ final Handler mPrivateHandler = new PrivateHandler();
-    private WebTextView mWebTextView;
     // Used to ignore changes to webkit text that arrives to the UI side after
     // more key events.
     private int mTextGeneration;
@@ -964,10 +961,6 @@
     private float mLastDeferTouchX;
     private float mLastDeferTouchY;
 
-    // To keep track of whether the current drag was initiated by a WebTextView,
-    // so that we know not to hide the cursor
-    boolean mDragFromTextInput;
-
     // Whether or not to draw the cursor ring.
     private boolean mDrawCursorRing = true;
 
@@ -1079,8 +1072,6 @@
     static final int HANDLE_ID_BASE = 2;
     static final int HANDLE_ID_EXTENT = 3;
 
-    static boolean sDisableNavcache = false;
-    static boolean sEnableWebTextView = false;
     // the color used to highlight the touch rectangles
     static final int HIGHLIGHT_COLOR = 0x6633b5e5;
     // the region indicating where the user touched on the screen
@@ -1113,7 +1104,6 @@
     private static final int SWITCH_TO_SHORTPRESS       = 3;
     private static final int SWITCH_TO_LONGPRESS        = 4;
     private static final int RELEASE_SINGLE_TAP         = 5;
-    private static final int REQUEST_FORM_DATA          = 6;
     private static final int DRAG_HELD_MOTIONLESS       = 8;
     private static final int AWAKEN_SCROLL_BARS         = 9;
     private static final int PREVENT_DEFAULT_TIMEOUT    = 10;
@@ -1128,7 +1118,6 @@
      */
     static final int SCROLL_TO_MSG_ID                   = 101;
     static final int NEW_PICTURE_MSG_ID                 = 105;
-    static final int UPDATE_TEXT_ENTRY_MSG_ID           = 106;
     static final int WEBCORE_INITIALIZED_MSG_ID         = 107;
     static final int UPDATE_TEXTFIELD_TEXT_MSG_ID       = 108;
     static final int UPDATE_ZOOM_RANGE                  = 109;
@@ -1142,13 +1131,10 @@
     // obj=Rect in doc coordinates
     static final int INVAL_RECT_MSG_ID                  = 117;
     static final int REQUEST_KEYBOARD                   = 118;
-    static final int DO_MOTION_UP                       = 119;
     static final int SHOW_FULLSCREEN                    = 120;
     static final int HIDE_FULLSCREEN                    = 121;
-    static final int DOM_FOCUS_CHANGED                  = 122;
     static final int REPLACE_BASE_CONTENT               = 123;
     static final int FORM_DID_BLUR                      = 124;
-    static final int RETURN_LABEL                       = 125;
     static final int UPDATE_MATCH_COUNT                 = 126;
     static final int CENTER_FIT_RECT                    = 127;
     static final int REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID = 128;
@@ -1160,10 +1146,8 @@
     static final int SET_AUTOFILLABLE                   = 133;
     static final int AUTOFILL_COMPLETE                  = 134;
 
-    static final int SELECT_AT                          = 135;
     static final int SCREEN_ON                          = 136;
     static final int ENTER_FULLSCREEN_VIDEO             = 137;
-    static final int UPDATE_SELECTION                   = 138;
     static final int UPDATE_ZOOM_DENSITY                = 139;
     static final int EXIT_FULLSCREEN_VIDEO              = 140;
 
@@ -1695,7 +1679,6 @@
 
     private void init() {
         OnTrimMemoryListener.init(mContext);
-        sDisableNavcache = nativeDisableNavcache();
         mWebView.setWillNotDraw(false);
         mWebView.setFocusable(true);
         mWebView.setFocusableInTouchMode(true);
@@ -2082,10 +2065,10 @@
     /**
      * Called to clear state when moving from one page to another, or changing
      * in some other way that makes elements associated with the current page
-     * (such as WebTextView or ActionModes) no longer relevant.
+     * (such as ActionModes) no longer relevant.
      */
     private void clearHelpers() {
-        clearTextEntry();
+        hideSoftKeyboard();
         clearActionModes();
         dismissFullScreenMode();
         cancelSelectDialog();
@@ -2114,17 +2097,8 @@
             mListBoxDialog.dismiss();
             mListBoxDialog = null;
         }
-        // remove so that it doesn't cause events
-        if (mWebTextView != null) {
-            mWebTextView.remove();
-            mWebTextView = null;
-        }
         if (mNativeClass != 0) nativeStopGL();
         if (mWebViewCore != null) {
-            // Set the handlers to null before destroying WebViewCore so no
-            // more messages will be posted.
-            mCallbackProxy.setWebViewClient(null);
-            mCallbackProxy.setWebChromeClient(null);
             // Tell WebViewCore to destroy itself
             synchronized (this) {
                 WebViewCore webViewCore = mWebViewCore;
@@ -2133,12 +2107,6 @@
             }
             // Remove any pending messages that might not be serviced yet.
             mPrivateHandler.removeCallbacksAndMessages(null);
-            mCallbackProxy.removeCallbacksAndMessages(null);
-            // Wake up the WebCore thread just in case it is waiting for a
-            // JavaScript dialog.
-            synchronized (mCallbackProxy) {
-                mCallbackProxy.notify();
-            }
         }
         if (mNativeClass != 0) {
             nativeDestroy();
@@ -2843,7 +2811,6 @@
         if (mNativeClass == 0) {
             return false;
         }
-        nativeClearCursor(); // start next trackball movement from page edge
         if (top) {
             // go to the top of the document
             return pinScrollTo(getScrollX(), 0, true, 0);
@@ -2870,7 +2837,6 @@
         if (mNativeClass == 0) {
             return false;
         }
-        nativeClearCursor(); // start next trackball movement from page edge
         if (bottom) {
             return pinScrollTo(getScrollX(), computeRealVerticalScrollRange(), true, 0);
         }
@@ -2916,25 +2882,6 @@
     }
 
     /**
-     *  Return true if the browser is displaying a TextView for text input.
-     */
-    private boolean inEditingMode() {
-        return mWebTextView != null && mWebTextView.getParent() != null;
-    }
-
-    /**
-     * Remove the WebTextView.
-     */
-    private void clearTextEntry() {
-        if (inEditingMode()) {
-            mWebTextView.remove();
-        } else {
-            // The keyboard may be open with the WebView as the served view
-            hideSoftKeyboard();
-        }
-    }
-
-    /**
      * Return the current scale of the WebView
      * @return The current scale.
      */
@@ -3002,71 +2949,13 @@
      */
     public HitTestResult getHitTestResult() {
         checkThread();
-        return hitTestResult(mInitialHitTestResult);
+        return mInitialHitTestResult;
     }
 
-    private HitTestResult hitTestResult(HitTestResult fallback) {
-        if (mNativeClass == 0 || sDisableNavcache) {
-            return fallback;
-        }
-
-        HitTestResult result = new HitTestResult();
-        if (nativeHasCursorNode()) {
-            if (nativeCursorIsTextInput()) {
-                result.setType(HitTestResult.EDIT_TEXT_TYPE);
-            } else {
-                String text = nativeCursorText();
-                if (text != null) {
-                    if (text.startsWith(SCHEME_TEL)) {
-                        result.setType(HitTestResult.PHONE_TYPE);
-                        result.setExtra(URLDecoder.decode(text
-                                .substring(SCHEME_TEL.length())));
-                    } else if (text.startsWith(SCHEME_MAILTO)) {
-                        result.setType(HitTestResult.EMAIL_TYPE);
-                        result.setExtra(text.substring(SCHEME_MAILTO.length()));
-                    } else if (text.startsWith(SCHEME_GEO)) {
-                        result.setType(HitTestResult.GEO_TYPE);
-                        result.setExtra(URLDecoder.decode(text
-                                .substring(SCHEME_GEO.length())));
-                    } else if (nativeCursorIsAnchor()) {
-                        result.setType(HitTestResult.SRC_ANCHOR_TYPE);
-                        result.setExtra(text);
-                    }
-                }
-            }
-        } else if (fallback != null) {
-            /* If webkit causes a rebuild while the long press is in progress,
-             * the cursor node may be reset, even if it is still around. This
-             * uses the cursor node saved when the touch began. Since the
-             * nativeImageURI below only changes the result if it is successful,
-             * this uses the data beneath the touch if available or the original
-             * tap data otherwise.
-             */
-            Log.v(LOGTAG, "hitTestResult use fallback");
-            result = fallback;
-        }
-        int type = result.getType();
-        if (type == HitTestResult.UNKNOWN_TYPE
-                || type == HitTestResult.SRC_ANCHOR_TYPE) {
-            // Now check to see if it is an image.
-            int contentX = viewToContentX(mLastTouchX + getScrollX());
-            int contentY = viewToContentY(mLastTouchY + getScrollY());
-            String text = nativeImageURI(contentX, contentY);
-            if (text != null) {
-                result.setType(type == HitTestResult.UNKNOWN_TYPE ?
-                        HitTestResult.IMAGE_TYPE :
-                        HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
-                result.setExtra(text);
-            }
-        }
-        return result;
-    }
+    // No left edge for double-tap zoom alignment
+    static final int NO_LEFTEDGE = -1;
 
     int getBlockLeftEdge(int x, int y, float readingScale) {
-        if (!sDisableNavcache) {
-            return nativeGetBlockLeftEdge(x, y, readingScale);
-        }
-
         float invReadingScale = 1.0f / readingScale;
         int readingWidth = (int) (getViewWidth() * invReadingScale);
         int left = NO_LEFTEDGE;
@@ -3090,13 +2979,6 @@
         return left;
     }
 
-    // Called by JNI when the DOM has changed the focus.  Clear the focus so
-    // that new keys will go to the newly focused field
-    private void domChangedFocus() {
-        if (inEditingMode()) {
-            mPrivateHandler.obtainMessage(DOM_FOCUS_CHANGED).sendToTarget();
-        }
-    }
     /**
      * Request the anchor or image element URL at the last tapped point.
      * If hrefMsg is null, this method returns immediately and does not
@@ -3126,17 +3008,6 @@
             hrefMsg.sendToTarget();
             return;
         }
-        if (nativeHasCursorNode()) {
-            Rect cursorBounds = cursorRingBounds();
-            if (!cursorBounds.contains(contentX, contentY)) {
-                int slop = viewToContentDimension(mNavSlop);
-                cursorBounds.inset(-slop, -slop);
-                if (cursorBounds.contains(contentX, contentY)) {
-                    contentX = cursorBounds.centerX();
-                    contentY = cursorBounds.centerY();
-                }
-            }
-        }
         mWebViewCore.sendMessage(EventHub.REQUEST_CURSOR_HREF,
                 contentX, contentY, hrefMsg);
     }
@@ -3151,11 +3022,9 @@
     public void requestImageRef(Message msg) {
         checkThread();
         if (0 == mNativeClass) return; // client isn't initialized
-        int contentX = viewToContentX(mLastTouchX + getScrollX());
-        int contentY = viewToContentY(mLastTouchY + getScrollY());
-        String ref = nativeImageURI(contentX, contentY);
+        String url = mFocusedNode != null ? mFocusedNode.mImageUrl : null;
         Bundle data = msg.getData();
-        data.putString("url", ref);
+        data.putString("url", url);
         msg.setData(data);
         msg.sendToTarget();
     }
@@ -3247,8 +3116,7 @@
 
     /**
      * Given an x coordinate in view space, convert it to content space.  Also
-     * may be used for absolute heights (such as for the WebTextView's
-     * textSize, which is unaffected by the height of the title bar).
+     * may be used for absolute heights.
      */
     /*package*/ int viewToContentX(int x) {
         return viewToContentDimension(x);
@@ -3405,7 +3273,7 @@
                 mScrollOffset.set(mVisibleRect.left, mVisibleRect.top);
                 mWebViewCore.removeMessages(EventHub.SET_SCROLL_OFFSET);
                 mWebViewCore.sendMessage(EventHub.SET_SCROLL_OFFSET,
-                        nativeMoveGeneration(), mSendScrollEvent ? 1 : 0, mScrollOffset);
+                        mSendScrollEvent ? 1 : 0, mScrollOffset);
             }
             mLastVisibleRectSent.set(mVisibleRect);
             mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
@@ -3867,9 +3735,7 @@
      */
     public void clearFormData() {
         checkThread();
-        if (inEditingMode()) {
-            mWebTextView.setAdapterCustom(null);
-        }
+        // TODO: Implement b/6083041
     }
 
     /**
@@ -4008,8 +3874,6 @@
      */
     private void setFindIsUp(boolean isUp) {
         mFindIsUp = isUp;
-        if (0 == mNativeClass) return; // client isn't initialized
-        nativeSetFindIsUp(isUp);
     }
 
     // Used to know whether the find dialog is open.  Affects whether
@@ -4751,9 +4615,103 @@
         return false;  // We never call invalidate(), so unconditionally returning false.
     }
 
-    private void drawContent(Canvas canvas, boolean drawRings) {
-        drawCoreAndCursorRing(canvas, mBackgroundColor,
-                mDrawCursorRing && drawRings);
+    private void drawContent(Canvas canvas) {
+        if (mDrawHistory) {
+            canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
+            canvas.drawPicture(mHistoryPicture);
+            return;
+        }
+        if (mNativeClass == 0) return;
+
+        boolean animateZoom = mZoomManager.isFixedLengthAnimationInProgress();
+        boolean animateScroll = ((!mScroller.isFinished()
+                || mVelocityTracker != null)
+                && (mTouchMode != TOUCH_DRAG_MODE ||
+                mHeldMotionless != MOTIONLESS_TRUE))
+                || mDeferTouchMode == TOUCH_DRAG_MODE;
+        if (mTouchMode == TOUCH_DRAG_MODE) {
+            if (mHeldMotionless == MOTIONLESS_PENDING) {
+                mPrivateHandler.removeMessages(DRAG_HELD_MOTIONLESS);
+                mPrivateHandler.removeMessages(AWAKEN_SCROLL_BARS);
+                mHeldMotionless = MOTIONLESS_FALSE;
+            }
+            if (mHeldMotionless == MOTIONLESS_FALSE) {
+                mPrivateHandler.sendMessageDelayed(mPrivateHandler
+                        .obtainMessage(DRAG_HELD_MOTIONLESS), MOTIONLESS_TIME);
+                mPrivateHandler.sendMessageDelayed(mPrivateHandler
+                        .obtainMessage(AWAKEN_SCROLL_BARS),
+                            ViewConfiguration.getScrollDefaultDelay());
+                mHeldMotionless = MOTIONLESS_PENDING;
+            }
+        }
+        int saveCount = canvas.save();
+        if (animateZoom) {
+            mZoomManager.animateZoom(canvas);
+        } else if (!canvas.isHardwareAccelerated()) {
+            canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
+        }
+
+        boolean UIAnimationsRunning = false;
+        // Currently for each draw we compute the animation values;
+        // We may in the future decide to do that independently.
+        if (mNativeClass != 0 && !canvas.isHardwareAccelerated()
+                && nativeEvaluateLayersAnimations(mNativeClass)) {
+            UIAnimationsRunning = true;
+            // If we have unfinished (or unstarted) animations,
+            // we ask for a repaint. We only need to do this in software
+            // rendering (with hardware rendering we already have a different
+            // method of requesting a repaint)
+            mWebViewCore.sendMessage(EventHub.NOTIFY_ANIMATION_STARTED);
+            invalidate();
+        }
+
+        // decide which adornments to draw
+        int extras = DRAW_EXTRAS_NONE;
+        if (!mFindIsUp && mSelectingText) {
+            extras = DRAW_EXTRAS_SELECTION;
+        }
+
+        calcOurContentVisibleRectF(mVisibleContentRect);
+        if (canvas.isHardwareAccelerated()) {
+            Rect glRectViewport = mGLViewportEmpty ? null : mGLRectViewport;
+            Rect viewRectViewport = mGLViewportEmpty ? null : mViewRectViewport;
+
+            int functor = nativeGetDrawGLFunction(mNativeClass, glRectViewport,
+                    viewRectViewport, mVisibleContentRect, getScale(), extras);
+            ((HardwareCanvas) canvas).callDrawGLFunction(functor);
+            if (mHardwareAccelSkia != getSettings().getHardwareAccelSkiaEnabled()) {
+                mHardwareAccelSkia = getSettings().getHardwareAccelSkiaEnabled();
+                nativeUseHardwareAccelSkia(mHardwareAccelSkia);
+            }
+
+        } else {
+            DrawFilter df = null;
+            if (mZoomManager.isZoomAnimating() || UIAnimationsRunning) {
+                df = mZoomFilter;
+            } else if (animateScroll) {
+                df = mScrollFilter;
+            }
+            canvas.setDrawFilter(df);
+            // XXX: Revisit splitting content.  Right now it causes a
+            // synchronization problem with layers.
+            int content = nativeDraw(canvas, mVisibleContentRect, mBackgroundColor,
+                    extras, false);
+            canvas.setDrawFilter(null);
+            if (!mBlockWebkitViewMessages && content != 0) {
+                mWebViewCore.sendMessage(EventHub.SPLIT_PICTURE_SET, content, 0);
+            }
+        }
+
+        canvas.restoreToCount(saveCount);
+        if (mSelectingText) {
+            drawTextSelectionHandles(canvas);
+        }
+
+        if (extras == DRAW_EXTRAS_CURSOR_RING) {
+            if (mTouchMode == TOUCH_SHORTPRESS_START_MODE) {
+                mTouchMode = TOUCH_SHORTPRESS_MODE;
+            }
+        }
     }
 
     /**
@@ -4824,8 +4782,7 @@
         if (mTitleBar != null) {
             canvas.translate(0, getTitleHeight());
         }
-        boolean drawNativeRings = !sDisableNavcache;
-        drawContent(canvas, drawNativeRings);
+        drawContent(canvas);
         canvas.restoreToCount(saveCount);
 
         if (AUTO_REDRAW_HACK && mAutoRedraw) {
@@ -4895,28 +4852,6 @@
             return false;
         }
 
-        if (mNativeClass != 0 && nativeCursorIsTextInput()) {
-            // Send the click so that the textfield is in focus
-            centerKeyPressOnTextField();
-            rebuildWebTextView();
-        } else {
-            clearTextEntry();
-        }
-        if (inEditingMode()) {
-            // Since we just called rebuildWebTextView, the layout is not set
-            // properly.  Update it so it can correctly find the word to select.
-            mWebTextView.ensureLayout();
-            // Provide a touch down event to WebTextView, which will allow it
-            // to store the location to use in performLongClick.
-            AbsoluteLayout.LayoutParams params
-                    = (AbsoluteLayout.LayoutParams) mWebTextView.getLayoutParams();
-            MotionEvent fake = MotionEvent.obtain(mLastTouchTime,
-                    mLastTouchTime, MotionEvent.ACTION_DOWN,
-                    mLastTouchX - params.x + getScrollX(),
-                    mLastTouchY - params.y + getScrollY(), 0);
-            mWebTextView.dispatchTouchEvent(fake);
-            return mWebTextView.performLongClick();
-        }
         if (mSelectingText) return false; // long click does nothing on selection
         /* if long click brings up a context menu, the super function
          * returns true and we're done. Otherwise, nothing happened when
@@ -4979,69 +4914,6 @@
      */
     private SelectActionModeCallback mSelectCallback;
 
-    // These values are possible options for didUpdateWebTextViewDimensions.
-    private static final int FULLY_ON_SCREEN = 0;
-    private static final int INTERSECTS_SCREEN = 1;
-    private static final int ANYWHERE = 2;
-
-    /**
-     * Check to see if the focused textfield/textarea is still on screen.  If it
-     * is, update the the dimensions and location of WebTextView.  Otherwise,
-     * remove the WebTextView.  Should be called when the zoom level changes.
-     * @param intersection How to determine whether the textfield/textarea is
-     *        still on screen.
-     * @return boolean True if the textfield/textarea is still on screen and the
-     *         dimensions/location of WebTextView have been updated.
-     */
-    private boolean didUpdateWebTextViewDimensions(int intersection) {
-        Rect contentBounds = nativeFocusCandidateNodeBounds();
-        Rect vBox = contentToViewRect(contentBounds);
-        Rect visibleRect = new Rect();
-        calcOurVisibleRect(visibleRect);
-        offsetByLayerScrollPosition(vBox);
-        // If the textfield is on screen, place the WebTextView in
-        // its new place, accounting for our new scroll/zoom values,
-        // and adjust its textsize.
-        boolean onScreen;
-        switch (intersection) {
-            case FULLY_ON_SCREEN:
-                onScreen = visibleRect.contains(vBox);
-                break;
-            case INTERSECTS_SCREEN:
-                onScreen = Rect.intersects(visibleRect, vBox);
-                break;
-            case ANYWHERE:
-                onScreen = true;
-                break;
-            default:
-                throw new AssertionError(
-                        "invalid parameter passed to didUpdateWebTextViewDimensions");
-        }
-        if (onScreen) {
-            mWebTextView.setRect(vBox.left, vBox.top, vBox.width(),
-                    vBox.height());
-            mWebTextView.updateTextSize();
-            updateWebTextViewPadding();
-            return true;
-        } else {
-            // The textfield is now off screen.  The user probably
-            // was not zooming to see the textfield better.  Remove
-            // the WebTextView.  If the user types a key, and the
-            // textfield is still in focus, we will reconstruct
-            // the WebTextView and scroll it back on screen.
-            mWebTextView.remove();
-            return false;
-        }
-    }
-
-    private void offsetByLayerScrollPosition(Rect box) {
-        if ((mCurrentScrollingLayerId != 0)
-                && (mCurrentScrollingLayerId == nativeFocusCandidateLayerId())) {
-            box.offsetTo(box.left - mScrollingLayerRect.left,
-                    box.top - mScrollingLayerRect.top);
-        }
-    }
-
     void setBaseLayer(int layer, Region invalRegion, boolean showVisualIndicator,
             boolean isPictureAfterFirstLayout) {
         if (mNativeClass == 0)
@@ -5071,20 +4943,9 @@
     }
 
     private void onZoomAnimationStart() {
-        // If it is in password mode, turn it off so it does not draw misplaced.
-        if (inEditingMode()) {
-            mWebTextView.setVisibility(View.INVISIBLE);
-        }
     }
 
     private void onZoomAnimationEnd() {
-        // adjust the edit text view if needed
-        if (inEditingMode()
-                && didUpdateWebTextViewDimensions(FULLY_ON_SCREEN)) {
-            // If it is a password field, start drawing the WebTextView once
-            // again.
-            mWebTextView.setVisibility(View.VISIBLE);
-        }
     }
 
     void onFixedLengthZoomAnimationStart() {
@@ -5111,128 +4972,6 @@
     private final DrawFilter mScrollFilter =
             new PaintFlagsDrawFilter(SCROLL_BITS, 0);
 
-    private void drawCoreAndCursorRing(Canvas canvas, int color,
-        boolean drawCursorRing) {
-        if (mDrawHistory) {
-            canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
-            canvas.drawPicture(mHistoryPicture);
-            return;
-        }
-        if (mNativeClass == 0) return;
-
-        boolean animateZoom = mZoomManager.isFixedLengthAnimationInProgress();
-        boolean animateScroll = ((!mScroller.isFinished()
-                || mVelocityTracker != null)
-                && (mTouchMode != TOUCH_DRAG_MODE ||
-                mHeldMotionless != MOTIONLESS_TRUE))
-                || mDeferTouchMode == TOUCH_DRAG_MODE;
-        if (mTouchMode == TOUCH_DRAG_MODE) {
-            if (mHeldMotionless == MOTIONLESS_PENDING) {
-                mPrivateHandler.removeMessages(DRAG_HELD_MOTIONLESS);
-                mPrivateHandler.removeMessages(AWAKEN_SCROLL_BARS);
-                mHeldMotionless = MOTIONLESS_FALSE;
-            }
-            if (mHeldMotionless == MOTIONLESS_FALSE) {
-                mPrivateHandler.sendMessageDelayed(mPrivateHandler
-                        .obtainMessage(DRAG_HELD_MOTIONLESS), MOTIONLESS_TIME);
-                mPrivateHandler.sendMessageDelayed(mPrivateHandler
-                        .obtainMessage(AWAKEN_SCROLL_BARS),
-                            ViewConfiguration.getScrollDefaultDelay());
-                mHeldMotionless = MOTIONLESS_PENDING;
-            }
-        }
-        int saveCount = canvas.save();
-        if (animateZoom) {
-            mZoomManager.animateZoom(canvas);
-        } else if (!canvas.isHardwareAccelerated()) {
-            canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
-        }
-
-        boolean UIAnimationsRunning = false;
-        // Currently for each draw we compute the animation values;
-        // We may in the future decide to do that independently.
-        if (mNativeClass != 0 && !canvas.isHardwareAccelerated()
-                && nativeEvaluateLayersAnimations(mNativeClass)) {
-            UIAnimationsRunning = true;
-            // If we have unfinished (or unstarted) animations,
-            // we ask for a repaint. We only need to do this in software
-            // rendering (with hardware rendering we already have a different
-            // method of requesting a repaint)
-            mWebViewCore.sendMessage(EventHub.NOTIFY_ANIMATION_STARTED);
-            invalidate();
-        }
-
-        // decide which adornments to draw
-        int extras = DRAW_EXTRAS_NONE;
-        if (!mFindIsUp) {
-            if (mSelectingText) {
-                extras = DRAW_EXTRAS_SELECTION;
-            } else if (drawCursorRing) {
-                extras = DRAW_EXTRAS_CURSOR_RING;
-            }
-        }
-        if (DebugFlags.WEB_VIEW) {
-            Log.v(LOGTAG, "mFindIsUp=" + mFindIsUp
-                    + " mSelectingText=" + mSelectingText
-                    + " nativePageShouldHandleShiftAndArrows()="
-                    + nativePageShouldHandleShiftAndArrows()
-                    + " animateZoom=" + animateZoom
-                    + " extras=" + extras);
-        }
-
-        calcOurContentVisibleRectF(mVisibleContentRect);
-        if (canvas.isHardwareAccelerated()) {
-            Rect glRectViewport = mGLViewportEmpty ? null : mGLRectViewport;
-            Rect viewRectViewport = mGLViewportEmpty ? null : mViewRectViewport;
-
-            int functor = nativeGetDrawGLFunction(mNativeClass, glRectViewport,
-                    viewRectViewport, mVisibleContentRect, getScale(), extras);
-            ((HardwareCanvas) canvas).callDrawGLFunction(functor);
-            if (mHardwareAccelSkia != getSettings().getHardwareAccelSkiaEnabled()) {
-                mHardwareAccelSkia = getSettings().getHardwareAccelSkiaEnabled();
-                nativeUseHardwareAccelSkia(mHardwareAccelSkia);
-            }
-
-        } else {
-            DrawFilter df = null;
-            if (mZoomManager.isZoomAnimating() || UIAnimationsRunning) {
-                df = mZoomFilter;
-            } else if (animateScroll) {
-                df = mScrollFilter;
-            }
-            canvas.setDrawFilter(df);
-            // XXX: Revisit splitting content.  Right now it causes a
-            // synchronization problem with layers.
-            int content = nativeDraw(canvas, mVisibleContentRect, color,
-                    extras, false);
-            canvas.setDrawFilter(null);
-            if (!mBlockWebkitViewMessages && content != 0) {
-                mWebViewCore.sendMessage(EventHub.SPLIT_PICTURE_SET, content, 0);
-            }
-        }
-
-        canvas.restoreToCount(saveCount);
-        if (mSelectingText) {
-            drawTextSelectionHandles(canvas);
-        }
-
-        if (extras == DRAW_EXTRAS_CURSOR_RING) {
-            if (mTouchMode == TOUCH_SHORTPRESS_START_MODE) {
-                mTouchMode = TOUCH_SHORTPRESS_MODE;
-            }
-        }
-        if (mFocusSizeChanged) {
-            mFocusSizeChanged = false;
-            // If we are zooming, this will get handled above, when the zoom
-            // finishes.  We also do not need to do this unless the WebTextView
-            // is showing. With hardware acceleration, the pageSwapCallback()
-            // updates the WebTextView position in sync with page swapping
-            if (!canvas.isHardwareAccelerated() && !animateZoom && inEditingMode()) {
-                didUpdateWebTextViewDimensions(ANYWHERE);
-            }
-        }
-    }
-
     private void ensureSelectionHandles() {
         if (mSelectHandleCenter == null) {
             mSelectHandleCenter = mContext.getResources().getDrawable(
@@ -5330,25 +5069,6 @@
         }
     }
 
-    // TODO: Remove this
-    WebViewCore.CursorData cursorData() {
-        if (sDisableNavcache) {
-            return new WebViewCore.CursorData(0, 0, 0, 0);
-        }
-        WebViewCore.CursorData result = cursorDataNoPosition();
-        Point position = nativeCursorPosition();
-        result.mX = position.x;
-        result.mY = position.y;
-        return result;
-    }
-
-    WebViewCore.CursorData cursorDataNoPosition() {
-        WebViewCore.CursorData result = new WebViewCore.CursorData();
-        result.mMoveGeneration = nativeMoveGeneration();
-        result.mFrame = nativeCursorFramePointer();
-        return result;
-    }
-
     /**
      *  Delete text from start to end in the focused textfield. If there is no
      *  focus, or if start == end, silently fail.  If start and end are out of
@@ -5399,16 +5119,6 @@
             mZoomManager.setZoomCenter(mLastTouchX, mLastTouchY);
             mZoomManager.setZoomScale(mZoomManager.getDefaultScale(), false);
         }
-        if (isTextView) {
-            rebuildWebTextView();
-            if (inEditingMode()) {
-                imm.showSoftInput(mWebTextView, 0, mWebTextView.getResultReceiver());
-                if (zoom) {
-                    didUpdateWebTextViewDimensions(INTERSECTS_SCREEN);
-                }
-                return;
-            }
-        }
         // Used by plugins and contentEditable.
         // Also used if the navigation cache is out of date, and
         // does not recognize that a textfield is in focus.  In that
@@ -5420,202 +5130,11 @@
     // Called by WebKit to instruct the UI to hide the keyboard
     private void hideSoftKeyboard() {
         InputMethodManager imm = InputMethodManager.peekInstance();
-        if (imm != null && (imm.isActive(mWebView)
-                || (inEditingMode() && imm.isActive(mWebTextView)))) {
+        if (imm != null && (imm.isActive(mWebView))) {
             imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
         }
     }
 
-    /*
-     * This method checks the current focus and cursor and potentially rebuilds
-     * mWebTextView to have the appropriate properties, such as password,
-     * multiline, and what text it contains.  It also removes it if necessary.
-     */
-    /* package */ void rebuildWebTextView() {
-        if (!sEnableWebTextView) {
-            return; // always use WebKit's text entry
-        }
-        // If the WebView does not have focus, do nothing until it gains focus.
-        if (!mWebView.hasFocus() && (null == mWebTextView || !mWebTextView.hasFocus())) {
-            return;
-        }
-        boolean alreadyThere = inEditingMode();
-        // inEditingMode can only return true if mWebTextView is non-null,
-        // so we can safely call remove() if (alreadyThere)
-        if (0 == mNativeClass || !nativeFocusCandidateIsTextInput()) {
-            if (alreadyThere) {
-                mWebTextView.remove();
-            }
-            return;
-        }
-        // At this point, we know we have found an input field, so go ahead
-        // and create the WebTextView if necessary.
-        if (mWebTextView == null) {
-            mWebTextView = new WebTextView(mContext, WebViewClassic.this, mAutoFillData.getQueryId());
-            // Initialize our generation number.
-            mTextGeneration = 0;
-        }
-        mWebTextView.updateTextSize();
-        updateWebTextViewPosition();
-        String text = nativeFocusCandidateText();
-        int nodePointer = nativeFocusCandidatePointer();
-        // This needs to be called before setType, which may call
-        // requestFormData, and it needs to have the correct nodePointer.
-        mWebTextView.setNodePointer(nodePointer);
-        mWebTextView.setType(nativeFocusCandidateType());
-        // Gravity needs to be set after setType
-        mWebTextView.setGravityForRtl(nativeFocusCandidateIsRtlText());
-        if (null == text) {
-            if (DebugFlags.WEB_VIEW) {
-                Log.v(LOGTAG, "rebuildWebTextView null == text");
-            }
-            text = "";
-        }
-        mWebTextView.setTextAndKeepSelection(text);
-        InputMethodManager imm = InputMethodManager.peekInstance();
-        if (imm != null && imm.isActive(mWebTextView)) {
-            imm.restartInput(mWebTextView);
-            mWebTextView.clearComposingText();
-        }
-        if (mWebView.isFocused()) {
-            mWebTextView.requestFocus();
-        }
-    }
-
-    private void updateWebTextViewPosition() {
-        Rect visibleRect = new Rect();
-        calcOurContentVisibleRect(visibleRect);
-        // Note that sendOurVisibleRect calls viewToContent, so the coordinates
-        // should be in content coordinates.
-        Rect bounds = nativeFocusCandidateNodeBounds();
-        Rect vBox = contentToViewRect(bounds);
-        offsetByLayerScrollPosition(vBox);
-        mWebTextView.setRect(vBox.left, vBox.top, vBox.width(), vBox.height());
-        if (!Rect.intersects(bounds, visibleRect)) {
-            revealSelection();
-        }
-        updateWebTextViewPadding();
-    }
-
-    /**
-     * Update the padding of mWebTextView based on the native textfield/textarea
-     */
-    void updateWebTextViewPadding() {
-        Rect paddingRect = nativeFocusCandidatePaddingRect();
-        if (paddingRect != null) {
-            // Use contentToViewDimension since these are the dimensions of
-            // the padding.
-            mWebTextView.setPadding(
-                    contentToViewDimension(paddingRect.left),
-                    contentToViewDimension(paddingRect.top),
-                    contentToViewDimension(paddingRect.right),
-                    contentToViewDimension(paddingRect.bottom));
-        }
-    }
-
-    /**
-     * Tell webkit to put the cursor on screen.
-     */
-    /* package */ void revealSelection() {
-        if (mWebViewCore != null) {
-            mWebViewCore.sendMessage(EventHub.REVEAL_SELECTION);
-        }
-    }
-
-    /**
-     * Called by WebTextView to find saved form data associated with the
-     * textfield
-     * @param name Name of the textfield.
-     * @param nodePointer Pointer to the node of the textfield, so it can be
-     *          compared to the currently focused textfield when the data is
-     *          retrieved.
-     * @param autoFillable true if WebKit has determined this field is part of
-     *          a form that can be auto filled.
-     * @param autoComplete true if the attribute "autocomplete" is set to true
-     *          on the textfield.
-     */
-    /* package */ void requestFormData(String name, int nodePointer,
-            boolean autoFillable, boolean autoComplete) {
-        if (mWebViewCore.getSettings().getSaveFormData()) {
-            Message update = mPrivateHandler.obtainMessage(REQUEST_FORM_DATA);
-            update.arg1 = nodePointer;
-            RequestFormData updater = new RequestFormData(name, getUrl(),
-                    update, autoFillable, autoComplete);
-            Thread t = new Thread(updater);
-            t.start();
-        }
-    }
-
-    /**
-     * Pass a message to find out the <label> associated with the <input>
-     * identified by nodePointer
-     * @param framePointer Pointer to the frame containing the <input> node
-     * @param nodePointer Pointer to the node for which a <label> is desired.
-     */
-    /* package */ void requestLabel(int framePointer, int nodePointer) {
-        mWebViewCore.sendMessage(EventHub.REQUEST_LABEL, framePointer,
-                nodePointer);
-    }
-
-    /*
-     * This class requests an Adapter for the WebTextView which shows past
-     * entries stored in the database.  It is a Runnable so that it can be done
-     * in its own thread, without slowing down the UI.
-     */
-    private class RequestFormData implements Runnable {
-        private String mName;
-        private String mUrl;
-        private Message mUpdateMessage;
-        private boolean mAutoFillable;
-        private boolean mAutoComplete;
-        private WebSettingsClassic mWebSettings;
-
-        public RequestFormData(String name, String url, Message msg,
-                boolean autoFillable, boolean autoComplete) {
-            mName = name;
-            mUrl = WebTextView.urlForAutoCompleteData(url);
-            mUpdateMessage = msg;
-            mAutoFillable = autoFillable;
-            mAutoComplete = autoComplete;
-            mWebSettings = getSettings();
-        }
-
-        @Override
-        public void run() {
-            ArrayList<String> pastEntries = new ArrayList<String>();
-
-            if (mAutoFillable) {
-                // Note that code inside the adapter click handler in WebTextView depends
-                // on the AutoFill item being at the top of the drop down list. If you change
-                // the order, make sure to do it there too!
-                if (mWebSettings != null && mWebSettings.getAutoFillProfile() != null) {
-                    pastEntries.add(mWebView.getResources().getText(
-                            com.android.internal.R.string.autofill_this_form).toString() +
-                            " " +
-                            mAutoFillData.getPreviewString());
-                    mWebTextView.setAutoFillProfileIsSet(true);
-                } else {
-                    // There is no autofill profile set up yet, so add an option that
-                    // will invite the user to set their profile up.
-                    pastEntries.add(mWebView.getResources().getText(
-                            com.android.internal.R.string.setup_autofill).toString());
-                    mWebTextView.setAutoFillProfileIsSet(false);
-                }
-            }
-
-            if (mAutoComplete) {
-                pastEntries.addAll(mDatabase.getFormData(mUrl, mName));
-            }
-
-            if (pastEntries.size() > 0) {
-                AutoCompleteAdapter adapter = new
-                        AutoCompleteAdapter(mContext, pastEntries);
-                mUpdateMessage.obj = adapter;
-                mUpdateMessage.sendToTarget();
-            }
-        }
-    }
-
     /**
      * Dump the display tree to "/sdcard/displayTree.txt"
      *
@@ -5790,38 +5309,12 @@
         if (keyCode >= KeyEvent.KEYCODE_DPAD_UP
                 && keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT) {
             switchOutDrawHistory();
-            if (nativePageShouldHandleShiftAndArrows()) {
-                letPageHandleNavKey(keyCode, event.getEventTime(), true, event.getMetaState());
-                return true;
-            }
-            if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
-                switch (keyCode) {
-                    case KeyEvent.KEYCODE_DPAD_UP:
-                        pageUp(true);
-                        return true;
-                    case KeyEvent.KEYCODE_DPAD_DOWN:
-                        pageDown(true);
-                        return true;
-                    case KeyEvent.KEYCODE_DPAD_LEFT:
-                        nativeClearCursor(); // start next trackball movement from page edge
-                        return pinScrollTo(0, getScrollY(), true, 0);
-                    case KeyEvent.KEYCODE_DPAD_RIGHT:
-                        nativeClearCursor(); // start next trackball movement from page edge
-                        return pinScrollTo(mContentWidth, getScrollY(), true, 0);
-                }
-            }
-            if (navHandledKey(keyCode, 1, false, event.getEventTime())) {
-                mWebView.playSoundEffect(keyCodeToSoundsEffect(keyCode));
-                return true;
-            }
-            // Bubble up the key event as WebView doesn't handle it
-            return false;
+            letPageHandleNavKey(keyCode, event.getEventTime(), true, event.getMetaState());
+            return true;
         }
 
         if (isEnterActionKey(keyCode)) {
             switchOutDrawHistory();
-            boolean wantsKeyEvents = nativeCursorNodePointer() == 0
-                || nativeCursorWantsKeyEvents();
             if (event.getRepeatCount() == 0) {
                 if (mSelectingText) {
                     return true; // discard press if copy in progress
@@ -5829,10 +5322,7 @@
                 mGotCenterDown = true;
                 mPrivateHandler.sendMessageDelayed(mPrivateHandler
                         .obtainMessage(LONG_PRESS_CENTER), LONG_PRESS_TIMEOUT);
-                if (!wantsKeyEvents) return true;
             }
-            // Bubble up the key event as WebView doesn't handle it
-            if (!wantsKeyEvents) return false;
         }
 
         if (getSettings().getNavDump()) {
@@ -5851,39 +5341,10 @@
             }
         }
 
-        if (nativeCursorIsTextInput()) {
-            // This message will put the node in focus, for the DOM's notion
-            // of focus.
-            mWebViewCore.sendMessage(EventHub.FAKE_CLICK, nativeCursorFramePointer(),
-                    nativeCursorNodePointer());
-            // This will bring up the WebTextView and put it in focus, for
-            // our view system's notion of focus
-            rebuildWebTextView();
-            // Now we need to pass the event to it
-            if (inEditingMode()) {
-                mWebTextView.setDefaultSelection();
-                return mWebTextView.dispatchKeyEvent(event);
-            }
-        } else if (nativeHasFocusNode()) {
-            // In this case, the cursor is not on a text input, but the focus
-            // might be.  Check it, and if so, hand over to the WebTextView.
-            rebuildWebTextView();
-            if (inEditingMode()) {
-                mWebTextView.setDefaultSelection();
-                return mWebTextView.dispatchKeyEvent(event);
-            }
-        }
-
-        // TODO: should we pass all the keys to DOM or check the meta tag
-        if (nativeCursorWantsKeyEvents() || true) {
-            // pass the key to DOM
-            mWebViewCore.sendMessage(EventHub.KEY_DOWN, event);
-            // return true as DOM handles the key
-            return true;
-        }
-
-        // Bubble up the key event as WebView doesn't handle it
-        return false;
+        // pass the key to DOM
+        mWebViewCore.sendMessage(EventHub.KEY_DOWN, event);
+        // return true as DOM handles the key
+        return true;
     }
 
     @Override
@@ -5901,14 +5362,13 @@
         }
 
         // special CALL handling when cursor node's href is "tel:XXX"
-        if (keyCode == KeyEvent.KEYCODE_CALL && nativeHasCursorNode()) {
-            String text = nativeCursorText();
-            if (!nativeCursorIsTextInput() && text != null
-                    && text.startsWith(SCHEME_TEL)) {
-                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(text));
-                mContext.startActivity(intent);
-                return true;
-            }
+        if (keyCode == KeyEvent.KEYCODE_CALL
+                && mInitialHitTestResult != null
+                && mInitialHitTestResult.getType() == HitTestResult.PHONE_TYPE) {
+            String text = mInitialHitTestResult.getExtra();
+            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(text));
+            mContext.startActivity(intent);
+            return true;
         }
 
         // Bubble up the key event if
@@ -5947,13 +5407,8 @@
 
         if (keyCode >= KeyEvent.KEYCODE_DPAD_UP
                 && keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT) {
-            if (nativePageShouldHandleShiftAndArrows()) {
-                letPageHandleNavKey(keyCode, event.getEventTime(), false, event.getMetaState());
-                return true;
-            }
-            // always handle the navigation keys in the UI thread
-            // Bubble up the key event as WebView doesn't handle it
-            return false;
+            letPageHandleNavKey(keyCode, event.getEventTime(), false, event.getMetaState());
+            return true;
         }
 
         if (isEnterActionKey(keyCode)) {
@@ -5966,49 +5421,12 @@
                 selectionDone();
                 return true; // discard press if copy in progress
             }
-
-            if (!sDisableNavcache) {
-                // perform the single click
-                Rect visibleRect = sendOurVisibleRect();
-                // Note that sendOurVisibleRect calls viewToContent, so the
-                // coordinates should be in content coordinates.
-                if (!nativeCursorIntersects(visibleRect)) {
-                    return false;
-                }
-                WebViewCore.CursorData data = cursorData();
-                mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE, data);
-                mWebView.playSoundEffect(SoundEffectConstants.CLICK);
-                if (nativeCursorIsTextInput()) {
-                    rebuildWebTextView();
-                    centerKeyPressOnTextField();
-                    if (inEditingMode()) {
-                        mWebTextView.setDefaultSelection();
-                    }
-                    return true;
-                }
-                clearTextEntry();
-                nativeShowCursorTimed();
-                if (mCallbackProxy.uiOverrideUrlLoading(nativeCursorText())) {
-                    return true;
-                }
-                if (nativeCursorNodePointer() != 0 && !nativeCursorWantsKeyEvents()) {
-                    mWebViewCore.sendMessage(EventHub.CLICK, data.mFrame,
-                            nativeCursorNodePointer());
-                    return true;
-                }
-            }
         }
 
-        // TODO: should we pass all the keys to DOM or check the meta tag
-        if (nativeCursorWantsKeyEvents() || true) {
-            // pass the key to DOM
-            mWebViewCore.sendMessage(EventHub.KEY_UP, event);
-            // return true as DOM handles the key
-            return true;
-        }
-
-        // Bubble up the key event as WebView doesn't handle it
-        return false;
+        // pass the key to DOM
+        mWebViewCore.sendMessage(EventHub.KEY_UP, event);
+        // return true as DOM handles the key
+        return true;
     }
 
     private boolean startSelectActionMode() {
@@ -6262,18 +5680,11 @@
             if (mWebView.hasFocus()) {
                 // If our window regained focus, and we have focus, then begin
                 // drawing the cursor ring
-                mDrawCursorRing = !inEditingMode();
+                mDrawCursorRing = true;
                 setFocusControllerActive(true);
             } else {
                 mDrawCursorRing = false;
-                if (!inEditingMode()) {
-                    // If our window gained focus, but we do not have it, do not
-                    // draw the cursor ring.
-                    setFocusControllerActive(false);
-                }
-                // We do not call recordButtons here because we assume
-                // that when we lost focus, or window focus, it got called with
-                // false for the first parameter
+                setFocusControllerActive(false);
             }
         } else {
             if (!mZoomManager.isZoomPickerVisible()) {
@@ -6339,23 +5750,11 @@
             Log.v(LOGTAG, "MT focusChanged " + focused + ", " + direction);
         }
         if (focused) {
-            // When we regain focus, if we have window focus, resume drawing
-            // the cursor ring
-            if (mWebView.hasWindowFocus()) {
-                mDrawCursorRing = !inEditingMode();
-                setFocusControllerActive(true);
-            //} else {
-                // The WebView has gained focus while we do not have
-                // windowfocus.  When our window lost focus, we should have
-                // called recordButtons(false...)
-            }
+            mDrawCursorRing = true;
+            setFocusControllerActive(true);
         } else {
-            // When we lost focus, unless focus went to the TextView (which is
-            // true if we are in editing mode), stop drawing the cursor ring.
             mDrawCursorRing = false;
-            if (!inEditingMode()) {
-                setFocusControllerActive(false);
-            }
+            setFocusControllerActive(false);
             mKeysPressed.clear();
         }
     }
@@ -6461,13 +5860,7 @@
                 // action is added to KeyEvent.
                 break;
         }
-        if (inEditingMode() && mWebTextView.isFocused()) {
-            // Ensure that the WebTextView gets the event, even if it does
-            // not currently have a bounds.
-            return mWebTextView.dispatchKeyEvent(event);
-        } else {
-            return mWebViewPrivate.super_dispatchKeyEvent(event);
-        }
+        return mWebViewPrivate.super_dispatchKeyEvent(event);
     }
 
     /*
@@ -6497,14 +5890,8 @@
     private static final float MMA_WEIGHT_N = 5;
 
     private boolean hitFocusedPlugin(int contentX, int contentY) {
-        if (DebugFlags.WEB_VIEW) {
-            Log.v(LOGTAG, "nativeFocusIsPlugin()=" + nativeFocusIsPlugin());
-            Rect r = nativeFocusNodeBounds();
-            Log.v(LOGTAG, "nativeFocusNodeBounds()=(" + r.left + ", " + r.top
-                    + ", " + r.right + ", " + r.bottom + ")");
-        }
-        return nativeFocusIsPlugin()
-                && nativeFocusNodeBounds().contains(contentX, contentY);
+        // TODO: Figure out what to do with this (b/6111517)
+        return false;
     }
 
     private boolean shouldForwardTouchEvent() {
@@ -6569,10 +5956,9 @@
         if (mNativeClass == 0) {
             return false;
         }
-        WebViewCore.CursorData data = cursorDataNoPosition();
-        data.mX = viewToContentX((int) event.getX() + getScrollX());
-        data.mY = viewToContentY((int) event.getY() + getScrollY());
-        mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE, data);
+        int x = viewToContentX((int) event.getX() + getScrollX());
+        int y = viewToContentY((int) event.getY() + getScrollY());
+        mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE, x, y);
         return true;
     }
 
@@ -6642,9 +6028,7 @@
                     nativeSetIsScrolling(false);
                 } else if (mPrivateHandler.hasMessages(RELEASE_SINGLE_TAP)) {
                     mPrivateHandler.removeMessages(RELEASE_SINGLE_TAP);
-                    if (sDisableNavcache) {
-                        removeTouchHighlight();
-                    }
+                    removeTouchHighlight();
                     if (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare) {
                         mTouchMode = TOUCH_DOUBLE_TAP_MODE;
                     } else {
@@ -6662,36 +6046,30 @@
                             && (!inFullScreenMode() && mForwardTouchEvents)
                             ? hitFocusedPlugin(contentX, contentY)
                             : false;
+                    TouchHighlightData data = new TouchHighlightData();
+                    data.mX = contentX;
+                    data.mY = contentY;
+                    data.mNativeLayerRect = new Rect();
+                    data.mNativeLayer = nativeScrollableLayer(
+                            contentX, contentY, data.mNativeLayerRect, null);
+                    data.mSlop = viewToContentDimension(mNavSlop);
+                    mTouchHighlightRegion.setEmpty();
                     if (!mBlockWebkitViewMessages) {
-                        mWebViewCore.sendMessage(
-                                EventHub.UPDATE_FRAME_CACHE_IF_LOADING);
+                        mTouchHighlightRequested = System.currentTimeMillis();
+                        mWebViewCore.sendMessageAtFrontOfQueue(
+                                EventHub.HIT_TEST, data);
                     }
-                    if (sDisableNavcache) {
-                        TouchHighlightData data = new TouchHighlightData();
-                        data.mX = contentX;
-                        data.mY = contentY;
-                        data.mNativeLayerRect = new Rect();
-                        data.mNativeLayer = nativeScrollableLayer(
-                                contentX, contentY, data.mNativeLayerRect, null);
-                        data.mSlop = viewToContentDimension(mNavSlop);
-                        mTouchHighlightRegion.setEmpty();
-                        if (!mBlockWebkitViewMessages) {
-                            mTouchHighlightRequested = System.currentTimeMillis();
-                            mWebViewCore.sendMessageAtFrontOfQueue(
-                                    EventHub.HIT_TEST, data);
-                        }
-                        if (DEBUG_TOUCH_HIGHLIGHT) {
-                            if (getSettings().getNavDump()) {
-                                mTouchHighlightX = x + getScrollX();
-                                mTouchHighlightY = y + getScrollY();
-                                mPrivateHandler.postDelayed(new Runnable() {
-                                    @Override
-                                    public void run() {
-                                        mTouchHighlightX = mTouchHighlightY = 0;
-                                        invalidate();
-                                    }
-                                }, TOUCH_HIGHLIGHT_ELAPSE_TIME);
-                            }
+                    if (DEBUG_TOUCH_HIGHLIGHT) {
+                        if (getSettings().getNavDump()) {
+                            mTouchHighlightX = x + getScrollX();
+                            mTouchHighlightY = y + getScrollY();
+                            mPrivateHandler.postDelayed(new Runnable() {
+                                @Override
+                                public void run() {
+                                    mTouchHighlightX = mTouchHighlightY = 0;
+                                    invalidate();
+                                }
+                            }, TOUCH_HIGHLIGHT_ELAPSE_TIME);
                         }
                     }
                     if (mLogEvent && eventTime - mLastTouchUpTime < 1000) {
@@ -6790,9 +6168,7 @@
                     if (mTouchMode == TOUCH_DOUBLE_TAP_MODE) {
                         mTouchMode = TOUCH_INIT_MODE;
                     }
-                    if (sDisableNavcache) {
-                        removeTouchHighlight();
-                    }
+                    removeTouchHighlight();
                 }
                 if (mSelectingText && mSelectionStarted) {
                     if (DebugFlags.WEB_VIEW) {
@@ -7271,8 +6647,6 @@
         mLastTouchTime = eventTime;
         mVelocityTracker = VelocityTracker.obtain();
         mSnapScrollMode = SNAP_NONE;
-        mPrivateHandler.sendEmptyMessageDelayed(UPDATE_SELECTION,
-                ViewConfiguration.getTapTimeout());
     }
 
     private void startDrag() {
@@ -7281,10 +6655,6 @@
         WebViewCore.pauseUpdatePicture(mWebViewCore);
         nativeSetIsScrolling(true);
 
-        if (!mDragFromTextInput) {
-            nativeHideCursor();
-        }
-
         if (mHorizontalScrollBarMode != SCROLLBAR_ALWAYSOFF
                 || mVerticalScrollBarMode != SCROLLBAR_ALWAYSOFF) {
             mZoomManager.invokeZoomPicker();
@@ -7398,12 +6768,9 @@
         mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
         mPrivateHandler.removeMessages(DRAG_HELD_MOTIONLESS);
         mPrivateHandler.removeMessages(AWAKEN_SCROLL_BARS);
-        if (sDisableNavcache) {
-            removeTouchHighlight();
-        }
+        removeTouchHighlight();
         mHeldMotionless = MOTIONLESS_TRUE;
         mTouchMode = TOUCH_DONE_MODE;
-        nativeHideCursor();
     }
 
     @Override
@@ -7454,7 +6821,6 @@
     private static final int SELECT_SCROLL = 5;
     private int mSelectX = 0;
     private int mSelectY = 0;
-    private boolean mFocusSizeChanged = false;
     private boolean mTrackballDown = false;
     private long mTrackballUpTime = 0;
     private long mLastCursorTime = 0;
@@ -7493,10 +6859,6 @@
             if (mNativeClass == 0) {
                 return false;
             }
-            if (time - mLastCursorTime <= TRACKBALL_TIMEOUT
-                    && !mLastCursorBounds.equals(cursorRingBounds())) {
-                nativeSelectBestAt(mLastCursorBounds);
-            }
             if (DebugFlags.WEB_VIEW) {
                 Log.v(LOGTAG, "onTrackballEvent down ev=" + ev
                         + " time=" + time
@@ -7640,13 +7002,11 @@
                         + " mTrackballRemainsX=" + mTrackballRemainsX
                         + " mTrackballRemainsY=" + mTrackballRemainsY);
             }
-            if (mNativeClass != 0 && nativePageShouldHandleShiftAndArrows()) {
+            if (mNativeClass != 0) {
                 for (int i = 0; i < count; i++) {
                     letPageHandleNavKey(selectKeyCode, time, true, metaState);
                 }
                 letPageHandleNavKey(selectKeyCode, time, false, metaState);
-            } else if (navHandledKey(selectKeyCode, count, false, time)) {
-                mWebView.playSoundEffect(keyCodeToSoundsEffect(selectKeyCode));
             }
             mTrackballRemainsX = mTrackballRemainsY = 0;
         }
@@ -7893,105 +7253,6 @@
         return mZoomManager.zoomOut();
     }
 
-    /**
-     * This selects the best clickable target at mLastTouchX and mLastTouchY
-     * and calls showCursorTimed on the native side
-     */
-    private void updateSelection() {
-        if (mNativeClass == 0 || sDisableNavcache) {
-            return;
-        }
-        mPrivateHandler.removeMessages(UPDATE_SELECTION);
-        // mLastTouchX and mLastTouchY are the point in the current viewport
-        int contentX = viewToContentX(mLastTouchX + getScrollX());
-        int contentY = viewToContentY(mLastTouchY + getScrollY());
-        int slop = viewToContentDimension(mNavSlop);
-        Rect rect = new Rect(contentX - slop, contentY - slop,
-                contentX + slop, contentY + slop);
-        nativeSelectBestAt(rect);
-        mInitialHitTestResult = hitTestResult(null);
-    }
-
-    /**
-     * Scroll the focused text field to match the WebTextView
-     * @param xPercent New x position of the WebTextView from 0 to 1.
-     */
-    /*package*/ void scrollFocusedTextInputX(float xPercent) {
-        if (!inEditingMode() || mWebViewCore == null) {
-            return;
-        }
-        mWebViewCore.sendMessage(EventHub.SCROLL_TEXT_INPUT, 0,
-                new Float(xPercent));
-    }
-
-    /**
-     * Scroll the focused textarea vertically to match the WebTextView
-     * @param y New y position of the WebTextView in view coordinates
-     */
-    /* package */ void scrollFocusedTextInputY(int y) {
-        if (!inEditingMode() || mWebViewCore == null) {
-            return;
-        }
-        mWebViewCore.sendMessage(EventHub.SCROLL_TEXT_INPUT, 0, viewToContentDimension(y));
-    }
-
-    /**
-     * Set our starting point and time for a drag from the WebTextView.
-     */
-    /*package*/ void initiateTextFieldDrag(float x, float y, long eventTime) {
-        if (!inEditingMode()) {
-            return;
-        }
-        mLastTouchX = Math.round(x + mWebTextView.getLeft() - getScrollX());
-        mLastTouchY = Math.round(y + mWebTextView.getTop() - getScrollY());
-        mLastTouchTime = eventTime;
-        if (!mScroller.isFinished()) {
-            abortAnimation();
-        }
-        mSnapScrollMode = SNAP_NONE;
-        mVelocityTracker = VelocityTracker.obtain();
-        mTouchMode = TOUCH_DRAG_START_MODE;
-    }
-
-    /**
-     * Given a motion event from the WebTextView, set its location to our
-     * coordinates, and handle the event.
-     */
-    /*package*/ boolean textFieldDrag(MotionEvent event) {
-        if (!inEditingMode()) {
-            return false;
-        }
-        mDragFromTextInput = true;
-        event.offsetLocation((mWebTextView.getLeft() - getScrollX()),
-                (mWebTextView.getTop() - getScrollY()));
-        boolean result = onTouchEvent(event);
-        mDragFromTextInput = false;
-        return result;
-    }
-
-    /**
-     * Due a touch up from a WebTextView.  This will be handled by webkit to
-     * change the selection.
-     * @param event MotionEvent in the WebTextView's coordinates.
-     */
-    /*package*/ void touchUpOnTextField(MotionEvent event) {
-        if (!inEditingMode()) {
-            return;
-        }
-        int x = viewToContentX((int) event.getX() + mWebTextView.getLeft());
-        int y = viewToContentY((int) event.getY() + mWebTextView.getTop());
-        int slop = viewToContentDimension(mNavSlop);
-        nativeMotionUp(x, y, slop);
-    }
-
-    /**
-     * Called when pressing the center key or trackball on a textfield.
-     */
-    /*package*/ void centerKeyPressOnTextField() {
-        mWebViewCore.sendMessage(EventHub.CLICK, nativeCursorFramePointer(),
-                    nativeCursorNodePointer());
-    }
-
     private void doShortPress() {
         if (mNativeClass == 0) {
             return;
@@ -8000,13 +7261,8 @@
             return;
         }
         mTouchMode = TOUCH_DONE_MODE;
-        updateSelection();
         switchOutDrawHistory();
-        // mLastTouchX and mLastTouchY are the point in the current viewport
-        int contentX = viewToContentX(mLastTouchX + getScrollX());
-        int contentY = viewToContentY(mLastTouchY + getScrollY());
-        int slop = viewToContentDimension(mNavSlop);
-        if (sDisableNavcache && !mTouchHighlightRegion.isEmpty()) {
+        if (!mTouchHighlightRegion.isEmpty()) {
             // set mTouchHighlightRequested to 0 to cause an immediate
             // drawing of the touch rings
             mTouchHighlightRequested = 0;
@@ -8021,34 +7277,12 @@
         if (mFocusedNode != null && mFocusedNode.mIntentUrl != null) {
             mWebView.playSoundEffect(SoundEffectConstants.CLICK);
             overrideLoading(mFocusedNode.mIntentUrl);
-        } else if (sDisableNavcache) {
+        } else {
             WebViewCore.TouchUpData touchUpData = new WebViewCore.TouchUpData();
             // use "0" as generation id to inform WebKit to use the same x/y as
             // it used when processing GET_TOUCH_HIGHLIGHT_RECTS
             touchUpData.mMoveGeneration = 0;
             mWebViewCore.sendMessage(EventHub.TOUCH_UP, touchUpData);
-        } else if (nativePointInNavCache(contentX, contentY, slop)) {
-            WebViewCore.MotionUpData motionUpData = new WebViewCore
-                    .MotionUpData();
-            motionUpData.mFrame = nativeCacheHitFramePointer();
-            motionUpData.mNode = nativeCacheHitNodePointer();
-            motionUpData.mBounds = nativeCacheHitNodeBounds();
-            motionUpData.mX = contentX;
-            motionUpData.mY = contentY;
-            mWebViewCore.sendMessageAtFrontOfQueue(EventHub.VALID_NODE_BOUNDS,
-                    motionUpData);
-        } else {
-            doMotionUp(contentX, contentY);
-        }
-    }
-
-    private void doMotionUp(int contentX, int contentY) {
-        int slop = viewToContentDimension(mNavSlop);
-        if (nativeMotionUp(contentX, contentY, slop) && mLogEvent) {
-            EventLog.writeEvent(EventLogTags.BROWSER_SNAP_CENTER);
-        }
-        if (nativeHasCursorNode() && !nativeCursorIsTextInput()) {
-            mWebView.playSoundEffect(SoundEffectConstants.CLICK);
         }
     }
 
@@ -8056,19 +7290,6 @@
         mWebViewCore.sendMessage(EventHub.PLUGIN_SURFACE_READY);
     }
 
-    /**
-     * Returns plugin bounds if x/y in content coordinates corresponds to a
-     * plugin. Otherwise a NULL rectangle is returned.
-     */
-    Rect getPluginBounds(int x, int y) {
-        int slop = viewToContentDimension(mNavSlop);
-        if (nativePointInNavCache(x, y, slop) && nativeCacheHitIsPlugin()) {
-            return nativeCacheHitNodeBounds();
-        } else {
-            return null;
-        }
-    }
-
     /*
      * Return true if the rect (e.g. plugin) is fully visible and maximized
      * inside the WebView.
@@ -8152,36 +7373,29 @@
         // background window, it can steal focus.
         if (mFindIsUp) return false;
         boolean result = false;
-        if (inEditingMode()) {
-            result = mWebTextView.requestFocus(direction,
-                    previouslyFocusedRect);
-        } else {
-            result = mWebViewPrivate.super_requestFocus(direction, previouslyFocusedRect);
-            if (mWebViewCore.getSettings().getNeedInitialFocus() && !mWebView.isInTouchMode()) {
-                // For cases such as GMail, where we gain focus from a direction,
-                // we want to move to the first available link.
-                // FIXME: If there are no visible links, we may not want to
-                int fakeKeyDirection = 0;
-                switch(direction) {
-                    case View.FOCUS_UP:
-                        fakeKeyDirection = KeyEvent.KEYCODE_DPAD_UP;
-                        break;
-                    case View.FOCUS_DOWN:
-                        fakeKeyDirection = KeyEvent.KEYCODE_DPAD_DOWN;
-                        break;
-                    case View.FOCUS_LEFT:
-                        fakeKeyDirection = KeyEvent.KEYCODE_DPAD_LEFT;
-                        break;
-                    case View.FOCUS_RIGHT:
-                        fakeKeyDirection = KeyEvent.KEYCODE_DPAD_RIGHT;
-                        break;
-                    default:
-                        return result;
-                }
-                if (mNativeClass != 0 && !nativeHasCursorNode()) {
-                    navHandledKey(fakeKeyDirection, 1, true, 0);
-                }
+        result = mWebViewPrivate.super_requestFocus(direction, previouslyFocusedRect);
+        if (mWebViewCore.getSettings().getNeedInitialFocus() && !mWebView.isInTouchMode()) {
+            // For cases such as GMail, where we gain focus from a direction,
+            // we want to move to the first available link.
+            // FIXME: If there are no visible links, we may not want to
+            int fakeKeyDirection = 0;
+            switch(direction) {
+                case View.FOCUS_UP:
+                    fakeKeyDirection = KeyEvent.KEYCODE_DPAD_UP;
+                    break;
+                case View.FOCUS_DOWN:
+                    fakeKeyDirection = KeyEvent.KEYCODE_DPAD_DOWN;
+                    break;
+                case View.FOCUS_LEFT:
+                    fakeKeyDirection = KeyEvent.KEYCODE_DPAD_LEFT;
+                    break;
+                case View.FOCUS_RIGHT:
+                    fakeKeyDirection = KeyEvent.KEYCODE_DPAD_RIGHT;
+                    break;
+                default:
+                    return result;
             }
+            // TODO: Send initial focus request to webkit (b/6108927)
         }
         return result;
     }
@@ -8244,7 +7458,7 @@
             return false;
         }
         // don't scroll while in zoom animation. When it is done, we will adjust
-        // the necessary components (e.g., WebTextView if it is in editing mode)
+        // the necessary components
         if (mZoomManager.isFixedLengthAnimationInProgress()) {
             return false;
         }
@@ -8327,8 +7541,7 @@
         // document state when it goes to background, we force to save the
         // document state.
         mWebViewCore.removeMessages(EventHub.SAVE_DOCUMENT_STATE);
-        mWebViewCore.sendMessageDelayed(EventHub.SAVE_DOCUMENT_STATE,
-                cursorData(), 1000);
+        mWebViewCore.sendMessageDelayed(EventHub.SAVE_DOCUMENT_STATE, null, 1000);
     }
 
     /**
@@ -8895,34 +8108,16 @@
                             SCROLL_SELECT_TEXT, SELECT_SCROLL_INTERVAL);
                     break;
                 }
-                case UPDATE_SELECTION: {
-                    if (mTouchMode == TOUCH_INIT_MODE
-                            || mTouchMode == TOUCH_SHORTPRESS_MODE
-                            || mTouchMode == TOUCH_SHORTPRESS_START_MODE) {
-                        updateSelection();
-                    }
-                    break;
-                }
                 case SWITCH_TO_SHORTPRESS: {
                     if (mTouchMode == TOUCH_INIT_MODE) {
-                        if (!sDisableNavcache
-                                && mPreventDefault != PREVENT_DEFAULT_YES) {
-                            mTouchMode = TOUCH_SHORTPRESS_START_MODE;
-                            updateSelection();
-                        } else {
-                            // set to TOUCH_SHORTPRESS_MODE so that it won't
-                            // trigger double tap any more
-                            mTouchMode = TOUCH_SHORTPRESS_MODE;
-                        }
+                        mTouchMode = TOUCH_SHORTPRESS_MODE;
                     } else if (mTouchMode == TOUCH_DOUBLE_TAP_MODE) {
                         mTouchMode = TOUCH_DONE_MODE;
                     }
                     break;
                 }
                 case SWITCH_TO_LONGPRESS: {
-                    if (sDisableNavcache) {
-                        removeTouchHighlight();
-                    }
+                    removeTouchHighlight();
                     if (inFullScreenMode() || mDeferTouchProcess) {
                         TouchEventData ted = new TouchEventData();
                         ted.mAction = WebViewCore.ACTION_LONGPRESS;
@@ -8963,8 +8158,7 @@
                         // view, but is only necessary if the IME is showing
                         InputMethodManager imm = InputMethodManager.peekInstance();
                         if (imm == null || !imm.isAcceptingText()
-                                || (!imm.isActive(mWebView) && (!inEditingMode()
-                                || !imm.isActive(mWebTextView)))) {
+                                || !imm.isActive(mWebView)) {
                             break;
                         }
                     }
@@ -9022,10 +8216,7 @@
                         if (null == text) {
                             text = "";
                         }
-                        if (inEditingMode() &&
-                                mWebTextView.isSameTextField(msg.arg1)) {
-                            mWebTextView.setTextAndKeepSelection(text);
-                        } else if (mInputConnection != null &&
+                        if (mInputConnection != null &&
                                 mFieldPointer == msg.arg1) {
                             mInputConnection.setTextAndKeepSelection(text);
                         }
@@ -9039,37 +8230,13 @@
                             (WebViewCore.TextSelectionData) msg.obj);
                     break;
                 case FORM_DID_BLUR:
-                    if (inEditingMode()
-                            && mWebTextView.isSameTextField(msg.arg1)) {
-                        hideSoftKeyboard();
-                    }
-                    break;
-                case RETURN_LABEL:
-                    if (inEditingMode()
-                            && mWebTextView.isSameTextField(msg.arg1)) {
-                        mWebTextView.setHint((String) msg.obj);
-                        InputMethodManager imm
-                                = InputMethodManager.peekInstance();
-                        // The hint is propagated to the IME in
-                        // onCreateInputConnection.  If the IME is already
-                        // active, restart it so that its hint text is updated.
-                        if (imm != null && imm.isActive(mWebTextView)) {
-                            imm.restartInput(mWebTextView);
-                        }
-                    }
+                    // TODO: Figure out if this is needed for something (b/6111763)
                     break;
                 case UNHANDLED_NAV_KEY:
-                    navHandledKey(msg.arg1, 1, false, 0);
-                    break;
-                case UPDATE_TEXT_ENTRY_MSG_ID:
-                    // this is sent after finishing resize in WebViewCore. Make
-                    // sure the text edit box is still on the  screen.
-                    if (inEditingMode() && nativeCursorIsTextInput()) {
-                        updateWebTextViewPosition();
-                    }
+                    // TODO: Support this (b/6109044)
                     break;
                 case CLEAR_TEXT_ENTRY:
-                    clearTextEntry();
+                    hideSoftKeyboard();
                     break;
                 case INVAL_RECT_MSG_ID: {
                     Rect r = (Rect)msg.obj;
@@ -9082,12 +8249,6 @@
                     }
                     break;
                 }
-                case REQUEST_FORM_DATA:
-                    AutoCompleteAdapter adapter = (AutoCompleteAdapter) msg.obj;
-                    if (mWebTextView.isSameTextField(msg.arg1)) {
-                        mWebTextView.setAdapterCustom(adapter);
-                    }
-                    break;
 
                 case LONG_PRESS_CENTER:
                     // as this is shared by keydown and trackballdown, reset all
@@ -9138,10 +8299,6 @@
                     }
                     break;
 
-                case DO_MOTION_UP:
-                    doMotionUp(msg.arg1, msg.arg2);
-                    break;
-
                 case SCREEN_ON:
                     mWebView.setKeepScreenOn(msg.arg1 == 1);
                     break;
@@ -9181,13 +8338,6 @@
                     dismissFullScreenMode();
                     break;
 
-                case DOM_FOCUS_CHANGED:
-                    if (inEditingMode()) {
-                        nativeClearCursor();
-                        rebuildWebTextView();
-                    }
-                    break;
-
                 case SHOW_RECT_MSG_ID: {
                     WebViewCore.ShowRectData data = (WebViewCore.ShowRectData) msg.obj;
                     int x = getScrollX();
@@ -9269,22 +8419,11 @@
 
                 case SET_AUTOFILLABLE:
                     mAutoFillData = (WebViewCore.AutoFillData) msg.obj;
-                    if (mWebTextView != null) {
-                        mWebTextView.setAutoFillable(mAutoFillData.getQueryId());
-                        rebuildWebTextView();
-                    }
+                    // TODO: Support (b/6083041)
                     break;
 
                 case AUTOFILL_COMPLETE:
-                    if (mWebTextView != null) {
-                        // Clear the WebTextView adapter when AutoFill finishes
-                        // so that the drop down gets cleared.
-                        mWebTextView.setAdapterCustom(null);
-                    }
-                    break;
-
-                case SELECT_AT:
-                    nativeSelectAt(msg.arg1, msg.arg2);
+                    // TODO: Support (b/6083041)
                     break;
 
                 case COPY_TO_CLIPBOARD:
@@ -9534,9 +8673,6 @@
      * acceleration) */
     protected void pageSwapCallback(boolean notifyAnimationStarted) {
         mWebViewCore.resumeWebKitDraw();
-        if (inEditingMode()) {
-            didUpdateWebTextViewDimensions(ANYWHERE);
-        }
         if (notifyAnimationStarted) {
             mWebViewCore.sendMessage(EventHub.NOTIFY_ANIMATION_STARTED);
         }
@@ -9586,11 +8722,8 @@
             int scrollY = viewState.mScrollY;
             setContentScrollTo(scrollX, scrollY);
             if (!mDrawHistory) {
-                // As we are on a new page, remove the WebTextView. This
-                // is necessary for page loads driven by webkit, and in
-                // particular when the user was on a password field, so
-                // the WebTextView was visible.
-                clearTextEntry();
+                // As we are on a new page, hide the keyboard
+                hideSoftKeyboard();
             }
         }
         mSendScrollEvent = true;
@@ -9609,9 +8742,6 @@
         // update the zoom information based on the new picture
         mZoomManager.onNewPicture(draw);
 
-        if (draw.mFocusSizeChanged && inEditingMode()) {
-            mFocusSizeChanged = true;
-        }
         if (isPictureAfterFirstLayout) {
             mViewManager.postReadyToDrawAll();
         }
@@ -9619,15 +8749,12 @@
 
     /**
      * Used when receiving messages for REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID
-     * and UPDATE_TEXT_SELECTION_MSG_ID.  Update the selection of WebTextView.
+     * and UPDATE_TEXT_SELECTION_MSG_ID.
      */
     private void updateTextSelectionFromMessage(int nodePointer,
             int textGeneration, WebViewCore.TextSelectionData data) {
         if (textGeneration == mTextGeneration) {
-            if (inEditingMode()
-                    && mWebTextView.isSameTextField(nodePointer)) {
-                mWebTextView.setSelectionFromWebKit(data.mStart, data.mEnd);
-            } else if (mInputConnection != null && mFieldPointer == nodePointer) {
+            if (mInputConnection != null && mFieldPointer == nodePointer) {
                 mInputConnection.setSelection(data.mStart, data.mEnd);
             }
         }
@@ -9961,59 +9088,6 @@
                 new InvokeListBox(array, enabledArray, selection));
     }
 
-    // called by JNI
-    private void sendMoveFocus(int frame, int node) {
-        mWebViewCore.sendMessage(EventHub.SET_MOVE_FOCUS,
-                new WebViewCore.CursorData(frame, node, 0, 0));
-    }
-
-    // called by JNI
-    private void sendMoveMouse(int frame, int node, int x, int y) {
-        mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE,
-                new WebViewCore.CursorData(frame, node, x, y));
-    }
-
-    /*
-     * Send a mouse move event to the webcore thread.
-     *
-     * @param removeFocus Pass true to remove the WebTextView, if present.
-     * @param stopPaintingCaret Stop drawing the blinking caret if true.
-     * called by JNI
-     */
-    @SuppressWarnings("unused")
-    private void sendMoveMouseIfLatest(boolean removeFocus, boolean stopPaintingCaret) {
-        if (removeFocus) {
-            clearTextEntry();
-        }
-        mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE_IF_LATEST,
-                stopPaintingCaret ? 1 : 0, 0,
-                cursorData());
-    }
-
-    /**
-     * Called by JNI to send a message to the webcore thread that the user
-     * touched the webpage.
-     * @param touchGeneration Generation number of the touch, to ignore touches
-     *      after a new one has been generated.
-     * @param frame Pointer to the frame holding the node that was touched.
-     * @param node Pointer to the node touched.
-     * @param x x-position of the touch.
-     * @param y y-position of the touch.
-     */
-    private void sendMotionUp(int touchGeneration,
-            int frame, int node, int x, int y) {
-        WebViewCore.TouchUpData touchUpData = new WebViewCore.TouchUpData();
-        touchUpData.mMoveGeneration = touchGeneration;
-        touchUpData.mFrame = frame;
-        touchUpData.mNode = node;
-        touchUpData.mX = x;
-        touchUpData.mY = y;
-        touchUpData.mNativeLayer = nativeScrollableLayer(
-                x, y, touchUpData.mNativeLayerRect, null);
-        mWebViewCore.sendMessage(EventHub.TOUCH_UP, touchUpData);
-    }
-
-
     private int getScaledMaxXScroll() {
         int width;
         if (mHeightCanMeasure == false) {
@@ -10073,67 +9147,6 @@
         mWebViewCore.sendMessage(eventHubAction, event);
     }
 
-    // return true if the key was handled
-    private boolean navHandledKey(int keyCode, int count, boolean noScroll,
-            long time) {
-        if (mNativeClass == 0) {
-            return false;
-        }
-        mInitialHitTestResult = null;
-        mLastCursorTime = time;
-        mLastCursorBounds = cursorRingBounds();
-        boolean keyHandled
-                = nativeMoveCursor(keyCode, count, noScroll) == false;
-        if (DebugFlags.WEB_VIEW) {
-            Log.v(LOGTAG, "navHandledKey mLastCursorBounds=" + mLastCursorBounds
-                    + " mLastCursorTime=" + mLastCursorTime
-                    + " handled=" + keyHandled);
-        }
-        if (keyHandled == false) {
-            return keyHandled;
-        }
-        Rect contentCursorRingBounds = cursorRingBounds();
-        if (contentCursorRingBounds.isEmpty()) return keyHandled;
-        Rect viewCursorRingBounds = contentToViewRect(contentCursorRingBounds);
-        // set last touch so that context menu related functions will work
-        mLastTouchX = (viewCursorRingBounds.left + viewCursorRingBounds.right) / 2;
-        mLastTouchY = (viewCursorRingBounds.top + viewCursorRingBounds.bottom) / 2;
-        if (mHeightCanMeasure == false) {
-            return keyHandled;
-        }
-        Rect visRect = new Rect();
-        calcOurVisibleRect(visRect);
-        Rect outset = new Rect(visRect);
-        int maxXScroll = visRect.width() / 2;
-        int maxYScroll = visRect.height() / 2;
-        outset.inset(-maxXScroll, -maxYScroll);
-        if (Rect.intersects(outset, viewCursorRingBounds) == false) {
-            return keyHandled;
-        }
-        // FIXME: Necessary because ScrollView/ListView do not scroll left/right
-        int maxH = Math.min(viewCursorRingBounds.right - visRect.right,
-                maxXScroll);
-        if (maxH > 0) {
-            pinScrollBy(maxH, 0, true, 0);
-        } else {
-            maxH = Math.max(viewCursorRingBounds.left - visRect.left,
-                    -maxXScroll);
-            if (maxH < 0) {
-                pinScrollBy(maxH, 0, true, 0);
-            }
-        }
-        if (mLastCursorBounds.isEmpty()) return keyHandled;
-        if (mLastCursorBounds.equals(contentCursorRingBounds)) {
-            return keyHandled;
-        }
-        if (DebugFlags.WEB_VIEW) {
-            Log.v(LOGTAG, "navHandledKey contentCursorRingBounds="
-                    + contentCursorRingBounds);
-        }
-        mWebView.requestRectangleOnScreen(viewCursorRingBounds);
-        return keyHandled;
-    }
-
     /**
      * @return Whether accessibility script has been injected.
      */
@@ -10160,9 +9173,6 @@
      */
     @Deprecated
     public void debugDump() {
-        checkThread();
-        nativeDebugDump();
-        mWebViewCore.sendMessage(EventHub.DUMP_NAVTREE);
     }
 
     /**
@@ -10208,17 +9218,6 @@
         cm.setPrimaryClip(clip);
     }
 
-    /**
-     *  Update our cache with updatedText.
-     *  @param updatedText  The new text to put in our cache.
-     *  @hide
-     */
-    protected void updateCachedTextfield(String updatedText) {
-        // Also place our generation number so that when we look at the cache
-        // we recognize that it is up to date.
-        nativeUpdateCachedTextfield(updatedText, mTextGeneration);
-    }
-
     /*package*/ void autoFillForm(int autoFillQueryId) {
         mWebViewCore.sendMessage(EventHub.AUTOFILL_FORM, autoFillQueryId, /* unused */0);
     }
@@ -10295,44 +9294,18 @@
      * @return true if the focused item is an editable text field.
      */
     boolean focusCandidateIsEditableText() {
-        boolean isEditable = false;
-        // TODO: reverse sDisableNavcache so that its name is positive
-        boolean isNavcacheEnabled = !sDisableNavcache;
-        if (isNavcacheEnabled) {
-            isEditable = nativeFocusCandidateIsEditableText(mNativeClass);
-        } else if (mFocusedNode != null) {
-            isEditable = mFocusedNode.mEditable;
+        if (mFocusedNode != null) {
+            return mFocusedNode.mEditable;
         }
-        return isEditable;
+        return false;
     }
 
-    // TODO: Remove this
-    Rect cursorRingBounds() {
-        if (sDisableNavcache) {
-            return new Rect();
-        }
-        return nativeGetCursorRingBounds();
+    // Called via JNI
+    private void postInvalidate() {
+        mWebView.postInvalidate();
     }
 
-    private native int nativeCacheHitFramePointer();
-    private native boolean  nativeCacheHitIsPlugin();
-    private native Rect nativeCacheHitNodeBounds();
-    private native int nativeCacheHitNodePointer();
-    /* package */ native void nativeClearCursor();
     private native void     nativeCreate(int ptr, String drawableDir, boolean isHighEndGfx);
-    private native int      nativeCursorFramePointer();
-    private native Rect     nativeCursorNodeBounds();
-    private native int nativeCursorNodePointer();
-    private native boolean  nativeCursorIntersects(Rect visibleRect);
-    private native boolean  nativeCursorIsAnchor();
-    private native boolean  nativeCursorIsTextInput();
-    private native Point    nativeCursorPosition();
-    private native String   nativeCursorText();
-    /**
-     * Returns true if the native cursor node says it wants to handle key events
-     * (ala plugins). This can only be called if mNativeClass is non-zero!
-     */
-    private native boolean  nativeCursorWantsKeyEvents();
     private native void     nativeDebugDump();
     private native void     nativeDestroy();
 
@@ -10350,81 +9323,18 @@
             Rect viewRect, RectF visibleRect, float scale, int extras);
     private native void     nativeUpdateDrawGLFunction(Rect rect, Rect viewRect,
             RectF visibleRect, float scale);
-    private native void     nativeExtendSelection(int x, int y);
-    /* package */ native int      nativeFocusCandidateFramePointer();
-    /* package */ native boolean  nativeFocusCandidateHasNextTextfield();
-    /* package */ native boolean  nativeFocusCandidateIsPassword();
-    private native boolean  nativeFocusCandidateIsRtlText();
-    private native boolean  nativeFocusCandidateIsTextInput();
-    private native boolean nativeFocusCandidateIsEditableText(int nativeClass);
-    /* package */ native int      nativeFocusCandidateMaxLength();
-    /* package */ native boolean  nativeFocusCandidateIsAutoComplete();
-    /* package */ native boolean  nativeFocusCandidateIsSpellcheck();
-    /* package */ native String   nativeFocusCandidateName();
-    private native Rect     nativeFocusCandidateNodeBounds();
-    /**
-     * @return A Rect with left, top, right, bottom set to the corresponding
-     * padding values in the focus candidate, if it is a textfield/textarea with
-     * a style.  Otherwise return null.  This is not actually a rectangle; Rect
-     * is being used to pass four integers.
-     */
-    private native Rect     nativeFocusCandidatePaddingRect();
-    /* package */ native int      nativeFocusCandidatePointer();
-    private native String   nativeFocusCandidateText();
-    /* package */ native float    nativeFocusCandidateTextSize();
-    /* package */ native int nativeFocusCandidateLineHeight();
-    /**
-     * Returns an integer corresponding to WebView.cpp::type.
-     * See WebTextView.setType()
-     */
-    private native int      nativeFocusCandidateType();
-    private native int      nativeFocusCandidateLayerId();
-    private native boolean  nativeFocusIsPlugin();
-    private native Rect     nativeFocusNodeBounds();
-    /* package */ native int nativeFocusNodePointer();
-    private native Rect     nativeGetCursorRingBounds();
     private native String   nativeGetSelection();
-    private native boolean  nativeHasCursorNode();
-    private native boolean  nativeHasFocusNode();
-    private native void     nativeHideCursor();
-    private native boolean  nativeHitSelection(int x, int y);
-    private native String   nativeImageURI(int x, int y);
     private native Rect     nativeLayerBounds(int layer);
-    /* package */ native boolean nativeMoveCursorToNextTextInput();
-    // return true if the page has been scrolled
-    private native boolean  nativeMotionUp(int x, int y, int slop);
-    // returns false if it handled the key
-    private native boolean  nativeMoveCursor(int keyCode, int count,
-            boolean noScroll);
-    private native int      nativeMoveGeneration();
-    /**
-     * @return true if the page should get the shift and arrow keys, rather
-     * than select text/navigation.
-     *
-     * If the focus is a plugin, or if the focus and cursor match and are
-     * a contentEditable element, then the page should handle these keys.
-     */
-    private native boolean  nativePageShouldHandleShiftAndArrows();
-    private native boolean  nativePointInNavCache(int x, int y, int slop);
-    private native void     nativeSelectBestAt(Rect rect);
-    private native void     nativeSelectAt(int x, int y);
-    private native void     nativeSetExtendSelection();
-    private native void     nativeSetFindIsUp(boolean isUp);
     private native void     nativeSetHeightCanMeasure(boolean measure);
     private native boolean  nativeSetBaseLayer(int nativeInstance,
             int layer, Region invalRegion,
             boolean showVisualIndicator, boolean isPictureAfterFirstLayout);
     private native int      nativeGetBaseLayer();
-    private native void     nativeShowCursorTimed();
     private native void     nativeReplaceBaseContent(int content);
     private native void     nativeCopyBaseContentToPicture(Picture pict);
     private native boolean  nativeHasContent();
-    private native void     nativeSetSelectionPointer(int nativeInstance,
-            boolean set, float scale, int x, int y);
-    private native boolean  nativeStartSelection(int x, int y);
     private native void     nativeStopGL();
     private native Rect     nativeSubtractLayers(Rect content);
-    private native int      nativeTextGeneration();
     private native void     nativeDiscardAllTextures();
     private native void     nativeTileProfilingStart();
     private native float    nativeTileProfilingStop();
@@ -10433,14 +9343,6 @@
     private native int      nativeTileProfilingNumTilesInFrame(int frame);
     private native int      nativeTileProfilingGetInt(int frame, int tile, String key);
     private native float    nativeTileProfilingGetFloat(int frame, int tile, String key);
-    // Never call this version except by updateCachedTextfield(String) -
-    // we always want to pass in our generation number.
-    private native void     nativeUpdateCachedTextfield(String updatedText,
-            int generation);
-    private native boolean  nativeWordSelection(int x, int y);
-    // return NO_LEFTEDGE means failure.
-    static final int NO_LEFTEDGE = -1;
-    native int nativeGetBlockLeftEdge(int x, int y, float scale);
 
     private native void     nativeUseHardwareAccelSkia(boolean enabled);
 
@@ -10464,7 +9366,6 @@
      */
     private static native void     nativeOnTrimMemory(int level);
     private static native void nativeSetPauseDrawing(int instance, boolean pause);
-    private static native boolean nativeDisableNavcache();
     private static native void nativeSetTextSelection(int instance, int selection);
     private static native int nativeGetHandleLayerId(int instance, int handle,
             Rect cursorLocation);
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 4bda5ef..65356f5 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -610,15 +610,9 @@
     private native void nativeSetFocusControllerActive(int nativeClass,
             boolean active);
 
-    private native void nativeSaveDocumentState(int nativeClass, int frame);
+    private native void nativeSaveDocumentState(int nativeClass);
 
-    private native void nativeMoveFocus(int nativeClass, int framePtr,
-            int nodePointer);
-    private native void nativeMoveMouse(int nativeClass, int framePtr, int x,
-            int y);
-
-    private native void nativeMoveMouseIfLatest(int nativeClass,
-            int moveGeneration, int framePtr, int x, int y);
+    private native void nativeMoveMouse(int nativeClass, int x, int y);
 
     private native String nativeRetrieveHref(int nativeClass, int x, int y);
     private native String nativeRetrieveAnchorText(int nativeClass,
@@ -632,16 +626,12 @@
             int[] idArray, int[] xArray, int[] yArray, int count,
             int actionIndex, int metaState);
 
-    private native void nativeUpdateFrameCache(int nativeClass);
-
     private native void nativeSetBackgroundColor(int nativeClass, int color);
 
     private native void nativeDumpDomTree(int nativeClass, boolean useFile);
 
     private native void nativeDumpRenderTree(int nativeClass, boolean useFile);
 
-    private native void nativeDumpNavTree(int nativeClass);
-
     private native void nativeSetJsFlags(int nativeClass, String flags);
 
     /**
@@ -799,21 +789,6 @@
         String mHistoryUrl;
     }
 
-    static class CursorData {
-        CursorData() {}
-        CursorData(int frame, int node, int x, int y) {
-            mFrame = frame;
-            mNode = node;
-            mX = x;
-            mY = y;
-        }
-        int mMoveGeneration;
-        int mFrame;
-        int mNode;
-        int mX;
-        int mY;
-    }
-
     static class JSInterfaceData {
         Object mObject;
         String mInterfaceName;
@@ -970,8 +945,8 @@
 
         static final String[] HandlerDebugString = {
             "REVEAL_SELECTION", // 96
-            "REQUEST_LABEL", // 97
-            "UPDATE_FRAME_CACHE_IF_LOADING", // = 98
+            "", // 97
+            "", // = 98
             "SCROLL_TEXT_INPUT", // = 99
             "LOAD_URL", // = 100;
             "STOP_LOADING", // = 101;
@@ -990,7 +965,7 @@
             "REPLACE_TEXT", // = 114;
             "PASS_TO_JS", // = 115;
             "SET_GLOBAL_BOUNDS", // = 116;
-            "UPDATE_CACHE_AND_TEXT_ENTRY", // = 117;
+            "", // = 117;
             "CLICK", // = 118;
             "SET_NETWORK_STATE", // = 119;
             "DOC_HAS_IMAGES", // = 120;
@@ -1008,8 +983,8 @@
             "POST_URL", // = 132;
             "SPLIT_PICTURE_SET", // = 133;
             "CLEAR_CONTENT", // = 134;
-            "SET_MOVE_MOUSE", // = 135;
-            "SET_MOVE_MOUSE_IF_LATEST", // = 136;
+            "", // = 135;
+            "", // = 136;
             "REQUEST_CURSOR_HREF", // = 137;
             "ADD_JS_INTERFACE", // = 138;
             "LOAD_DATA", // = 139;
@@ -1040,8 +1015,6 @@
     public class EventHub {
         // Message Ids
         static final int REVEAL_SELECTION = 96;
-        static final int REQUEST_LABEL = 97;
-        static final int UPDATE_FRAME_CACHE_IF_LOADING = 98;
         static final int SCROLL_TEXT_INPUT = 99;
         static final int LOAD_URL = 100;
         static final int STOP_LOADING = 101;
@@ -1060,7 +1033,6 @@
         static final int REPLACE_TEXT = 114;
         static final int PASS_TO_JS = 115;
         static final int SET_GLOBAL_BOUNDS = 116;
-        static final int UPDATE_CACHE_AND_TEXT_ENTRY = 117;
         static final int CLICK = 118;
         static final int SET_NETWORK_STATE = 119;
         static final int DOC_HAS_IMAGES = 120;
@@ -1070,7 +1042,6 @@
         static final int SINGLE_LISTBOX_CHOICE = 124;
         public static final int MESSAGE_RELAY = 125;
         static final int SET_BACKGROUND_COLOR = 126;
-        static final int SET_MOVE_FOCUS = 127;
         static final int SAVE_DOCUMENT_STATE = 128;
         static final int DELETE_SURROUNDING_TEXT = 129;
 
@@ -1082,7 +1053,6 @@
 
         // UI nav messages
         static final int SET_MOVE_MOUSE = 135;
-        static final int SET_MOVE_MOUSE_IF_LATEST = 136;
         static final int REQUEST_CURSOR_HREF = 137;
         static final int ADD_JS_INTERFACE = 138;
         static final int LOAD_DATA = 139;
@@ -1102,7 +1072,6 @@
         static final int ON_PAUSE = 143;
         static final int ON_RESUME = 144;
         static final int FREE_MEMORY = 145;
-        static final int VALID_NODE_BOUNDS = 146;
 
         // Load and save web archives
         static final int SAVE_WEBARCHIVE = 147;
@@ -1122,7 +1091,6 @@
         // debugging
         static final int DUMP_DOMTREE = 170;
         static final int DUMP_RENDERTREE = 171;
-        static final int DUMP_NAVTREE = 172;
 
         static final int SET_JS_FLAGS = 174;
         static final int CONTENT_INVALIDATE_ALL = 175;
@@ -1201,7 +1169,7 @@
         private EventHub() {}
 
         private static final int FIRST_PACKAGE_MSG_ID = REVEAL_SELECTION;
-        private static final int LAST_PACKAGE_MSG_ID = VALID_NODE_BOUNDS;
+        private static final int LAST_PACKAGE_MSG_ID = REMOVE_JS_INTERFACE;
 
         /**
          * Transfer all messages to the newly created webcore thread handler.
@@ -1252,6 +1220,12 @@
                             // Time to take down the world. Cancel all pending
                             // loads and destroy the native view and frame.
                             synchronized (WebViewCore.this) {
+                                mCallbackProxy.shutdown();
+                                // Wake up the WebCore thread just in case it is waiting for a
+                                // JavaScript dialog.
+                                synchronized (mCallbackProxy) {
+                                    mCallbackProxy.notify();
+                                }
                                 mBrowserFrame.destroy();
                                 mBrowserFrame = null;
                                 mSettings.onDestroyed();
@@ -1264,23 +1238,6 @@
                             nativeRevealSelection(mNativeClass);
                             break;
 
-                        case REQUEST_LABEL:
-                            if (mWebView != null) {
-                                int nodePointer = msg.arg2;
-                                String label = nativeRequestLabel(mNativeClass,
-                                        msg.arg1, nodePointer);
-                                if (label != null && label.length() > 0) {
-                                    Message.obtain(mWebView.mPrivateHandler,
-                                            WebViewClassic.RETURN_LABEL, nodePointer,
-                                            0, label).sendToTarget();
-                                }
-                            }
-                            break;
-
-                        case UPDATE_FRAME_CACHE_IF_LOADING:
-                            nativeUpdateFrameCacheIfLoading(mNativeClass);
-                            break;
-
                         case SCROLL_TEXT_INPUT:
                             float xPercent;
                             if (msg.obj == null) {
@@ -1381,8 +1338,8 @@
                             // note: these are in document coordinates
                             // (inv-zoom)
                             Point pt = (Point) msg.obj;
-                            nativeSetScrollOffset(mNativeClass, msg.arg1,
-                                    msg.arg2 == 1, pt.x, pt.y);
+                            nativeSetScrollOffset(mNativeClass,
+                                    msg.arg1 == 1, pt.x, pt.y);
                             break;
 
                         case SET_GLOBAL_BOUNDS:
@@ -1486,8 +1443,7 @@
                         }
 
                         case SAVE_DOCUMENT_STATE: {
-                            CursorData cDat = (CursorData) msg.obj;
-                            nativeSaveDocumentState(mNativeClass, cDat.mFrame);
+                            nativeSaveDocumentState(mNativeClass);
                             break;
                         }
 
@@ -1562,22 +1518,8 @@
                             mBrowserFrame.documentAsText((Message) msg.obj);
                             break;
 
-                        case SET_MOVE_FOCUS:
-                            CursorData focusData = (CursorData) msg.obj;
-                            nativeMoveFocus(mNativeClass, focusData.mFrame, focusData.mNode);
-                            break;
-
                         case SET_MOVE_MOUSE:
-                            CursorData cursorData = (CursorData) msg.obj;
-                            nativeMoveMouse(mNativeClass,
-                                     cursorData.mFrame, cursorData.mX, cursorData.mY);
-                            break;
-
-                        case SET_MOVE_MOUSE_IF_LATEST:
-                            CursorData cData = (CursorData) msg.obj;
-                            nativeMoveMouseIfLatest(mNativeClass,
-                                    cData.mMoveGeneration,
-                                    cData.mFrame, cData.mX, cData.mY);
+                            nativeMoveMouse(mNativeClass, msg.arg1, msg.arg2);
                             break;
 
                         case REQUEST_CURSOR_HREF: {
@@ -1591,15 +1533,6 @@
                             break;
                         }
 
-                        case UPDATE_CACHE_AND_TEXT_ENTRY:
-                            nativeUpdateFrameCache(mNativeClass);
-                            // FIXME: this should provide a minimal rectangle
-                            if (mWebView != null) {
-                                mWebView.getWebView().postInvalidate();
-                            }
-                            sendUpdateTextEntry();
-                            break;
-
                         case DOC_HAS_IMAGES:
                             Message imageResult = (Message) msg.obj;
                             imageResult.arg1 =
@@ -1655,10 +1588,6 @@
                             nativeDumpRenderTree(mNativeClass, msg.arg1 == 1);
                             break;
 
-                        case DUMP_NAVTREE:
-                            nativeDumpNavTree(mNativeClass);
-                            break;
-
                         case SET_JS_FLAGS:
                             nativeSetJsFlags(mNativeClass, (String)msg.obj);
                             break;
@@ -1705,21 +1634,6 @@
                             nativeProvideVisitedHistory(mNativeClass, (String[])msg.obj);
                             break;
 
-                        case VALID_NODE_BOUNDS: {
-                            MotionUpData motionUpData = (MotionUpData) msg.obj;
-                            if (!nativeValidNodeAndBounds(
-                                    mNativeClass, motionUpData.mFrame,
-                                    motionUpData.mNode, motionUpData.mBounds)) {
-                                nativeUpdateFrameCache(mNativeClass);
-                            }
-                            Message message = mWebView.mPrivateHandler
-                                    .obtainMessage(WebViewClassic.DO_MOTION_UP,
-                                    motionUpData.mX, motionUpData.mY);
-                            mWebView.mPrivateHandler.sendMessageAtFrontOfQueue(
-                                    message);
-                            break;
-                        }
-
                         case HIDE_FULLSCREEN:
                             nativeFullScreenPluginHidden(mNativeClass, msg.arg1);
                             break;
@@ -2117,8 +2031,6 @@
             if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "viewSizeChanged");
             contentDraw();
         }
-        mEventHub.sendMessage(Message.obtain(null,
-                EventHub.UPDATE_CACHE_AND_TEXT_ENTRY));
     }
 
     // Calculate width to be used in webkit window.
@@ -2139,13 +2051,6 @@
         return width;
     }
 
-    private void sendUpdateTextEntry() {
-        if (mWebView != null) {
-            Message.obtain(mWebView.mPrivateHandler,
-                    WebViewClassic.UPDATE_TEXT_ENTRY_MSG_ID).sendToTarget();
-        }
-    }
-
     // Utility method for exceededDatabaseQuota and reachedMaxAppCacheSize
     // callbacks. Computes the sum of database quota for all origins.
     private long getUsedQuota() {
@@ -2448,7 +2353,6 @@
 
     // called by JNI
     private void sendNotifyProgressFinished() {
-        sendUpdateTextEntry();
         contentDraw();
     }
 
@@ -2501,10 +2405,8 @@
         }
 
         // remove the touch highlight when moving to a new page
-        if (WebViewClassic.sDisableNavcache) {
-            mWebView.mPrivateHandler.sendEmptyMessage(
-                    WebViewClassic.HIT_TEST_RESULT);
-        }
+        mWebView.mPrivateHandler.sendEmptyMessage(
+                WebViewClassic.HIT_TEST_RESULT);
 
         // reset the scroll position, the restored offset and scales
         mRestoredX = mRestoredY = 0;
@@ -2856,7 +2758,6 @@
                 findText).sendToTarget();
     }
 
-    private native void nativeUpdateFrameCacheIfLoading(int nativeClass);
     private native void nativeRevealSelection(int nativeClass);
     private native String nativeRequestLabel(int nativeClass, int framePtr,
             int nodePtr);
@@ -2867,7 +2768,7 @@
             float xPercent, int y);
 
     // these must be in document space (i.e. not scaled/zoomed).
-    private native void nativeSetScrollOffset(int nativeClass, int gen,
+    private native void nativeSetScrollOffset(int nativeClass,
             boolean sendScrollEvent, int dx, int dy);
 
     private native void nativeSetGlobalBounds(int nativeClass, int x, int y,
@@ -3062,11 +2963,8 @@
     }
 
     // called by JNI
-    @SuppressWarnings("unused")
     private void selectAt(int x, int y) {
-        if (mWebView != null) {
-            mWebView.mPrivateHandler.obtainMessage(WebViewClassic.SELECT_AT, x, y).sendToTarget();
-        }
+        // TODO: Figure out what to do with this (b/6111818)
     }
 
     private void useMockDeviceOrientation() {
@@ -3101,8 +2999,6 @@
     private native void nativeFreeMemory(int nativeClass);
     private native void nativeFullScreenPluginHidden(int nativeClass, int npp);
     private native void nativePluginSurfaceReady(int nativeClass);
-    private native boolean nativeValidNodeAndBounds(int nativeClass, int frame,
-            int node, Rect bounds);
 
     private native WebKitHitTest nativeHitTest(int nativeClass, int x, int y,
             int slop, boolean moveMouse);
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index e7b049e..2247678 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -643,20 +643,6 @@
         // remove the zoom control after double tap
         dismissZoomPicker();
 
-        /*
-         * If the double tap was on a plugin then either zoom to maximize the
-         * plugin on the screen or scale to overview mode.
-         */
-        Rect pluginBounds = mWebView.getPluginBounds(mAnchorX, mAnchorY);
-        if (pluginBounds != null) {
-            if (mWebView.isRectFitOnScreen(pluginBounds)) {
-                zoomToOverview();
-            } else {
-                mWebView.centerFitRect(pluginBounds);
-            }
-            return;
-        }
-
         final float newTextWrapScale;
         if (settings.getUseFixedViewport()) {
             newTextWrapScale = Math.max(mActualScale, getReadingLevelScale());
diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java
index 85252af..2a74f6a 100644
--- a/core/java/android/widget/CalendarView.java
+++ b/core/java/android/widget/CalendarView.java
@@ -154,21 +154,25 @@
 
     private final int mWeekSeperatorLineWidth;
 
-    private final int mDateTextSize;
+    private int mDateTextSize;
 
-    private final Drawable mSelectedDateVerticalBar;
+    private Drawable mSelectedDateVerticalBar;
 
     private final int mSelectedDateVerticalBarWidth;
 
-    private final int mSelectedWeekBackgroundColor;
+    private int mSelectedWeekBackgroundColor;
 
-    private final int mFocusedMonthDateColor;
+    private int mFocusedMonthDateColor;
 
-    private final int mUnfocusedMonthDateColor;
+    private int mUnfocusedMonthDateColor;
 
-    private final int mWeekSeparatorLineColor;
+    private int mWeekSeparatorLineColor;
 
-    private final int mWeekNumberColor;
+    private int mWeekNumberColor;
+
+    private int mWeekDayTextAppearanceResId;
+
+    private int mDateTextAppearanceResId;
 
     /**
      * The top offset of the weeks list.
@@ -366,15 +370,11 @@
         mSelectedDateVerticalBar = attributesArray.getDrawable(
                 R.styleable.CalendarView_selectedDateVerticalBar);
 
-        int dateTextAppearanceResId= attributesArray.getResourceId(
+        mDateTextAppearanceResId = attributesArray.getResourceId(
                 R.styleable.CalendarView_dateTextAppearance, R.style.TextAppearance_Small);
-        TypedArray dateTextAppearance = context.obtainStyledAttributes(dateTextAppearanceResId,
-                com.android.internal.R.styleable.TextAppearance);
-        mDateTextSize = dateTextAppearance.getDimensionPixelSize(
-                R.styleable.TextAppearance_textSize, DEFAULT_DATE_TEXT_SIZE);
-        dateTextAppearance.recycle();
+        updateDateTextSize();
 
-        int weekDayTextAppearanceResId = attributesArray.getResourceId(
+        mWeekDayTextAppearanceResId = attributesArray.getResourceId(
                 R.styleable.CalendarView_weekDayTextAppearance,
                 DEFAULT_WEEK_DAY_TEXT_APPEARANCE_RES_ID);
         attributesArray.recycle();
@@ -400,7 +400,7 @@
         mDayNamesHeader = (ViewGroup) content.findViewById(com.android.internal.R.id.day_names);
         mMonthName = (TextView) content.findViewById(com.android.internal.R.id.month_name);
 
-        setUpHeader(weekDayTextAppearanceResId);
+        setUpHeader();
         setUpListView();
         setUpAdapter();
 
@@ -417,6 +417,235 @@
         invalidate();
     }
 
+    /**
+     * Sets the number of weeks to be shown.
+     *
+     * @param count The shown week count.
+     */
+    public void setShownWeekCount(int count) {
+        if (mShownWeekCount != count) {
+            mShownWeekCount = count;
+            invalidate();
+        }
+    }
+
+    /**
+     * Gets the number of weeks to be shown.
+     *
+     * @return The shown week count.
+     */
+    public int getShownWeekCount() {
+        return mShownWeekCount;
+    }
+
+    /**
+     * Sets the background color for the selected week.
+     *
+     * @param color The week background color.
+     */
+    public void setSelectedWeekBackgroundColor(int color) {
+        if (mSelectedWeekBackgroundColor != color) {
+            mSelectedWeekBackgroundColor = color;
+            final int childCount = mListView.getChildCount();
+            for (int i = 0; i < childCount; i++) {
+                WeekView weekView = (WeekView) mListView.getChildAt(i);
+                if (weekView.mHasSelectedDay) {
+                    weekView.invalidate();
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets the background color for the selected week.
+     *
+     * @return The week background color.
+     */
+    public int getSelectedWeekBackgroundColor() {
+        return mSelectedWeekBackgroundColor;
+    }
+
+    /**
+     * Sets the color for the dates of the focused month.
+     *
+     * @param color The focused month date color.
+     */
+    public void setFocusedMonthDateColor(int color) {
+        if (mFocusedMonthDateColor != color) {
+            mFocusedMonthDateColor = color;
+            final int childCount = mListView.getChildCount();
+            for (int i = 0; i < childCount; i++) {
+                WeekView weekView = (WeekView) mListView.getChildAt(i);
+                if (weekView.mHasFocusedDay) {
+                    weekView.invalidate();
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets the color for the dates in the focused month.
+     *
+     * @return The focused month date color.
+     */
+    public int getFocusedMonthDateColor() {
+        return mFocusedMonthDateColor;
+    }
+
+    /**
+     * Sets the color for the dates of a not focused month.
+     *
+     * @param color A not focused month date color.
+     */
+    public void setUnfocusedMonthDateColor(int color) {
+        if (mUnfocusedMonthDateColor != color) {
+            mUnfocusedMonthDateColor = color;
+            final int childCount = mListView.getChildCount();
+            for (int i = 0; i < childCount; i++) {
+                WeekView weekView = (WeekView) mListView.getChildAt(i);
+                if (weekView.mHasUnfocusedDay) {
+                    weekView.invalidate();
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets the color for the dates in a not focused month.
+     *
+     * @return A not focused month date color.
+     */
+    public int getUnfocusedMonthDateColor() {
+        return mFocusedMonthDateColor;
+    }
+
+    /**
+     * Sets the color for the week numbers.
+     *
+     * @param color The week number color.
+     */
+    public void setWeekNumberColor(int color) {
+        if (mWeekNumberColor != color) {
+            mWeekNumberColor = color;
+            if (mShowWeekNumber) {
+                invalidateAllWeekViews();
+            }
+        }
+    }
+
+    /**
+     * Gets the color for the week numbers.
+     *
+     * @return The week number color.
+     */
+    public int getWeekNumberColor() {
+        return mWeekNumberColor;
+    }
+
+    /**
+     * Sets the color for the separator line between weeks.
+     *
+     * @param color The week separator color.
+     */
+    public void setWeekSeparatorLineColor(int color) {
+        if (mWeekSeparatorLineColor != color) {
+            mWeekSeparatorLineColor = color;
+            invalidateAllWeekViews();
+        }
+    }
+
+    /**
+     * Gets the color for the separator line between weeks.
+     *
+     * @return The week separator color.
+     */
+    public int getWeekSeparatorLineColor() {
+        return mWeekSeparatorLineColor;
+    }
+
+    /**
+     * Sets the drawable for the vertical bar shown at the beginning and at
+     * the end of the selected date.
+     *
+     * @param resourceId The vertical bar drawable resource id.
+     */
+    public void setSelectedDateVerticalBar(int resourceId) {
+        Drawable drawable = getResources().getDrawable(resourceId);
+        setSelectedDateVerticalBar(drawable);
+    }
+
+    /**
+     * Sets the drawable for the vertical bar shown at the beginning and at
+     * the end of the selected date.
+     *
+     * @param drawable The vertical bar drawable.
+     */
+    public void setSelectedDateVerticalBar(Drawable drawable) {
+        if (mSelectedDateVerticalBar != drawable) {
+            mSelectedDateVerticalBar = drawable;
+            final int childCount = mListView.getChildCount();
+            for (int i = 0; i < childCount; i++) {
+                WeekView weekView = (WeekView) mListView.getChildAt(i);
+                if (weekView.mHasSelectedDay) {
+                    weekView.invalidate();
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets the drawable for the vertical bar shown at the beginning and at
+     * the end of the selected date.
+     *
+     * @return The vertical bar drawable.
+     */
+    public Drawable getSelectedDateVerticalBar() {
+        return mSelectedDateVerticalBar;
+    }
+
+    /**
+     * Sets the text appearance for the week day abbreviation of the calendar header.
+     *
+     * @param resourceId The text appearance resource id.
+     */
+    public void setWeekDayTextAppearance(int resourceId) {
+        if (mWeekDayTextAppearanceResId != resourceId) {
+            mWeekDayTextAppearanceResId = resourceId;
+            setUpHeader();
+        }
+    }
+
+    /**
+     * Gets the text appearance for the week day abbreviation of the calendar header.
+     *
+     * @return The text appearance resource id.
+     */
+    public int getWeekDayTextAppearance() {
+        return mWeekDayTextAppearanceResId;
+    }
+
+    /**
+     * Sets the text appearance for the calendar dates.
+     *
+     * @param resourceId The text appearance resource id.
+     */
+    public void setDateTextAppearance(int resourceId) {
+        if (mDateTextAppearanceResId != resourceId) {
+            mDateTextAppearanceResId = resourceId;
+            updateDateTextSize();
+            invalidateAllWeekViews();
+        }
+    }
+
+    /**
+     * Gets the text appearance for the calendar dates.
+     *
+     * @return The text appearance resource id.
+     */
+    public int getDateTextAppearance() {
+        return mDateTextAppearanceResId;
+    }
+
     @Override
     public void setEnabled(boolean enabled) {
         mListView.setEnabled(enabled);
@@ -545,7 +774,7 @@
         }
         mShowWeekNumber = showWeekNumber;
         mAdapter.notifyDataSetChanged();
-        setUpHeader(DEFAULT_WEEK_DAY_TEXT_APPEARANCE_RES_ID);
+        setUpHeader();
     }
 
     /**
@@ -594,7 +823,7 @@
         mFirstDayOfWeek = firstDayOfWeek;
         mAdapter.init();
         mAdapter.notifyDataSetChanged();
-        setUpHeader(DEFAULT_WEEK_DAY_TEXT_APPEARANCE_RES_ID);
+        setUpHeader();
     }
 
     /**
@@ -655,6 +884,25 @@
         goTo(mTempDate, animate, true, center);
     }
 
+    private void updateDateTextSize() {
+        TypedArray dateTextAppearance = getContext().obtainStyledAttributes(
+                mDateTextAppearanceResId, R.styleable.TextAppearance);
+        mDateTextSize = dateTextAppearance.getDimensionPixelSize(
+                R.styleable.TextAppearance_textSize, DEFAULT_DATE_TEXT_SIZE);
+        dateTextAppearance.recycle();
+    }
+
+    /**
+     * Invalidates all week views.
+     */
+    private void invalidateAllWeekViews() {
+        final int childCount = mListView.getChildCount();
+        for (int i = 0; i < childCount; i++) {
+            View view = mListView.getChildAt(i);
+            view.invalidate();
+        }
+    }
+
     /**
      * Sets the current locale.
      *
@@ -727,7 +975,7 @@
     /**
      * Sets up the strings to be used by the header.
      */
-    private void setUpHeader(int weekDayTextAppearanceResId) {
+    private void setUpHeader() {
         mDayLabels = new String[mDaysPerWeek];
         for (int i = mFirstDayOfWeek, count = mFirstDayOfWeek + mDaysPerWeek; i < count; i++) {
             int calendarDay = (i > Calendar.SATURDAY) ? i - Calendar.SATURDAY : i;
@@ -743,8 +991,8 @@
         }
         for (int i = 1, count = mDayNamesHeader.getChildCount(); i < count; i++) {
             label = (TextView) mDayNamesHeader.getChildAt(i);
-            if (weekDayTextAppearanceResId > -1) {
-                label.setTextAppearance(mContext, weekDayTextAppearanceResId);
+            if (mWeekDayTextAppearanceResId > -1) {
+                label.setTextAppearance(mContext, mWeekDayTextAppearanceResId);
             }
             if (i < mDaysPerWeek + 1) {
                 label.setText(mDayLabels[i - 1]);
@@ -1198,6 +1446,12 @@
         // Quick lookup for checking which days are in the focus month
         private boolean[] mFocusDay;
 
+        // Whether this view has a focused day.
+        private boolean mHasFocusedDay;
+
+        // Whether this view has only focused days.
+        private boolean mHasUnfocusedDay;
+
         // The first day displayed by this item
         private Calendar mFirstDay;
 
@@ -1235,11 +1489,8 @@
         public WeekView(Context context) {
             super(context);
 
-            mHeight = (mListView.getHeight() - mListView.getPaddingTop() - mListView
-                    .getPaddingBottom()) / mShownWeekCount;
-
             // Sets up any standard paints that will be used
-            setPaintProperties();
+            initilaizePaints();
         }
 
         /**
@@ -1281,8 +1532,12 @@
             mFirstDay = (Calendar) mTempDate.clone();
             mMonthOfFirstWeekDay = mTempDate.get(Calendar.MONTH);
 
+            mHasUnfocusedDay = true;
             for (; i < mNumCells; i++) {
-                mFocusDay[i] = (mTempDate.get(Calendar.MONTH) == focusedMonth);
+                final boolean isFocusedDay = (mTempDate.get(Calendar.MONTH) == focusedMonth);
+                mFocusDay[i] = isFocusedDay;
+                mHasFocusedDay |= isFocusedDay;
+                mHasUnfocusedDay &= !isFocusedDay;
                 // do not draw dates outside the valid range to avoid user confusion
                 if (mTempDate.before(mMinDate) || mTempDate.after(mMaxDate)) {
                     mDayNumbers[i] = "";
@@ -1302,18 +1557,15 @@
         }
 
         /**
-         * Sets up the text and style properties for painting.
+         * Initialize the paint isntances.
          */
-        private void setPaintProperties() {
+        private void initilaizePaints() {
             mDrawPaint.setFakeBoldText(false);
             mDrawPaint.setAntiAlias(true);
-            mDrawPaint.setTextSize(mDateTextSize);
             mDrawPaint.setStyle(Style.FILL);
 
             mMonthNumDrawPaint.setFakeBoldText(true);
             mMonthNumDrawPaint.setAntiAlias(true);
-            mMonthNumDrawPaint.setTextSize(mDateTextSize);
-            mMonthNumDrawPaint.setColor(mFocusedMonthDateColor);
             mMonthNumDrawPaint.setStyle(Style.FILL);
             mMonthNumDrawPaint.setTextAlign(Align.CENTER);
         }
@@ -1369,7 +1621,7 @@
         @Override
         protected void onDraw(Canvas canvas) {
             drawBackground(canvas);
-            drawWeekNumbers(canvas);
+            drawWeekNumbersAndDates(canvas);
             drawWeekSeparators(canvas);
             drawSelectedDateVerticalBars(canvas);
         }
@@ -1401,12 +1653,13 @@
          *
          * @param canvas The canvas to draw on
          */
-        private void drawWeekNumbers(Canvas canvas) {
+        private void drawWeekNumbersAndDates(Canvas canvas) {
             float textHeight = mDrawPaint.getTextSize();
             int y = (int) ((mHeight + textHeight) / 2) - mWeekSeperatorLineWidth;
             int nDays = mNumCells;
 
             mDrawPaint.setTextAlign(Align.CENTER);
+            mDrawPaint.setTextSize(mDateTextSize);
             int i = 0;
             int divisor = 2 * nDays;
             if (mShowWeekNumber) {
@@ -1487,6 +1740,8 @@
 
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+            mHeight = (mListView.getHeight() - mListView.getPaddingTop() - mListView
+                    .getPaddingBottom()) / mShownWeekCount;
             setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mHeight);
         }
     }
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java
index 110c8f3..fd93980 100644
--- a/core/java/android/widget/DatePicker.java
+++ b/core/java/android/widget/DatePicker.java
@@ -162,7 +162,7 @@
         int endYear = attributesArray.getInt(R.styleable.DatePicker_endYear, DEFAULT_END_YEAR);
         String minDate = attributesArray.getString(R.styleable.DatePicker_minDate);
         String maxDate = attributesArray.getString(R.styleable.DatePicker_maxDate);
-        int layoutResourceId = attributesArray.getResourceId(R.styleable.DatePicker_layout,
+        int layoutResourceId = attributesArray.getResourceId(R.styleable.DatePicker_internalLayout,
                 R.layout.date_picker);
         attributesArray.recycle();
 
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index 6405ee9..3335da0 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -559,17 +559,17 @@
                 getResources().getDisplayMetrics());
         mSelectionDividerHeight = attributesArray.getDimensionPixelSize(
                 R.styleable.NumberPicker_selectionDividerHeight, defSelectionDividerHeight);
-        mMinHeight = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_minHeight,
-                SIZE_UNSPECIFIED);
-        mMaxHeight = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_maxHeight,
-                SIZE_UNSPECIFIED);
+        mMinHeight = attributesArray.getDimensionPixelSize(
+                R.styleable.NumberPicker_internalMinHeight, SIZE_UNSPECIFIED);
+        mMaxHeight = attributesArray.getDimensionPixelSize(
+                R.styleable.NumberPicker_internalMaxHeight, SIZE_UNSPECIFIED);
         if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED
                 && mMinHeight > mMaxHeight) {
             throw new IllegalArgumentException("minHeight > maxHeight");
         }
-        mMinWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_minWidth,
+        mMinWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_internalMinWidth,
                 SIZE_UNSPECIFIED);
-        mMaxWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_maxWidth,
+        mMaxWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_internalMaxWidth,
                 SIZE_UNSPECIFIED);
         if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED
                 && mMinWidth > mMaxWidth) {
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 62afd61..55acb74 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -1217,7 +1217,7 @@
     /**
      * Equivalent to calling ImageView.setImageBitmap
      * 
-     * @param viewId The id of the view whose drawable should change
+     * @param viewId The id of the view whose bitmap should change
      * @param bitmap The new Bitmap for the drawable
      */
     public void setImageViewBitmap(int viewId, Bitmap bitmap) {
@@ -1240,7 +1240,7 @@
      * and {@link Chronometer#start Chronometer.start()} or
      * {@link Chronometer#stop Chronometer.stop()}.
      * 
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the {@link Chronometer} to change
      * @param base The time at which the timer would have read 0:00.  This
      *             time should be based off of
      *             {@link android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime()}.
@@ -1261,7 +1261,7 @@
      *
      * If indeterminate is true, then the values for max and progress are ignored.
      * 
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the {@link ProgressBar} to change
      * @param max The 100% value for the progress bar
      * @param progress The current value of the progress bar.
      * @param indeterminate True if the progress bar is indeterminate, 
@@ -1367,7 +1367,7 @@
     /**
      * Equivalent to calling {@link android.widget.TextView#setTextColor(int)}.
      * 
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view whose text color should change
      * @param color Sets the text color for all the states (normal, selected,
      *            focused) to be this color.
      */
@@ -1380,7 +1380,7 @@
      *
      * @param appWidgetId The id of the app widget which contains the specified view. (This
      *      parameter is ignored in this deprecated method)
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the {@link AbsListView}
      * @param intent The intent of the service which will be
      *            providing data to the RemoteViewsAdapter
      * @deprecated This method has been deprecated. See
@@ -1395,7 +1395,7 @@
      * Equivalent to calling {@link android.widget.AbsListView#setRemoteViewsAdapter(Intent)}.
      * Can only be used for App Widgets.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the {@link AbsListView}
      * @param intent The intent of the service which will be
      *            providing data to the RemoteViewsAdapter
      */
@@ -1406,7 +1406,7 @@
     /**
      * Equivalent to calling {@link android.widget.AbsListView#smoothScrollToPosition(int, int)}.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view to change
      * @param position Scroll to this adapter position
      */
     public void setScrollPosition(int viewId, int position) {
@@ -1416,7 +1416,7 @@
     /**
      * Equivalent to calling {@link android.widget.AbsListView#smoothScrollToPosition(int, int)}.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view to change
      * @param offset Scroll by this adapter position offset
      */
     public void setRelativeScrollPosition(int viewId, int offset) {
@@ -1426,7 +1426,7 @@
     /**
      * Call a method taking one boolean on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1437,7 +1437,7 @@
     /**
      * Call a method taking one byte on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1448,7 +1448,7 @@
     /**
      * Call a method taking one short on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1459,7 +1459,7 @@
     /**
      * Call a method taking one int on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1470,7 +1470,7 @@
     /**
      * Call a method taking one long on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1481,7 +1481,7 @@
     /**
      * Call a method taking one float on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1492,7 +1492,7 @@
     /**
      * Call a method taking one double on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1503,7 +1503,7 @@
     /**
      * Call a method taking one char on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1514,7 +1514,7 @@
     /**
      * Call a method taking one String on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1525,7 +1525,7 @@
     /**
      * Call a method taking one CharSequence on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1536,7 +1536,7 @@
     /**
      * Call a method taking one Uri on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1550,7 +1550,7 @@
      * <p class="note">The bitmap will be flattened into the parcel if this object is
      * sent across processes, so it may end up using a lot of memory, and may be fairly slow.</p>
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1561,7 +1561,7 @@
     /**
      * Call a method taking one Bundle on a view in the layout for this RemoteViews.
      *
-     * @param viewId The id of the view whose text should change
+     * @param viewId The id of the view on which to call the method.
      * @param methodName The name of the method to call.
      * @param value The value to pass to the method.
      */
@@ -1570,10 +1570,11 @@
     }
 
     /**
+     * Call a method taking one Intent on a view in the layout for this RemoteViews.
      *
-     * @param viewId
-     * @param methodName
-     * @param value
+     * @param viewId The id of the view on which to call the method.
+     * @param methodName The name of the method to call.
+     * @param value The {@link android.content.Intent} to pass the method.
      */
     public void setIntent(int viewId, String methodName, Intent value) {
         addAction(new ReflectionAction(viewId, methodName, ReflectionAction.INTENT, value));
diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java
index ef1d7d0..7eff1aa 100644
--- a/core/java/android/widget/TimePicker.java
+++ b/core/java/android/widget/TimePicker.java
@@ -136,7 +136,7 @@
         TypedArray attributesArray = context.obtainStyledAttributes(
                 attrs, R.styleable.TimePicker, defStyle, 0);
         int layoutResourceId = attributesArray.getResourceId(
-                R.styleable.TimePicker_layout, R.layout.time_picker);
+                R.styleable.TimePicker_internalLayout, R.layout.time_picker);
         attributesArray.recycle();
 
         LayoutInflater inflater = (LayoutInflater) context.getSystemService(
diff --git a/core/java/com/android/internal/widget/TransportControlView.java b/core/java/com/android/internal/widget/TransportControlView.java
index 979eb81..2f52585 100644
--- a/core/java/com/android/internal/widget/TransportControlView.java
+++ b/core/java/com/android/internal/widget/TransportControlView.java
@@ -314,7 +314,7 @@
         final int flags = mTransportControlFlags;
         setVisibilityBasedOnFlag(mBtnPrev, flags, RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS);
         setVisibilityBasedOnFlag(mBtnNext, flags, RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
-        setVisibilityBasedOnFlag(mBtnPrev, flags,
+        setVisibilityBasedOnFlag(mBtnPlay, flags,
                 RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                 | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
                 | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
diff --git a/core/java/com/google/android/mms/pdu/PduPersister.java b/core/java/com/google/android/mms/pdu/PduPersister.java
index 7037b61..b04f890 100644
--- a/core/java/com/google/android/mms/pdu/PduPersister.java
+++ b/core/java/com/google/android/mms/pdu/PduPersister.java
@@ -513,6 +513,9 @@
         PduCacheEntry cacheEntry;
         synchronized(PDU_CACHE_INSTANCE) {
             if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
+                if (LOCAL_LOGV) {
+                    Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
+                }
                 try {
                     PDU_CACHE_INSTANCE.wait();
                 } catch (InterruptedException e) {
@@ -840,6 +843,9 @@
             // If the cache item is getting updated, wait until it's done updating before
             // purging it.
             if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
+                if (LOCAL_LOGV) {
+                    Log.v(TAG, "updateHeaders: " + uri + " blocked by isUpdating()");
+                }
                 try {
                     PDU_CACHE_INSTANCE.wait();
                 } catch (InterruptedException e) {
@@ -1002,6 +1008,9 @@
             PduCacheEntry cacheEntry;
             synchronized(PDU_CACHE_INSTANCE) {
                 if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
+                    if (LOCAL_LOGV) {
+                        Log.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
+                    }
                     try {
                         PDU_CACHE_INSTANCE.wait();
                     } catch (InterruptedException e) {
@@ -1097,6 +1106,9 @@
             // If the cache item is getting updated, wait until it's done updating before
             // purging it.
             if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
+                if (LOCAL_LOGV) {
+                    Log.v(TAG, "persist: " + uri + " blocked by isUpdating()");
+                }
                 try {
                     PDU_CACHE_INSTANCE.wait();
                 } catch (InterruptedException e) {
diff --git a/core/java/com/google/android/mms/util/PduCache.java b/core/java/com/google/android/mms/util/PduCache.java
index 87cb48e..de83124 100644
--- a/core/java/com/google/android/mms/util/PduCache.java
+++ b/core/java/com/google/android/mms/util/PduCache.java
@@ -161,6 +161,7 @@
     }
 
     private PduCacheEntry purgeSingleEntry(Uri key) {
+        mUpdating.remove(key);
         PduCacheEntry entry = super.purge(key);
         if (entry != null) {
             removeFromThreads(key, entry);
@@ -176,6 +177,7 @@
 
         mMessageBoxes.clear();
         mThreads.clear();
+        mUpdating.clear();
     }
 
     /**
@@ -216,6 +218,7 @@
             HashSet<Uri> msgBox = mMessageBoxes.remove(msgBoxId);
             if (msgBox != null) {
                 for (Uri key : msgBox) {
+                    mUpdating.remove(key);
                     PduCacheEntry entry = super.purge(key);
                     if (entry != null) {
                         removeFromThreads(key, entry);
@@ -240,6 +243,7 @@
         HashSet<Uri> thread = mThreads.remove(threadId);
         if (thread != null) {
             for (Uri key : thread) {
+                mUpdating.remove(key);
                 PduCacheEntry entry = super.purge(key);
                 if (entry != null) {
                     removeFromMessageBoxes(key, entry);
diff --git a/core/jni/android_database_SQLiteGlobal.cpp b/core/jni/android_database_SQLiteGlobal.cpp
index 9301183..acc2276 100644
--- a/core/jni/android_database_SQLiteGlobal.cpp
+++ b/core/jni/android_database_SQLiteGlobal.cpp
@@ -37,7 +37,7 @@
 // Called each time a message is logged.
 static void sqliteLogCallback(void* data, int iErrCode, const char* zMsg) {
     bool verboseLog = !!data;
-    if (iErrCode == 0 || iErrCode == SQLITE_CONSTRAINT) {
+    if (iErrCode == 0 || iErrCode == SQLITE_CONSTRAINT || iErrCode == SQLITE_SCHEMA) {
         if (verboseLog) {
             ALOGV(LOG_VERBOSE, SQLITE_LOG_TAG, "(%d) %s\n", iErrCode, zMsg);
         }
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index f0560c1..8e5db36 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -679,7 +679,7 @@
 
 static void android_view_GLES20Canvas_destroyDisplayList(JNIEnv* env,
         jobject clazz, DisplayList* displayList) {
-    delete displayList;
+    DisplayList::destroyDisplayListDeferred(displayList);
 }
 
 static bool android_view_GLES20Canvas_drawDisplayList(JNIEnv* env,
@@ -770,6 +770,12 @@
     LayerRenderer::updateTextureLayer(layer, width, height, isOpaque, renderTarget, transform);
 }
 
+static void android_view_GLES20Canvas_updateRenderLayer(JNIEnv* env, jobject clazz,
+        Layer* layer, OpenGLRenderer* renderer, DisplayList* displayList,
+        jint left, jint top, jint right, jint bottom) {
+    layer->updateDeferred(renderer, displayList, left, top, right, bottom);
+}
+
 static void android_view_GLES20Canvas_setTextureLayerTransform(JNIEnv* env, jobject clazz,
         Layer* layer, SkMatrix* matrix) {
 
@@ -953,13 +959,15 @@
     { "nCreateTextureLayer",     "(Z[I)I",     (void*) android_view_GLES20Canvas_createTextureLayer },
     { "nUpdateTextureLayer",     "(IIIZLandroid/graphics/SurfaceTexture;)V",
                                                (void*) android_view_GLES20Canvas_updateTextureLayer },
-    { "nSetTextureLayerTransform", "(II)V",    (void*) android_view_GLES20Canvas_setTextureLayerTransform },
+    { "nUpdateRenderLayer",      "(IIIIIII)V", (void*) android_view_GLES20Canvas_updateRenderLayer },
     { "nDestroyLayer",           "(I)V",       (void*) android_view_GLES20Canvas_destroyLayer },
     { "nDestroyLayerDeferred",   "(I)V",       (void*) android_view_GLES20Canvas_destroyLayerDeferred },
     { "nFlushLayer",             "(I)V",       (void*) android_view_GLES20Canvas_flushLayer },
     { "nDrawLayer",              "(IIFFI)V",   (void*) android_view_GLES20Canvas_drawLayer },
     { "nCopyLayer",              "(II)Z",      (void*) android_view_GLES20Canvas_copyLayer },
 
+    { "nSetTextureLayerTransform", "(II)V",    (void*) android_view_GLES20Canvas_setTextureLayerTransform },
+
     { "nGetMaximumTextureWidth",  "()I",       (void*) android_view_GLES20Canvas_getMaxTextureWidth },
     { "nGetMaximumTextureHeight", "()I",       (void*) android_view_GLES20Canvas_getMaxTextureHeight },
 
diff --git a/core/res/res/anim/screen_rotate_0_frame.xml b/core/res/res/anim/screen_rotate_0_frame.xml
new file mode 100644
index 0000000..5ea9bf8
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_0_frame.xml
@@ -0,0 +1,25 @@
+<?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">
+    <alpha android:fromAlpha="1.0" android:toAlpha="1.0"
+            android:interpolator="@interpolator/decelerate_quint"
+            android:duration="@android:integer/config_shortAnimTime" />
+</set>
diff --git a/core/res/res/anim/screen_rotate_180_enter.xml b/core/res/res/anim/screen_rotate_180_enter.xml
index 470416b..688a8d5 100644
--- a/core/res/res/anim/screen_rotate_180_enter.xml
+++ b/core/res/res/anim/screen_rotate_180_enter.xml
@@ -25,4 +25,4 @@
             android:fillEnabled="true"
             android:fillBefore="true" android:fillAfter="true"
             android:duration="@android:integer/config_mediumAnimTime" />
-</set>
\ No newline at end of file
+</set>
diff --git a/core/res/res/anim/screen_rotate_180_frame.xml b/core/res/res/anim/screen_rotate_180_frame.xml
new file mode 100644
index 0000000..19dade1
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_180_frame.xml
@@ -0,0 +1,28 @@
+<?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">
+    <rotate android:fromDegrees="180" 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_finish_enter.xml b/core/res/res/anim/screen_rotate_finish_enter.xml
index 849aa66..9d731e6 100644
--- a/core/res/res/anim/screen_rotate_finish_enter.xml
+++ b/core/res/res/anim/screen_rotate_finish_enter.xml
@@ -19,13 +19,14 @@
 
 <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"
+    <scale android:fromXScale="1.0" android:toXScale="1.1111111111111"
+            android:fromYScale="1.0" android:toYScale="1.1111111111111"
             android:pivotX="50%" android:pivotY="50%"
-            android:interpolator="@interpolator/decelerate_quint"
+            android:interpolator="@interpolator/accelerate_decelerate"
             android:fillEnabled="true"
             android:fillBefore="true" android:fillAfter="true"
-            android:duration="@android:integer/config_mediumAnimTime"/>
+            android:duration="@android:integer/config_shortAnimTime"/>
+    <!--
     <scale android:fromXScale="100%p" android:toXScale="100%"
             android:fromYScale="100%p" android:toYScale="100%"
             android:pivotX="50%" android:pivotY="50%"
@@ -33,4 +34,5 @@
             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
index 7f70dbc..60daa18 100644
--- a/core/res/res/anim/screen_rotate_finish_exit.xml
+++ b/core/res/res/anim/screen_rotate_finish_exit.xml
@@ -19,23 +19,21 @@
 
 <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"
+    <scale android:fromXScale="1.0" android:toXScale="1.0"
+            android:fromYScale="1.0" android:toYScale="1.0"
             android:pivotX="50%" android:pivotY="50%"
-            android:interpolator="@interpolator/decelerate_quint"
+            android:interpolator="@interpolator/accelerate_decelerate"
             android:fillEnabled="true"
             android:fillBefore="false" android:fillAfter="true"
-            android:duration="@android:integer/config_mediumAnimTime"/>
-    <!--
+            android:duration="@android:integer/config_shortAnimTime"/>
     <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:interpolator="@interpolator/accelerate_decelerate"
             android:duration="@android:integer/config_mediumAnimTime" />
-    -->
     <alpha android:fromAlpha="1.0" android:toAlpha="0"
-            android:interpolator="@interpolator/decelerate_quint"
+            android:interpolator="@interpolator/accelerate_decelerate"
             android:fillEnabled="true"
             android:fillBefore="true" android:fillAfter="true"
-            android:duration="@android:integer/config_mediumAnimTime" />
+            android:duration="@android:integer/config_shortAnimTime" />
 </set>
diff --git a/core/res/res/anim/screen_rotate_finish_frame.xml b/core/res/res/anim/screen_rotate_finish_frame.xml
new file mode 100644
index 0000000..06dfc5e
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_finish_frame.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.1111111111111"
+            android:fromYScale="1.0" android:toYScale="1.1111111111111"
+            android:pivotX="50%" android:pivotY="50%"
+            android:interpolator="@interpolator/accelerate_decelerate"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:duration="@android:integer/config_shortAnimTime"/>
+    <scale android:fromXScale="100%" android:toXScale="100%p"
+            android:fromYScale="100%" android:toYScale="100%p"
+            android:pivotX="50%" android:pivotY="50%"
+            android:fillEnabled="true"
+            android:fillBefore="true" android:fillAfter="true"
+            android:interpolator="@interpolator/accelerate_decelerate"
+            android:duration="@android:integer/config_shortAnimTime" />
+</set>
diff --git a/core/res/res/anim/screen_rotate_minus_90_frame.xml b/core/res/res/anim/screen_rotate_minus_90_frame.xml
new file mode 100644
index 0000000..874f2e9
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_minus_90_frame.xml
@@ -0,0 +1,28 @@
+<?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">
+    <rotate android:fromDegrees="0" android:toDegrees="90"
+            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_frame.xml b/core/res/res/anim/screen_rotate_plus_90_frame.xml
new file mode 100644
index 0000000..03c6aa6
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_plus_90_frame.xml
@@ -0,0 +1,28 @@
+<?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">
+    <rotate android:fromDegrees="0" android:toDegrees="-90"
+            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_enter.xml b/core/res/res/anim/screen_rotate_start_enter.xml
index e3f48e4..162ae8c 100644
--- a/core/res/res/anim/screen_rotate_start_enter.xml
+++ b/core/res/res/anim/screen_rotate_start_enter.xml
@@ -19,8 +19,8 @@
 
 <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"
+    <scale android:fromXScale="1.0" android:toXScale="0.9"
+            android:fromYScale="1.0" android:toYScale="0.9"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
             android:fillEnabled="true"
diff --git a/core/res/res/anim/screen_rotate_start_exit.xml b/core/res/res/anim/screen_rotate_start_exit.xml
index e3f48e4..162ae8c 100644
--- a/core/res/res/anim/screen_rotate_start_exit.xml
+++ b/core/res/res/anim/screen_rotate_start_exit.xml
@@ -19,8 +19,8 @@
 
 <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"
+    <scale android:fromXScale="1.0" android:toXScale="0.9"
+            android:fromYScale="1.0" android:toYScale="0.9"
             android:pivotX="50%" android:pivotY="50%"
             android:interpolator="@interpolator/decelerate_quint"
             android:fillEnabled="true"
diff --git a/core/res/res/anim/screen_rotate_start_frame.xml b/core/res/res/anim/screen_rotate_start_frame.xml
new file mode 100644
index 0000000..162ae8c
--- /dev/null
+++ b/core/res/res/anim/screen_rotate_start_frame.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.9"
+            android:fromYScale="1.0" android:toYScale="0.9"
+            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/layout/alert_dialog_holo.xml b/core/res/res/layout/alert_dialog_holo.xml
index 2b686bd..173efa7 100644
--- a/core/res/res/layout/alert_dialog_holo.xml
+++ b/core/res/res/layout/alert_dialog_holo.xml
@@ -108,7 +108,7 @@
             android:layoutDirection="locale"
             android:measureWithLargestChild="true">
             <Button android:id="@+id/button2"
-                android:layout_width="0dip"
+                android:layout_width="wrap_content"
                 android:layout_gravity="left"
                 android:layout_weight="1"
                 android:maxLines="2"
@@ -117,7 +117,7 @@
                 android:minHeight="@dimen/alert_dialog_button_bar_height"
                 android:layout_height="wrap_content" />
             <Button android:id="@+id/button3"
-                android:layout_width="0dip"
+                android:layout_width="wrap_content"
                 android:layout_gravity="center_horizontal"
                 android:layout_weight="1"
                 android:maxLines="2"
@@ -126,7 +126,7 @@
                 android:minHeight="@dimen/alert_dialog_button_bar_height"
                 android:layout_height="wrap_content" />
             <Button android:id="@+id/button1"
-                android:layout_width="0dip"
+                android:layout_width="wrap_content"
                 android:layout_gravity="right"
                 android:layout_weight="1"
                 android:maxLines="2"
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 9375730..f31deef 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3376,9 +3376,13 @@
     </declare-styleable>
 
     <declare-styleable name="DatePicker">
-        <!-- The first year (inclusive), for example "1940". -->
+        <!-- The first year (inclusive), for example "1940".
+             {@deprecated Use minDate instead.}
+         -->
         <attr name="startYear" format="integer" />
-        <!-- The last year (inclusive), for example "2010". -->
+        <!-- The last year (inclusive), for example "2010".
+             {@deprecated Use maxDate instead.}
+         -->
         <attr name="endYear" format="integer" />
         <!-- Whether the spinners are shown. -->
         <attr name="spinnersShown" format="boolean" />
@@ -3388,8 +3392,8 @@
         <attr name="minDate" format="string" />
         <!-- The minimal date shown by this calendar view in mm/dd/yyyy format. -->
         <attr name="maxDate" format="string" />
-        <!-- @hide The layout of the time picker. -->
-        <attr name="layout" />
+        <!-- @hide The layout of the date picker. -->
+        <attr name="internalLayout" format="reference"  />
     </declare-styleable>
 
     <declare-styleable name="TwoLineListItem">
@@ -3593,15 +3597,15 @@
         <attr name="shownWeekCount" format="integer"/>
         <!-- The background color for the selected week. -->
         <attr name="selectedWeekBackgroundColor" format="color|reference" />
-        <!-- The color for the dates of the selected month. -->
+        <!-- The color for the dates of the focused month. -->
         <attr name="focusedMonthDateColor" format="color|reference" />
         <!-- The color for the dates of an unfocused month. -->
         <attr name="unfocusedMonthDateColor" format="color|reference" />
         <!-- The color for the week numbers. -->
         <attr name="weekNumberColor" format="color|reference" />
-        <!-- The color for the sepatator line between weeks. -->
+        <!-- The color for the separator line between weeks. -->
         <attr name="weekSeparatorLineColor" format="color|reference" />
-        <!-- Drawable for the vertical bar shown at the beggining and at the end of a selected date. -->
+        <!-- Drawable for the vertical bar shown at the beginning and at the end of the selected date. -->
         <attr name="selectedDateVerticalBar" format="reference" />
         <!-- The text appearance for the week day abbreviation of the calendar header. -->
         <attr name="weekDayTextAppearance" format="reference" />
@@ -3619,20 +3623,18 @@
         <!-- @hide The height of the selection divider. -->
         <attr name="selectionDividerHeight" format="dimension" />
         <!-- @hide The min height of the NumberPicker. -->
-        <attr name="minHeight" />
+        <attr name="internalMinHeight" format="dimension" />
         <!-- @hide The max height of the NumberPicker. -->
-        <attr name="maxHeight" />
+        <attr name="internalMaxHeight" format="dimension" />
         <!-- @hide The min width of the NumberPicker. -->
-        <attr name="minWidth" />
+        <attr name="internalMinWidth" format="dimension" />
         <!-- @hide The max width of the NumberPicker. -->
-        <attr name="maxWidth" />
-        <!-- @hide The max width of the NumberPicker. -->
-        <attr name="maxWidth" />
+        <attr name="internalMaxWidth" format="dimension" />
     </declare-styleable>
 
     <declare-styleable name="TimePicker">
         <!-- @hide The layout of the time picker. -->
-        <attr name="layout" />
+        <attr name="internalLayout" />
     </declare-styleable>
 
     <!-- ========================= -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index f87e155..2d8a394 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1282,16 +1282,22 @@
   <!-- From services -->
   <java-symbol type="anim" name="screen_rotate_0_enter" />
   <java-symbol type="anim" name="screen_rotate_0_exit" />
+  <java-symbol type="anim" name="screen_rotate_0_frame" />
   <java-symbol type="anim" name="screen_rotate_180_enter" />
   <java-symbol type="anim" name="screen_rotate_180_exit" />
+  <java-symbol type="anim" name="screen_rotate_180_frame" />
   <java-symbol type="anim" name="screen_rotate_finish_enter" />
   <java-symbol type="anim" name="screen_rotate_finish_exit" />
+  <java-symbol type="anim" name="screen_rotate_finish_frame" />
   <java-symbol type="anim" name="screen_rotate_minus_90_enter" />
   <java-symbol type="anim" name="screen_rotate_minus_90_exit" />
+  <java-symbol type="anim" name="screen_rotate_minus_90_frame" />
   <java-symbol type="anim" name="screen_rotate_plus_90_enter" />
   <java-symbol type="anim" name="screen_rotate_plus_90_exit" />
+  <java-symbol type="anim" name="screen_rotate_plus_90_frame" />
   <java-symbol type="anim" name="screen_rotate_start_enter" />
   <java-symbol type="anim" name="screen_rotate_start_exit" />
+  <java-symbol type="anim" name="screen_rotate_start_frame" />
   <java-symbol type="anim" name="window_move_from_decor" />
   <java-symbol type="array" name="config_autoBrightnessButtonBacklightValues" />
   <java-symbol type="array" name="config_autoBrightnessKeyboardBacklightValues" />
@@ -1955,7 +1961,9 @@
   <public type="attr" name="flipInterval" id="0x01010179" />
   <public type="attr" name="fillViewport" id="0x0101017a" />
   <public type="attr" name="prompt" id="0x0101017b" />
+  <!-- {@deprecated Use minDate instead.} -->
   <public type="attr" name="startYear" id="0x0101017c" />
+  <!-- {@deprecated Use maxDate instead.} -->
   <public type="attr" name="endYear" id="0x0101017d" />
   <public type="attr" name="mode" id="0x0101017e" />
   <public type="attr" name="layout_x" id="0x0101017f" />
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index 610bad8..569be90 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -528,11 +528,11 @@
     </style>
 
     <style name="Widget.TimePicker">
-        <item name="android:layout">@android:layout/time_picker</item>
+        <item name="android:internalLayout">@android:layout/time_picker</item>
     </style>
 
     <style name="Widget.DatePicker">
-        <item name="android:layout">@android:layout/date_picker</item>
+        <item name="android:internalLayout">@android:layout/date_picker</item>
         <item name="android:calendarViewShown">false</item>
     </style>
 
@@ -1656,16 +1656,16 @@
         <item name="android:flingable">true</item>
         <item name="android:selectionDivider">@android:drawable/numberpicker_selection_divider</item>
         <item name="android:selectionDividerHeight">2dip</item>
-        <item name="android:minWidth">48dip</item>
-        <item name="android:maxHeight">200dip</item>
+        <item name="android:internalMinWidth">48dip</item>
+        <item name="android:internalMaxHeight">200dip</item>
     </style>
 
     <style name="Widget.Holo.TimePicker" parent="Widget.TimePicker">
-        <item name="android:layout">@android:layout/time_picker_holo</item>
+        <item name="android:internalLayout">@android:layout/time_picker_holo</item>
     </style>
 
     <style name="Widget.Holo.DatePicker" parent="Widget.DatePicker">
-        <item name="android:layout">@android:layout/date_picker_holo</item>
+        <item name="android:internalLayout">@android:layout/date_picker_holo</item>
         <item name="android:calendarViewShown">true</item>
     </style>
 
diff --git a/docs/html/guide/appendix/install-location.jd b/docs/html/guide/appendix/install-location.jd
index 292d3e7..e5ed226 100644
--- a/docs/html/guide/appendix/install-location.jd
+++ b/docs/html/guide/appendix/install-location.jd
@@ -174,7 +174,7 @@
   <dt>Copy Protection</dt>
     <dd>Your application cannot be installed to a device's SD card if it uses Android Market's 
       Copy Protection feature. However, if you use Android Market's 
-      <a href="{@docRoot}guide/publishing/licensing.html">Application Licensing</a> instead, your 
+      <a href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> instead, your 
       application <em>can</em> be installed to internal or external storage, including SD cards.</dd>
 </dl>
 
diff --git a/docs/html/guide/developing/devices/emulator.jd b/docs/html/guide/developing/devices/emulator.jd
index 02dcb68..c217790 100644
--- a/docs/html/guide/developing/devices/emulator.jd
+++ b/docs/html/guide/developing/devices/emulator.jd
@@ -78,7 +78,7 @@
 applications. You can choose what version of the Android system you want to
 run in the emulator by configuring AVDs, and you can also customize the
 mobile device skin and key mappings. When launching the emulator and at runtime,
-you can use a variety of commands and options to control the its behaviors.
+you can use a variety of commands and options to control its behavior.
 </p>
 
 <p>The Android system image distributed in the SDK contains ARM machine code for
diff --git a/docs/html/guide/developing/tools/emulator.jd b/docs/html/guide/developing/tools/emulator.jd
index 5151ec1..09e41c3 100644
--- a/docs/html/guide/developing/tools/emulator.jd
+++ b/docs/html/guide/developing/tools/emulator.jd
@@ -516,7 +516,7 @@
   </tr>
   <tr>
     <td>Audio volume up button</td>
-    <td>KEYPAD_PLUS, Ctrl-5</td>
+    <td>KEYPAD_PLUS, Ctrl-F5</td>
   </tr>
 
   <tr>
diff --git a/docs/html/guide/developing/tools/proguard.jd b/docs/html/guide/developing/tools/proguard.jd
index eca262a..ea8a1ea 100644
--- a/docs/html/guide/developing/tools/proguard.jd
+++ b/docs/html/guide/developing/tools/proguard.jd
@@ -39,7 +39,7 @@
   sized <code>.apk</code> file that is more difficult to reverse engineer. Because ProGuard makes your
   application harder to reverse engineer, it is important that you use it
   when your application utilizes features that are sensitive to security like when you are
-  <a href="{@docRoot}guide/publishing/licensing.html">Licensing Your Applications</a>.</p>
+  <a href="{@docRoot}guide/market/licensing/index.html">Licensing Your Applications</a>.</p>
 
   <p>ProGuard is integrated into the Android build system, so you do not have to invoke it
   manually. ProGuard runs only when you build your application in release mode, so you do not 
diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs
index 4a9a684..fd2ec93 100644
--- a/docs/html/guide/guide_toc.cs
+++ b/docs/html/guide/guide_toc.cs
@@ -451,8 +451,24 @@
       <li><a href="<?cs var:toroot ?>guide/publishing/publishing.html">
           <span class="en">Publishing on Android Market</span>
           </a></li>
-      <li><a href="<?cs var:toroot ?>guide/publishing/licensing.html">
+      <li class="toggle-list">
+        <div><a href="<?cs var:toroot ?>guide/market/licensing/index.html">
           <span class="en">Application Licensing</span></a>
+        </div>
+        <ul>
+          <li><a href="<?cs var:toroot?>guide/market/licensing/overview.html">
+              <span class="en">Licensing Overview</span></a>
+          </li>
+          <li><a href="<?cs var:toroot?>guide/market/licensing/setting-up.html">
+              <span class="en">Setting Up for Licensing</span></a>
+          </li>
+          <li><a href="<?cs var:toroot?>guide/market/licensing/adding-licensing.html">
+              <span class="en">Adding Licensing to Your App</span></a>
+          </li>
+          <li><a href="<?cs var:toroot?>guide/market/licensing/licensing-reference.html">
+              <span class="en">Licensing Reference</span></a>
+          </li>
+        </ul>
       </li>
       <li class="toggle-list">
         <div><a href="<?cs var:toroot?>guide/market/billing/index.html">
@@ -485,6 +501,10 @@
       <li><a href="<?cs var:toroot ?>guide/market/publishing/multiple-apks.html">
           <span class="en">Multiple APK Support</span></a>
       </li>
+      <li><a href="<?cs var:toroot ?>guide/market/expansion-files.html">
+          <span class="en">APK Expansion Files</span></a>
+          <span class="new">new!</span>
+      </li>
     </ul>
   </li>
 
diff --git a/docs/html/guide/market/expansion-files.jd b/docs/html/guide/market/expansion-files.jd
new file mode 100644
index 0000000..cd9b57a
--- /dev/null
+++ b/docs/html/guide/market/expansion-files.jd
@@ -0,0 +1,1273 @@
+page.title=APK Expansion Files
+@jd:body
+
+
+<div id="qv-wrapper">
+<div id="qv">
+<h2>Quickview</h2>
+<ul>
+  <li>Recommended for most apps that exceed the 50MB APK limit</li>
+  <li>You can provide up to 4GB of additional data for each APK</li>
+  <li>Android Market hosts and serves the expansion files at no charge</li>
+  <li>The files can be any file type you want and are saved to the device's shared storage</li>
+</ul>
+
+<h2>In this document</h2>
+<ol>
+  <li><a href="#Overview">Overview</a>
+    <ol>
+      <li><a href="#Filename">File name format</a></li>
+      <li><a href="#StorageLocation">Storage location</a></li>
+      <li><a href="#DownloadProcess">Download process</a></li>
+      <li><a href="#Checklist">Development checklist</a></li>
+    </ol>
+  </li>
+  <li><a href="#Rules">Rules and Limitations</a></li>
+  <li><a href="#Downloading">Downloading the Expansion Files</a>
+    <ol>
+      <li><a href="#AboutLibraries">About the Downloader Library</a></li>
+      <li><a href="#Preparing">Preparing to use the Downloader Library</a></li>
+      <li><a href="#Permissions">Declaring user permissions</a></li>
+      <li><a href="#DownloaderService">Implementing the downloader service</a></li>
+      <li><a href="#AlarmReceiver">Implementing the alarm receiver</a></li>
+      <li><a href="#Download">Starting the download</a></li>
+      <li><a href="#Progress">Receiving download progress</a></li>
+    </ol>
+  </li>
+  <li><a href="#ExpansionPolicy">Using APKExpansionPolicy</a></li>
+  <li><a href="#ReadingTheFile">Reading the Expansion File</a>
+    <ol>
+      <li><a href="#GettingFilenames">Getting the file names</a></li>
+      <li><a href="#ZipLib">Using the APK Expansion Zip Library</a></li>
+    </ol>
+  </li>
+  <li><a href="#Testing">Testing Your Expansion Files</a>
+    <ol>
+      <li><a href="#TestingReading">Testing file reads</a></li>
+      <li><a href="#TestingReading">Testing file downloads</a></li>
+    </ol>
+  </li>
+  <li><a href="#Updating">Updating Your Application</a></li>
+</ol>
+
+<h2>See also</h2>
+<ol>
+  <li><a href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a></li>
+  <li><a href="{@docRoot}guide/market/publishing/multiple-apks.html">Multiple
+APK Support</a></li>
+</ol>
+</div>
+</div>
+
+
+
+<p>Android Market currently requires that your APK file be no more than 50MB. For most
+applications, this is plenty of space for all the application's code and assets.
+However, some apps need more space for high-fidelity graphics, media files, or other large assets.
+Previously, if your app exceeded 50MB, you had to host and download the additional resources
+yourself when the user opens the app. Hosting and serving the extra files can be costly, and the
+user experience is often less than ideal. To make this process easier for you and more pleasant
+for users, Android Market allows you to attach two large expansion files that supplement your
+APK.</p>
+
+<p>Android Market hosts the expansion files for your application and serves them to the device at
+no cost to you. The expansion files are saved to the device's shared storage location (the
+SD card or USB-mountable partition; also known as the "external" storage) where your app can access
+them. On most devices, Android Market downloads the expansion file(s) at the same time it
+downloads the APK, so your application has everything it needs when the user opens it for the
+first time. In some cases, however, your application must download the files from Android Market
+when your application starts.</p>
+
+
+
+<h2 id="Overview">Overview</h2>
+
+<p>Each time you upload an APK using the Android Market Developer Console, you have the option to
+add one or two expansion files to the APK. Each file can be up to 2GB and it can be any format you
+choose, but we recommend you use a compressed file to conserve bandwidth during the download.
+Conceptually, each expansion file plays a different role:</p>
+
+<ul>
+  <li>The <strong>main</strong> expansion file is the
+primary expansion file for additional resources required by your application.</li>
+  <li>The <strong>patch</strong> expansion file is optional and intended for small updates to the
+main expansion file.</li>
+</ul>
+
+<p>While you can use the two expansion files any way you wish, we recommend that the main
+expansion file deliver the primary assets and should rarely if ever updated; the patch expansion
+file should be smaller and serve as a “patch carrier,” getting updated with each major
+release or as necessary.</p>
+
+<p>However, even if your application update requires only a new patch expansion file, you still must
+upload a new APK with an updated <a
+href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code
+versionCode}</a> in the manifest. (The Android Market
+Developer Console does not allow you to upload an expansion file to an existing APK.)</p>
+
+<p class="note"><strong>Note:</strong> The patch expansion file is semantically the same as the
+main expansion file&mdash;you can use each file any way you want. The system does
+not use the patch expansion file to perform patching for your app. You must perform patching
+yourself or be able to distinguish between the two files.</p>
+
+
+
+<h3 id="Filename">File name format</h3>
+
+<p>Each expansion file you upload can be any format you choose (ZIP, PDF, MP4, etc.). Regardless of
+the file type, Android Market considers them opaque binary blobs and renames the files
+using the following scheme:</p>
+
+<pre class="classic no-pretty-print">
+[main|patch].&lt;expansion-version&gt;.&lt;package-name&gt;.obb
+</pre>
+
+<p>There are three components to this scheme:</p>
+
+<dl>
+  <dt>{@code main} or {@code patch}</dt>
+    <dd>Specifies whether the file is the main or patch expansion file. There can be
+only one main file and one patch file for each APK.</dd>
+  <dt>{@code &lt;expansion-version&gt;}</dt>
+    <dd>This is an integer that matches the version code of the APK with which the expansion is
+<em>first</em> associated (it matches the application's <a
+href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code android:versionCode}</a>
+value).
+    <p>"First" is emphasized because although the Android Market Developer Console allows you to
+re-use an uploaded expansion file with a new APK, the expansion file's name does not change&mdash;it
+retains the version applied to it when you first uploaded the file.</p></dd>
+  <dt>{@code &lt;package-name&gt;}</dt> 
+    <dd>Your application's Java-style package name.</dd>
+</dl>
+
+<p>For example, suppose your APK version is 314159 and your package name is com.example.app. If you
+upload a main expansion file, the file is renamed to:</p>
+<pre class="classic no-pretty-print">main.314159.com.example.app.obb</pre>
+
+
+<h3 id="StorageLocation">Storage location</h3>
+
+<p>When Android Market downloads your expansion files to a device, it saves them to the system's
+shared storage location. To ensure proper behavior, you must not delete, move, or rename the
+expansion files. In the event that your application must perform the download from Android Market
+itself, you must save the files to the exact same location.</p>
+
+<p>The specific location for your expansion files is:</p>
+
+<pre class="classic no-pretty-print">
+&lt;shared-storage&gt;/Android/obb/&lt;package-name&gt;/
+</pre>
+
+<ul>
+  <li>{@code &lt;shared-storage&gt;} is the path to the shared storage space, available from
+{@link android.os.Environment#getExternalStorageDirectory()}.</li>
+  <li>{@code &lt;package-name&gt;} is your application's Java-style package name, available
+from {@link android.content.Context#getPackageName()}.</li>
+</ul>
+
+<p>For each application, there are never more than two expansion files in this directory.
+One is the main expansion file and the other is the patch expansion file (if necessary). Previous
+versions are overwritten when you update your application with new expansion files.</p>
+
+<p>If you must unpack the contents of your expansion files, <strong>do not</strong> delete the
+{@code .obb} expansion files afterwards and <strong>do not</strong> save the unpacked data
+in the same directory. You should save your unpacked files in the directory
+specified by {@link android.content.Context#getExternalFilesDir getExternalFilesDir()}. However,
+if possible, it's best if you use an expansion file format that allows you to read directly from
+the file instead of requiring you to unpack the data. For example, we've provided a library
+project called the <a href="#ZipLib">APK Expansion Zip Library</a> that reads your data directly
+from the ZIP file.</p>
+
+<p class="note"><strong>Note:</strong> Unlike APK files, any files saved on the shared storage can
+be read by the user and other applications.</p>
+
+<p class="note"><strong>Tip:</strong> If you're packaging media files into a ZIP, you can use media
+playback calls on the files with offset and length controls (such as {@link
+android.media.MediaPlayer#setDataSource(FileDescriptor,long,long) MediaPlayer.setDataSource()} and
+{@link android.media.SoundPool#load(FileDescriptor,long,long,int) SoundPool.load()}) without the
+need to unpack your ZIP. In order for this to work, you must not perform additional compression on
+the media files when creating the ZIP packages. For example, when using the <code>zip</code> tool,
+you should use the <code>-n</code> option to specify the file suffixes that should not be
+compressed: <br/>
+<code>zip -n .mp4;.ogg main_expansion media_files</code></p>
+
+
+<h3 id="DownloadProcess">Download process</h3>
+
+<p>Most of the time, Android Market downloads and saves your expansion files at the same time it
+downloads the APK to the device. However, in some cases Android Market
+cannot download the expansion files or the user might have deleted previously downloaded expansion
+files. To handle these situations, your app must be able to download the files
+itself when the main activity starts, using a URL provided by Android Market.</p>
+
+<p>The download process from a high level looks like this:</p>
+
+<ol>
+  <li>User selects to install your app from Android Market.</li>
+  <li>If Android Market is able to download the expansion files (which is the case for most
+devices), it downloads them along with the APK.
+     <p>If Android Market is unable to download the expansion files, it downloads the
+APK only.</p>
+  </li>
+  <li>When the user launches your application, your app must check whether the expansion files are
+already saved on the device.
+    <ol>
+      <li>If yes, your app is ready to go.</li>
+      <li>If no, your app must download the expansion files over HTTP from Android Market. Your app
+must send a request to the Android Market client using the Android Market's <a
+href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> service, which
+responds with the name, file size, and URL for each expansion file. With this information, you then
+download the files and save them to the proper <a href="#StorageLocation">storage location</a>.</li>
+    </ol>
+  </li>
+</ol>
+
+<p class="caution"><strong>Caution:</strong> It is critical that you include the necessary code to
+download the expansion files from Android Market in the event that the files are not already on the
+device when your application starts. As discussed in the following section about <a
+href="#Downloading">Downloading the Expansion Files</a>, we've made a library available to you that
+greatly simplifies this process and performs the download from a service with a minimal amount of
+code from you.</p>
+
+
+
+
+<h3 id="Checklist">Development checklist</h3>
+
+<p>Here's a summary of the tasks you should perform to use expansion files with your
+application:</p>
+
+<ol>
+  <li>First determine whether your application absolutely requires more than 50MB per installation.
+Space is precious and you should keep your total application size as small as possible. If your app
+uses more than 50MB in order to provide multiple versions of your graphic assets for multiple screen
+densities, consider instead publishing <a
+href="{@docRoot}guide/market/publishing/multiple-apks.html">multiple APKs</a> in which each APK
+contains only the assets required for the screens that it targets.</li>
+  <li>Determine which application resources to separate from your APK and package them in a
+file to use as the main expansion file.
+    <p>Normally, you should only use the second patch expansion file when performing updates to
+the main expansion file. However, if your resources exceed the 2GB limit for the main
+expansion file, you can use the patch file for the rest of your assets.</p>
+  </li>
+  <li>Develop your application such that it uses the resources from your expansion files in the
+device's <a href="#StorageLocation">shared storage location</a>.
+    <p>Remember that you must not delete, move, or rename the expansion files.</p>
+    <p>If your application doesn't demand a specific format, we suggest you create ZIP files for 
+your expansion files, then read them using the <a href="#ZipLib">APK Expansion Zip
+Library</a>.</p>
+  </li>
+  <li>Add logic to your application's main activity that checks whether the expansion files
+are on the device upon start-up. If the files are not on the device, use Android Market's <a
+href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> service to request URLs
+for the expansion files, then download and save them.
+    <p>To greatly reduce the amount of code you must write and ensure a good user experience
+during the download, we recommend you use the <a href="AboutLibraries">Downloader
+Library</a> to implement your download behavior.</p>
+    <p>If you build your own download service instead of using the library, be aware that you
+must not change the name of the expansion files and must save them to the proper
+<a href="#StorageLocation">storage location</a>.</p></li>
+</ol>
+
+<p>Once you've finished your application development, follow the guide to <a href="#Testing">Testing
+Your Expansion Files</a>.</p>
+
+
+
+
+
+
+<h2 id="Rules">Rules and Limitations</h2>
+
+<p>Adding APK expansion files is a feature available when you upload your application using the
+Android Market Developer Console. When uploading your application for the first time or updating an
+application that uses expansion files, you must be aware of the following rules and limitations:</p>
+
+<ol type="I">
+  <li>Each expansion file can be no more than 2GB.</li>
+  <li>In order to download your expansion files from Android Market, <strong>the user must have
+acquired your application from Android Market</strong>. Android Market will not
+provide the URLs for your expansion files if the application was installed by other means.</li>
+  <li>When performing the download from within your application, the URL that Android Market
+provides for each file is unique for every download and each one expires shortly after it is given
+to your application.</li>
+  <li>If you update your application with a new APK or upload <a
+href="{@docRoot}guide/market/publishing/multiple-apks.html">multiple APKs</a> for the same
+application, you can select expansion files that you've uploaded for a previous APK. <strong>The
+expansion file's name does not change</strong>&mdash;it retains the version received by the APK to
+which the file was originally associated.</li>
+  <li>If you use expansion files in combination with <a
+href="{@docRoot}guide/market/publishing/multiple-apks.html">multiple APKs</a> in order to
+provide different expansion files for different devices, you still must upload separate APKs
+for each device in order to provide a unique  <a
+href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code versionCode}</a>
+value and declare different <a href="{@docRoot}guide/appendix/market-filters.html">filters</a> for
+each APK.</li>
+  <li>You cannot issue an update to your application by changing the expansion files
+alone&mdash;<strong>you must upload a new APK</strong> to update your app. If your changes only
+concern the assets in your expansion files, you can update your APK simply by changing the <a
+href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code versionCode}</a> (and
+perhaps also the <a href="{@docRoot}guide/topics/manifest/manifest-element.html#vname">{@code
+versionName}</a>).</p></li>
+  <li><strong>Do not save other data into your <code>obb/</code>
+directory</strong>. If you must unpack some data, save it into the location specified by {@link
+android.content.Context#getExternalFilesDir getExternalFilesDir()}.</li>
+  <li><strong>Do not delete or rename the {@code .obb} expansion file</strong> (unless you're
+performing an update). Doing so will cause Android Market (or your app itself) to repeatedly
+download the expansion file.</li>
+  <li>When updating an expansion file manually, you must delete the previous expansion file.</li>
+</ol>
+
+
+
+
+
+
+
+
+
+<h2 id="Downloading">Downloading the Expansion Files</h2>
+
+<p>In most cases, Android Market downloads and saves your expansion files to the device at the same
+time it installs or updates the APK. This way, the expansion files are available when your
+application launches for the first time. However, in some cases your app must download the
+expansion files itself by requesting them from a URL provided to you in a response
+from Android Market's <a
+href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> service.</p>
+
+<p>The basic logic you need to download your expansion files is the following:</p>
+
+<ol>
+  <li>When your application starts, look for the expansion files on the <a
+href="#StorageLocation">shared storage location</a> (in the
+<code>Android/obb/&lt;package-name&gt;/</code> directory).
+    <ol type="a">
+      <li>If the expansion files are there, you're all set and your application can continue.</li>
+      <li>If the expansion files are <em>not</em> there:
+        <ol>
+          <li>Perform a request using Android Market's <a
+href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> to get your
+app's expansion file names, sizes, and URLs.</li> 
+          <li>Use the URLs provided by Android Market to download the expansion files and save
+the expansion files. You <strong>must</strong> save the files to the <a
+href="#StorageLocation">shared storage location</a>
+(<code>Android/obb/&lt;package-name&gt;/</code>) and use the exact file name provided
+by Android Market's response.
+            <p class="note"><strong>Note:</strong> The URL that Android Market provides for your
+expansion files is unique for every download and each one expires shortly after it is given to
+your application.</p>
+          </li>
+        </ol>
+      </li>
+    </ol>
+  </li>
+</ol>
+
+
+<p>If your application is free (not a paid app), then you probably haven't used the <a
+href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> service. It's primarily
+designed for you to enforce
+licensing policies for your application and ensure that the user has the right to
+use your app (he or she rightfully paid for it on Android Market). In order to facilitate the
+expansion file functionality, the licensing service has been enhanced to provide a response
+to your application that includes the URL of your application's expansion files that are hosted
+on Android Market. So, even if your application is free for users, you need to include the Android
+Market License Verification Library (LVL) to use APK expansion files. Of course, if your application
+is free, you don't need to enforce license verification&mdash;you simply need the
+library to perform the request that returns the URL of your expansion files.</p>
+
+<p class="note"><strong>Note:</strong> Whether your application is free or not, Android Market
+returns the expansion file URLs only if the user acquired your application from Android Market.</p>
+
+<p>In addition to the LVL, you need a set of code that downloads the expansion files
+over an HTTP connection and saves them to the proper location on the device's shared storage.
+As you build this procedure into your application, there are several issues you should take into
+consideration:</p>
+
+<ul>
+  <li>The device might not have enough space for the expansion files, so you should check
+before beginning the download and warn the user if there's not enough space.</li>
+  <li>File downloads should occur in a background service in order to avoid blocking the user
+interaction and allow the user to leave your app while the download completes.</li>
+  <li>A variety of errors might occur during the request and download that you must
+gracefully handle.</li>
+  <li>Network connectivity can change during the download, so you should handle such changes and
+if interrupted, resume the download when possible.</li>
+  <li>While the download occurs in the background, you should provide a notification that
+indicates the download progress, notifies the user when it's done, and takes the user back to
+your application when selected.</li>
+</ul>
+
+
+<p>To simplify this work for you, we've built the <a href="#AboutLibraries">Downloader Library</a>,
+which requests the expansion file URLs through the licensing service, downloads the expansion files,
+performs all of the tasks listed above, and even allows your activity to pause and resume the
+download. By adding the Downloader Library and a few code hooks to your application, almost all the
+work to download the expansion files is already coded for you. As such, in order to provide the best
+user experience with minimal effort on your behalf, we recommend you use the Downloader Library to
+download your expansion files. The information in the following sections explain how to integrate
+the library into your application.</p>
+
+<p>If you'd rather develop your own solution to download the expansion files using the Android
+Market URLs, you must follow the <a href="{@docRoot}guide/market/licensing/index.html">Application
+Licensing</a> documentation to perform a license request, then retrieve the expansion file names,
+sizes, and URLs from the response extras. You should use the <a href="#ExpansionPolicy">{@code
+APKExpansionPolicy}</a> class (included in the License Verification Library) as your licensing
+policy, which captures the expansion file names, sizes, and URLs from the licensing service..</p>
+
+
+
+<h3 id="AboutLibraries">About the Downloader Library</h3>
+
+<p>To use APK expansion files with your application and provide the best user experience with
+minimal effort on your behalf, we recommend you use the Downloader Library that's included in the
+Android Market APK Expansion Library package. This library downloads your expansion files in a
+background service, shows a user notification with the download status, handles network
+connectivity loss, resumes the download when possible, and more.</p>
+
+<p>To implement expansion file downloads using the Downloader Library, all you need to do is:</p>
+
+<ul>
+  <li>Extend a special {@link android.app.Service} subclass and {@link
+android.content.BroadcastReceiver} subclass that each require just a few
+lines of code from you.</li>
+  <li>Add some logic to your main activity that checks whether the expansion files have
+already been downloaded and, if not, invokes the download process and displays a
+progress UI.</li>
+  <li>Implement a callback interface with a few methods in your main activity that
+receives updates about the download progress.</li>
+</ul>
+
+<p>The following sections explain how to set up your app using the Downloader Library.</p>
+
+
+<h3 id="Preparing">Preparing to use the Downloader Library</h3>
+
+<p>To use the Downloader Library, you need to
+download two packages from the SDK Manager and add the appropriate libraries to your
+application.</p>
+
+<p>First, open the Android SDK Manager, expand <em>Extras</em> and download:</p>
+<ul>
+  <li><em>Google Market Licensing package</em></li>
+  <li><em>Google Market APK Expansion Library package</em></li>
+</ul>
+
+<p>If you're using Eclipse, create a project for each library and add it to your app:</p>
+<ol>
+  <li>Create a new Library Project for the License Verification Library and Downloader
+Library. For each library:
+    <ol>
+      <li>Begin a new Android project.</li>
+      <li>Select <strong>Create project from existing
+source</strong> and choose the library from the {@code &lt;sdk&gt;/extras/google/} directory
+({@code market_licensing/} for the License Verification Library or {@code
+market_apk_expansion/downloader_library/} for the Downloader Library).</li>
+      <li>Specify a <em>Project Name</em> such as "Android Market License Library" and "Market
+Downloader
+Library"</li>
+      <li>Click <strong>Finish</strong>.</li>
+    </ol>
+<p class="note"><strong>Note:</strong> The Downloader Library depends on the License
+Verification Library. Be sure to add the License
+Verification Library to the Downloader Library's project properties (same process as
+steps 2 and 3 below).</p>
+  </li>
+  <li>Right-click the Android project in which you want to use APK expansion files and
+select <strong>Properties</strong>.</li>
+  <li>In the <em>Library</em> panel, click <strong>Add</strong> to select and add each of the
+libraries to your application.</li>
+</ol>
+
+<p>Or, from a command line, update your project to include the libraries:</p>
+<ol>
+  <li>Change directories to the <code>&lt;sdk&gt;/tools/</code> directory.</li>
+  <li>Execute <code>android update project</code> with the {@code --library} option to add both the
+LVL and the Downloader Library to your project. For example:
+<pre class="no-pretty-print">
+android update project --path ~/Android/MyApp \
+--library ~/android_sdk/extras/google/market_licensing \
+--library ~/android_sdk/extras/google/market_apk_expansion/downloader_library
+</pre>
+  </li>
+</ol>
+
+<p>With both the License Verification Library and Downloader Library added to your
+application, you'll be able to quickly integrate the ability to download expansion files from
+Android Market. The format that you choose for the expansion files and how you read them
+from the shared storage is a separate implementation that you should consider based on your
+application needs.</p>
+
+<p class="note"><strong>Tip:</strong> The APK Expansion Library package includes a sample
+application
+that shows how to use the Downloader Library in an app. The sample uses a third library
+available in the APK Expansion Library package called the APK Expansion Zip Library. If
+you plan on
+using ZIP files for your expansion files, we suggest you also add the APK Expansion Zip Library to
+your application. For more information, see the section below
+about <a href="#ZipLib">Using the APK Expansion Zip Library</a>.</p>
+
+
+
+<h3 id="Permissions">Declaring user permissions</h3>
+
+<p>In order to download the expansion files, the Downloader Library
+requires several permissions that you must declare in your application's manifest file. They
+are:</p>
+
+<pre>
+&lt;manifest ...>
+    &lt;!-- Required to access Android Market Licensing -->
+    &lt;uses-permission android:name="com.android.vending.CHECK_LICENSE" />
+
+    &lt;!-- Required to download files from Android Market -->
+    &lt;uses-permission android:name="android.permission.INTERNET" />
+
+    &lt;!-- Required to keep CPU alive while downloading files (NOT to keep screen awake) -->
+    &lt;uses-permission android:name="android.permission.WAKE_LOCK" />
+
+    &lt;!-- Required to poll the state of the network connection and respond to changes -->
+    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
+    &lt;!-- Required to check whether Wi-Fi is enabled -->
+    &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+
+    &lt;!-- Required to read and write the expansion files on shared storage -->
+    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    ...
+&lt;/manifest>
+</pre>
+
+<p class="note"><strong>Note:</strong> By default, the Downloader Library requires API
+level 4, but the APK Expansion Zip Library requires API level 5.</p>
+
+
+<h3 id="DownloaderService">Implementing the downloader service</h3>
+
+<p>In order to perform downloads in the background, the Downloader Library provides its
+own {@link android.app.Service} subclass called {@code DownloaderService} that you should extend. In
+addition to downloading the expansion files for you, the {@code DownloaderService} also:</p>
+
+<ul>
+  <li>Registers a {@link android.content.BroadcastReceiver} that listens for changes to the
+device's network connectivity (the {@link android.net.ConnectivityManager#CONNECTIVITY_ACTION}
+broadcast) in order to pause the download when necessary (such as due to connectivity loss) and
+resume the download when possible (connectivity is acquired).</li>
+  <li>Schedules an {@link android.app.AlarmManager#RTC_WAKEUP} alarm to retry the download for
+cases in which the service gets killed.</li>
+  <li>Builds a custom {@link android.app.Notification} that displays the download progress and
+any errors or state changes.</li>
+  <li>Allows your application to manually pause and resume the download.</li>
+  <li>Verifies that the shared storage is mounted and available, that the files don't already exist,
+and that there is enough space, all before downloading the expansion files. Then notifies the user
+if any of these are not true.</li>
+</ul>
+
+<p>All you need to do is create a class in your application that extends the {@code
+DownloaderService} class and override three methods to provide specific application details:</p>
+
+<dl>
+  <dt>{@code getPublicKey()}</dt>
+    <dd>This must return a string that is the Base64-encoded RSA public key for your publisher
+account, available from the profile page on the Android Market Developer Console (see <a
+href="{@docRoot}guide/market/licensing/setting-up.html">Setting Up for Licensing</a>).</dd>
+  <dt>{@code getSALT()}</dt>
+    <dd>This must return an array of random bytes that the licensing {@code Policy} uses to
+create an <a
+href="{@docRoot}guide/market/licensing/adding-licensing.html#impl-Obfuscator">{@code
+Obfuscator}</a>. The salt ensures that your obfuscated {@link android.content.SharedPreferences}
+file in which your licensing data is saved will be unique and non-discoverable.</dd>
+  <dt>{@code getAlarmReceiverClassName()}</dt>
+    <dd>This must return the class name of the {@link android.content.BroadcastReceiver} in
+your application that should receive the alarm indicating that the download should be
+restarted (which might happen if the downloader service unexpectedly stops).</dd>
+</dl>
+
+<p>For example, here's a complete implementation of {@code DownloaderService}:</p>
+
+<pre>
+public class SampleDownloaderService extends DownloaderService {
+    // You must use the public key belonging to your publisher account
+    public static final String BASE64_PUBLIC_KEY = "YourAndroidMarketLVLKey";
+    // You should also modify this salt
+    public static final byte[] SALT = new byte[] { 1, 42, -12, -1, 54, 98,
+            -100, -12, 43, 2, -8, -4, 9, 5, -106, -107, -33, 45, -1, 84
+    };
+
+    &#64;Override
+    public String getPublicKey() {
+        return BASE64_PUBLIC_KEY;
+    }
+
+    &#64;Override
+    public byte[] getSALT() {
+        return SALT;
+    }
+
+    &#64;Override
+    public String getAlarmReceiverClassName() {
+        return SampleAlarmReceiver.class.getName();
+    }
+}
+</pre>
+
+<p class="caution"><strong>Notice:</strong> You must update the {@code BASE64_PUBLIC_KEY} value
+to be the public key belonging to your publisher account. You can find the key in the Android
+Market Developer Console under your profile information. This is necessary even when testing
+your downloads.</p>
+
+<p>Remember to declare the service in your manifest file:</p>
+<pre>
+&lt;application ...>
+    &lt;service android:name=".SampleDownloaderService" />
+    ...
+&lt;/application>
+</pre>
+
+
+
+<h3 id="AlarmReceiver">Implementing the alarm receiver</h3>
+
+<p>In order to monitor the progress of the file downloads and restart the download if necessary, the
+{@code DownloaderService} schedules an {@link android.app.AlarmManager#RTC_WAKEUP} alarm that
+delivers an {@link android.content.Intent} to a {@link android.content.BroadcastReceiver} in your
+application. You must define the {@link android.content.BroadcastReceiver} to call an API
+from the Downloader Library that checks the status of the download and restarts
+it if necessary.</p>
+
+<p>You simply need to override the {@link android.content.BroadcastReceiver#onReceive
+onReceive()} method to call {@code
+DownloaderClientMarshaller.startDownloadServiceIfRequired()}.</p>
+
+<p>For example:</p>
+
+<pre>
+public class SampleAlarmReceiver extends BroadcastReceiver {
+    &#64;Override
+    public void onReceive(Context context, Intent intent) {
+        try {
+            DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent,
+                    SampleDownloaderService.class);
+        } catch (NameNotFoundException e) {
+            e.printStackTrace();
+        }      
+    }
+}
+</pre>
+
+<p>Notice that this is the class for which you must return the name
+in your service's {@code getAlarmReceiverClassName()} method (see the previous section).</p>
+
+<p>Remember to declare the receiver in your manifest file:</p>
+<pre>
+&lt;application ...>
+    &lt;receiver android:name=".SampleAlarmReceiver" />
+    ...
+&lt;/application>
+</pre>
+
+
+
+<h3 id="Download">Starting the download</h3>
+
+<p>The main activity in your application (the one started by your launcher icon) is
+responsible for verifying whether the expansion files are already on the device and initiating
+the download if they are not.</p>
+
+<p>Starting the download using the Downloader Library requires the following
+procedures:</p>
+
+<ol>
+  <li>Check whether the files have been downloaded.
+    <p>The Downloader Library includes some APIs in the {@code Helper} class to
+help with this process:</p>
+  <ul>
+    <li>{@code getExtendedAPKFileName(Context, c, boolean mainFile, int
+versionCode)}</li>
+    <li>{@code doesFileExist(Context c, String fileName, long fileSize)}</li>
+  </ul>
+    <p>For example, the sample app provided in the APK Expansion Library package calls the
+following method in the activity's {@link android.app.Activity#onCreate onCreate()} method to check
+whether the expansion files already exist on the device:</p>
+<pre>
+boolean expansionFilesDelivered() {
+    for (XAPKFile xf : xAPKS) {
+        String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsBase, xf.mFileVersion);
+        if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false))
+            return false;
+    }
+    return true;
+}        
+</pre>
+    <p>In this case, each {@code XAPKFile} object holds the version number and file size of a known
+expansion file and a boolean as to whether it's the main expansion file. (See the sample
+application's {@code SampleDownloaderActivity} class for details.)</p>
+    <p>If this method returns false, then the application must begin the download.</p>
+  </li>
+  <li>Start the download by calling the static method {@code
+DownloaderClientMarshaller.startDownloadServiceIfRequired(Context c, PendingIntent
+notificationClient, Class&lt;?> serviceClass)}.
+    <p>The method takes the following parameters:</p>
+    <ul>
+      <li><code>context</code>: Your application's {@link android.content.Context}.</li>
+      <li><code>notificationClient</code>: A {@link android.app.PendingIntent} to start your main
+activity. This is used in the {@link android.app.Notification} that the {@code DownloaderService}
+creates to show the download progress. When the user selects the notification, the system
+invokes the {@link android.app.PendingIntent} you supply here and should open the activity
+that shows the download progress (usually the same activity that started the download).</li>
+      <li><code>serviceClass</code>: The {@link java.lang.Class} object for your implementation of
+{@code DownloaderService}, required to start the service and begin the download if necessary.</li>
+    </ul>
+    <p>The method returns an integer that indicates
+whether or not the download is required. Possible values are:</p>
+    <ul>
+      <li>{@code NO_DOWNLOAD_REQUIRED}: Returned if the files already
+exist or a download is already in progress.</li>
+      <li>{@code LVL_CHECK_REQUIRED}: Returned if a license verification is
+required in order to acquire the expansion file URLs.</li>
+      <li>{@code DOWNLOAD_REQUIRED}: Returned if the expansion file URLs are already known,
+but have not been downloaded.</li>
+    </ul>
+    <p>The behavior for {@code LVL_CHECK_REQUIRED} and {@code DOWNLOAD_REQUIRED} are essentially the
+same and you normally don't need to be concerned about them. In your main activity that calls {@code
+startDownloadServiceIfRequired()}, you can simply check whether or not the response is {@code
+NO_DOWNLOAD_REQUIRED}. If the response is anything <em>other than</em> {@code NO_DOWNLOAD_REQUIRED},
+the Downloader Library begins the download and you should update your activity UI to
+display the download progress (see the next step). If the response <em>is</em> {@code
+NO_DOWNLOAD_REQUIRED}, then the files are available and your application can start.</p>
+    <p>For example:</p>
+<pre>
+&#64;Override
+public void onCreate(Bundle savedInstanceState) {
+    // Check if expansion files are available before going any further
+    if (!expansionFilesDelivered()) {
+        // Build an Intent to start this activity from the Notification
+        Intent notifierIntent = new Intent(this, MainActivity.getClass());
+        notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+                                Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        ...
+        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
+                notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+        
+        // Start the download service (if required)
+        int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
+                        pendingIntent, SampleDownloaderService.class);
+        // If download has started, initialize this activity to show download progress
+        if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
+            // This is where you do set up to display the download progress (next step)
+            ...
+            return;
+        } // If the download wasn't necessary, fall through to start the app
+    }
+    startApp(); // Expansion files are available, start the app
+}
+</pre>
+  </li>
+  <li>When the {@code startDownloadServiceIfRequired()} method returns anything <em>other
+than</em> {@code NO_DOWNLOAD_REQUIRED}, create an instance of {@code IStub} by
+calling {@code DownloaderClientMarshaller.CreateStub(IDownloaderClient client, Class&lt;?>
+downloaderService)}. The {@code IStub} provides a binding between your activity to the downloader
+service such that your activity receives callbacks about the download progress.
+    <p>In order to instantiate your {@code IStub} by calling {@code CreateStub()}, you must pass it
+an implementation of the {@code IDownloaderClient} interface and your {@code DownloaderService}
+implementation. The next section about <a href="#Progress">Receiving download progress</a> discusses
+the {@code IDownloaderClient} interface, which you should usually implement in your {@link
+android.app.Activity} class so you can update the activity UI when the download state changes.</p>
+    <p>We recommend that you call {@code
+CreateStub()} to instantiate your {@code IStub} during your activity's {@link
+android.app.Activity#onCreate onCreate()} method, after {@code startDownloadServiceIfRequired()}
+starts the download. </p>
+    <p>For example, in the previous code sample for {@link android.app.Activity#onCreate
+onCreate()}, you can respond to the {@code startDownloadServiceIfRequired()} result like this:</p>
+<pre>
+        // Start the download service (if required)
+        int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
+                        pendingIntent, SampleDownloaderService.class);
+        // If download has started, initialize activity to show progress
+        if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
+            // Instantiate a member instance of IStub
+            mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,
+                    SampleDownloaderService.class);
+            // Inflate layout that shows download progress
+            setContentView(R.layout.downloader_ui);
+            return;
+        }
+</pre>
+
+    <p>After the {@link android.app.Activity#onCreate onCreate()} method returns, your activity
+receives a call to {@link android.app.Activity#onResume onResume()}, which is where you should then
+call {@code connect()} on the {@code IStub}, passing it your application's {@link
+android.content.Context}. Conversely, you should call
+{@code disconnect()} in your activity's {@link android.app.Activity#onStop onStop()} callback.</p>
+<pre>
+&#64;Override
+protected void onResume() {
+    if (null != mDownloaderClientStub) {
+        mDownloaderClientStub.connect(this);
+    }
+    super.onResume();
+}
+
+&#64;Override
+protected void onStop() {
+    if (null != mDownloaderClientStub) {
+        mDownloaderClientStub.disconnect(this);
+    }
+    super.onStop();
+}
+</pre>
+    <p>Calling {@code connect()} on the {@code IStub} binds your activity to the {@code
+DownloaderService} such that your activity receives callbacks regarding changes to the download
+state through the {@code IDownloaderClient} interface.</p>
+  </li>
+</ol>
+
+
+
+<h3 id="Progress">Receiving download progress</h3>
+
+<p>To receive updates regarding the download progress and to interact with the {@code
+DownloaderService}, you must implement the Downloader Library's {@code IDownloaderClient} interface.
+Usually, the activity you use to start the download should implement this interface in order to
+display the download progress and send requests to the service.</p>
+
+<p>The required interface methods for {@code IDownloaderClient} are:</p>
+
+<dl>
+  <dt>{@code onServiceConnected(Messenger m)}</dt>
+    <dd>After you instantiate the {@code IStub} in your activity, you'll receive a call to this
+method, which passes a {@link android.os.Messenger} object that's connected with your instance
+of {@code DownloaderService}. To send requests to the service, such as to pause and resume
+downloads, you must call {@code DownloaderServiceMarshaller.CreateProxy()} to receive the {@code
+IDownloaderService} interface connected to the service.
+    <p>A recommended implementation looks like this:</p>
+<pre>
+private IDownloaderService mRemoteService;
+...
+
+&#64;Override
+public void onServiceConnected(Messenger m) {
+    mRemoteService = DownloaderServiceMarshaller.CreateProxy(m);
+    mRemoteService.onClientUpdated(mDownloaderClientStub.getMessenger());
+}
+</pre>
+    <p>With the {@code IDownloaderService} object initialized, you can send commands to the
+downloader service, such as to pause and resume the download ({@code requestPauseDownload()}
+and {@code requestContinueDownload()}).</p>
+</dd>
+  <dt>{@code onDownloadStateChanged(int newState)}</dt>
+    <dd>The download service calls this when a change in download state occurs, such as the
+download begins or completes.
+      <p>The <code>newState</code> value will be one of several possible values specified in
+by one of the {@code IDownloaderClient} class's {@code STATE_*} constants.</p>
+      <p>To provide a useful message to your users, you can request a corresponding string
+for each state by calling {@code Helpers.getDownloaderStringResourceIDFromState()}. This
+returns the resource ID for one of the strings bundled with the Downloader
+Library. For example, the string "Download paused because you are roaming" corresponds to {@code
+STATE_PAUSED_ROAMING}.</p></dd>
+  <dt>{@code onDownloadProgress(DownloadProgressInfo progress)}</dt>
+    <dd>The download service calls this to deliver a {@code DownloadProgressInfo} object,
+which describes various information about the download progress, including estimated time remaining,
+current speed, overall progress, and total so you can update the download progress UI.</dd>
+</dl>
+<p class="note"><strong>Tip:</strong> For examples of these callbacks that update the download
+progress UI, see the {@code SampleDownloaderActivity} in the sample app provided with the
+APK Expansion Library package.</p>
+
+<p>Some public methods for the {@code IDownloaderService} interface you might find useful are:</p>
+
+<dl>
+  <dt>{@code requestPauseDownload()}</dt>
+    <dd>Pauses the download.</dd>
+  <dt>{@code requestContinueDownload()}</dt>
+    <dd>Resumes a paused download.</dd>
+  <dt>{@code setDownloadFlags(int flags)}</dt>
+    <dd>Sets user preferences for network types on which its OK to download the files. The
+current implementation supports one flag, {@code FLAGS_DOWNLOAD_OVER_CELLULAR}, but you can add
+others. By default, this flag is <em>not</em> enabled, so the user must be on Wi-Fi to download
+expansion files. You might want to provide a user preference to enable downloads over
+the cellular network. In which case, you can call:
+<pre>
+mRemoteService.setDownloadFlags(IDownloaderService.FLAGS_DOWNLOAD_OVER_CELLULAR);
+</pre>
+</dd>
+</dl>
+
+
+
+
+<h2 id="ExpansionPolicy">Using APKExpansionPolicy</h2>
+
+<p>If you decide to build your own downloader service instead of using the Android Market
+<a href="#AboutLibraries">Downloader Library</a>, you should still use the {@code
+APKExpansionPolicy} that's provided in the License Verification Library. The {@code
+APKExpansionPolicy} class is nearly identical to {@code ServerManagedPolicy} (available in the
+Android Market License Verification Library) but includes additional handling for the APK expansion
+file response extras.</p>
+
+<p class="note"><strong>Note:</strong> If you <em>do use</em> the <a
+href="#AboutLibraries">Downloader Library</a> as discussed in the previous section, the
+library performs all interaction with the {@code APKExpansionPolicy} so you don't have to use
+this class directly.</p>
+
+<p>The class includes methods to help you get the necessary information about the available
+expansion files:</p>
+
+<ul>
+  <li>{@code getExpansionURLCount()}</li>
+  <li>{@code getExpansionURL(int index)}</li>
+  <li>{@code getExpansionFileName(int index)}</li>
+  <li>{@code getExpansionFileSize(int index)}</li>
+</ul>
+
+<p>For more information about how to use the {@code APKExpansionPolicy} when you're <em>not</em>
+using the <a
+href="#AboutLibraries">Downloader Library</a>, see the documentation for <a
+href="{@docRoot}guide/market/licensing/adding-licensing.html">Adding Licensing to Your App</a>,
+which explains how to implement a license policy such as this one.</p>
+
+
+
+
+
+
+
+<h2 id="ReadingTheFile">Reading the Expansion File</h2>
+
+<p>Once your APK expansion files are saved on the device, how you read your files
+depends on the type of file you've used. As discussed in the <a href="#Overview">overview</a>, your
+expansion files can be any kind of file you
+want, but are renamed using a particular <a href="#Filename">file name format</a> and are saved to
+{@code &lt;shared-storage&gt;/Android/obb/&lt;package-name&gt;/}.</p>
+
+<p>Regardless of how you read your files, you should always first check that the external
+storage is available for reading. There's a chance that the user has the storage mounted to a
+computer over USB or has actually removed the SD card.</p>
+
+<p class="note"><strong>Note:</strong> When your application starts, you should always check whether
+the external storage space is available and readable by calling {@link
+android.os.Environment#getExternalStorageState()}. This returns one of several possible strings
+that represent the state of the external storage. In order for it to be readable by your
+application, the return value must be {@link android.os.Environment#MEDIA_MOUNTED}.</p>
+
+
+<h3 id="GettingFilenames">Getting the file names</h3>
+
+<p>As described in the <a href="#Overview">overview</a>, your APK expansion files are saved
+using a specific file name format:</p>
+
+<pre class="classic no-pretty-print">
+[main|patch].&lt;expansion-version&gt;.&lt;package-name&gt;.obb
+</pre>
+
+<p>To get the location and names of your expansion files, you should use the
+{@link android.os.Environment#getExternalStorageDirectory()} and {@link
+android.content.Context#getPackageName()} methods to construct the path to your files.</p>
+
+<p>Here's a method you can use in your application to get an array containing the complete path
+to both your expansion files:</p>
+
+<pre>
+// The shared path to all app expansion files
+private final static String EXP_PATH = "/Android/obb/";
+
+static String[] getAPKExpansionFiles(Context ctx, int mainVersion, int patchVersion) {
+    String packageName = ctx.getPackageName();
+    Vector&lt;String> ret = new Vector&lt;String>();
+    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+        // Build the full path to the app's expansion files
+        File root = Environment.getExternalStorageDirectory();
+        File expPath = new File(root.toString() + EXP_PATH + packageName);
+
+        // Check that expansion file path exists
+        if (expPath.exists()) {
+            if ( mainVersion > 0 ) {
+                String strMainPath = expPath + File.separator + "main." +
+                        mainVersion + "." + packageName + ".obb";
+                File main = new File(strMainPath);
+                if ( main.isFile() ) {
+                        ret.add(strMainPath);
+                }
+            }
+            if ( patchVersion > 0 ) {
+                String strPatchPath = expPath + File.separator + "patch." +
+                        mainVersion + "." + packageName + ".obb";
+                File main = new File(strPatchPath);
+                if ( main.isFile() ) {
+                        ret.add(strPatchPath);
+                }
+            }
+        }
+    }
+    String[] retArray = new String[ret.size()];
+    ret.toArray(retArray);
+    return retArray;
+}
+</pre>
+
+<p>You can call this method by passing it your application {@link android.content.Context}
+and the desired expansion file's version.</p>
+
+<p>There are many ways you could determine the expansion file version number. One simple way is to
+save the version in a {@link android.content.SharedPreferences} file when the download begins, by
+querying the expansion file name with the {@code APKExpansionPolicy} class's {@code
+getExpansionFileName(int index)} method. You can then get the version code by reading the {@link
+android.content.SharedPreferences} file when you want to access the expansion
+file.</p>
+
+<p>For more information about reading from the shared storage, see the <a
+href="{@docRoot}guide/topics/data/data-storage.html#filesExternal">Data Storage</a>
+documentation.</p>
+
+
+
+<h3 id="ZipLib">Using the APK Expansion Zip Library</h3>
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+  <h3>Reading media files from a ZIP</h3>
+  <p>If you're using your expansion files to store media files, a ZIP file still allows you to
+use Android media playback calls that provide offset and length controls (such as {@link
+android.media.MediaPlayer#setDataSource(FileDescriptor,long,long) MediaPlayer.setDataSource()} and
+{@link android.media.SoundPool#load(FileDescriptor,long,long,int) SoundPool.load()}). In order for
+this to work, you must not perform additional compression on the media files when creating the ZIP
+packages. For example, when using the <code>zip</code> tool, you should use the <code>-n</code>
+option to specify the file suffixes that should not be compressed:</p>
+<p><code>zip -n .mp4;.ogg main_expansion media_files</code></p>
+</div>
+</div>
+
+<p>The Android Market APK Expansion Library package includes a library called the APK
+Expansion Zip Library (located in {@code
+&lt;sdk>/extras/google/google_market_apk_expansion/zip_file/}). This is an optional library that
+helps you read your expansion
+files when they're saved as ZIP files. Using this library allows you to easily read resources from
+your ZIP expansion files as a virtual file system.</p>
+
+<p>The APK Expansion Zip Library includes the following classes and APIs:</p>
+
+<dl>
+  <dt>{@code APKExpansionSupport}</dt>
+    <dd>Provides some methods to access expansion file names and ZIP files:
+      
+      <dl style="margin-top:1em">
+        <dt>{@code getAPKExpansionFiles()}</dt> 
+          <dd>The same method shown above that returns the complete file path to both expansion
+files.</dd>
+        <dt>{@code getAPKExpansionZipFile(Context ctx, int mainVersion, int
+patchVersion)}</dt>
+          <dd>Returns a {@code ZipResourceFile} representing the sum of both the main file and
+patch file. That is, if you specify both the <code>mainVersion</code> and the
+<code>patchVersion</code>, this returns a {@code ZipResourceFile} that provides read access to
+all the data, with the patch file's data merged on top of the main file.</dd>
+      </dl>
+    </dd>
+    
+  <dt>{@code ZipResourceFile}</dt>
+    <dd>Represents a ZIP file on the shared storage and performs all the work to provide a virtual
+file system based on your ZIP files. You can get an instance using {@code
+APKExpansionSupport.getAPKExpansionZipFile()} or with the {@code ZipResourceFile} by passing it the
+path to your expansion file. This class includes a variety of useful methods, but you generally
+don't need to access most of them. A couple of important methods are:
+
+      <dl style="margin-top:1em">
+        <dt>{@code getInputStream(String assetPath)}</dt>
+          <dd>Provides an {@link java.io.InputStream} to read a file within the ZIP file. The
+<code>assetPath</code> must be the path to the desired file, relative to
+the root of the ZIP file contents.</dd>
+        <dt>{@code getAssetFileDescriptor(String assetPath)}</dt>
+          <dd>Provides an {@link android.content.res.AssetFileDescriptor} for a file within the
+ZIP file. The <code>assetPath</code> must be the path to the desired file, relative to
+the root of the ZIP file contents. This is useful for certain Android APIs that require  an {@link
+android.content.res.AssetFileDescriptor}, such as some {@link android.media.MediaPlayer} APIs.</dd>
+      </dl>
+    </dd>
+    
+  <dt>{@code APEZProvider}</dt>
+    <dd>Most applications don't need to use this class. This class defines a {@link
+android.content.ContentProvider} that marshals the data from the ZIP files through a content
+provider {@link android.net.Uri} in order to provide file access for certain Android APIs that
+expect {@link android.net.Uri} access to media files.
+      <p>The sample application available in the
+APK Expansion Library package demonstrates a scenario in which this class is useful
+to specify a video with {@link android.widget.VideoView#setVideoURI
+VideoView.setVideoURI()}. See the sample app's class {@code SampleZipfileProvider} for an
+example of how to extend this class to use in your application.</p></dd>
+</dl>
+
+<h4>Reading from a ZIP file</h4>
+
+<p>When using the APK Expansion Zip Library, reading a file from your ZIP usually requires the
+following:</p>
+
+<pre>
+// Get a ZipResourceFile representing a merger of both the main and patch files
+ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(appContext,
+        mainVersion, patchVersion);
+        
+// Get an input stream for a known file inside the expansion file ZIPs
+InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);
+</pre>
+
+<p>The above code provides access to any file that exists in either your main expansion file or
+patch expansion file, by reading from a merged map of all the files from both files. All you
+need to provide the {@code getAPKExpansionFile()} method is your application {@code
+android.content.Context} and the version number for both the main expansion file and patch
+expansion file.</p>
+
+<p>If you'd rather read from a specific expansion file, you can use the {@code
+ZipResourceFile} constructor with the path to the desired expansion file:</p>
+
+<pre>
+// Get a ZipResourceFile representing a specific expansion file
+ZipResourceFile expansionFile = new ZipResourceFile(filePathToMyZip);
+
+// Get an input stream for a known file inside the expansion file ZIPs
+InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);
+</pre>
+
+<p>For more information about using this library for your expansion files, look at
+the sample application's {@code SampleDownloaderActivity} class, which includes additional code to
+verify the downloaded files using CRC. Beware that if you use this sample as the basis for
+your own implementation, it requires that you <strong>declare the byte size of your expansion
+files</strong> in the {@code xAPKS} array.</p>
+
+
+
+
+<h2 id="Testing">Testing Your Expansion Files</h2>
+
+<p>Before publishing your application, there are two things you should test: Reading the
+expansion files and downloading the files.</p>
+
+
+<h3 id="TestingReading">Testing file reads</h3>
+
+<p>Before you upload your application to Android Market, you
+should test your application's ability to read the files from the shared storage. All you need to do
+is add the files to the appropriate location on the device shared storage and launch your
+application:</p>
+
+<ol>
+  <li>On your device, create the appropriate directory on the shared storage where Android
+Market will save your files.
+  <p>For example, if your package name is {@code com.example.android}, you need to create
+the directory {@code Android/obb/com.example.android/} on the shared storage space. (Plug in
+your test device to your computer to mount the shared storage and manually create this
+directory.)</p>
+  </li>
+  <li>Manually add the expansion files to that directory. Be sure that you rename your files to
+match the <a href="#Filename">file name format</a> that Android Market will use.
+  <p>For example, regardless of the file type, the main expansion file for the {@code
+com.example.android} application should be {@code main.0300110.com.example.android.obb}.
+The version code can be whatever value you want. Just remember:</p>
+  <ul>
+    <li>The main expansion file always starts with {@code main} and the patch file starts with
+{@code patch}.</li>
+    <li>The package name always matches that of the APK to which the file is attached on
+Android Market.
+  </ul>
+  </li>
+  <li>Now that the expansion file(s) are on the device, you can install and run your application to
+test your expansion file(s).</li>
+</ol>
+
+<p>Here are some reminders about handling the expansion files:</p>
+<ul>
+  <li><strong>Do not delete or rename</strong> the {@code .obb} expansion files (even if you unpack
+the data to a different location). Doing so will cause Android Market (or your app itself) to
+repeatedly download the expansion file.</li>
+  <li><strong>Do not save other data into your <code>obb/</code>
+directory</strong>. If you must unpack some data, save it into the location specified by {@link
+android.content.Context#getExternalFilesDir getExternalFilesDir()}.</li>
+</ul>
+
+
+
+<h3 id="TestingReading">Testing file downloads</h3>
+
+<p>Because your application must sometimes manually download the expansion files when it first
+opens, it's important that you test this process to be sure your application can successfully query
+for the URLs, download the files, and save them to the device.</p>
+
+<p>To test your application's implementation of the manual download procedure, you must upload
+your application to Android Market as a "draft" to make your expansion files available for
+download:</p>
+
+<ol>
+  <li>Upload your APK and corresponding expansion files using the Android Market Developer
+Console.</li>
+  <li>Fill in the necessary application details (title, screenshots, etc.). You can come back and
+finalize these details before publishing your application.
+  <p>Click the <strong>Save</strong> button. <em>Do not click Publish.</em> This saves
+the application as a draft, such that your application is not published for Android Market users,
+but the expansion files are available for you to test the download process.</p></li>
+  <li>Install the application on your test device using the Eclipse tools or <a
+href="{@docRoot}guide/developing/tools/adb.html">{@code adb}</a>.</li>
+  <li>Launch the app.</li>
+</ol>
+
+<p>If everything works as expected, your application should begin downloading the expansion
+files as soon as the main activity starts.</p>
+
+
+
+
+<h2 id="Updating">Updating Your Application</h2>
+
+<p>One of the great benefits to using expansion files on Android Market is the ability to
+update your application without re-downloading all of the original assets. Because Android Market
+allows you to provide two expansion files with each APK, you can use the second file as a "patch"
+that provides updates and new assets. Doing so avoids the
+need to re-download the main expansion file which could be large and expensive for users.</p>
+
+<p>The patch expansion file is technically the same as the main expansion file and neither
+the Android system nor Android Market perform actual patching between your main and patch expansion
+files. Your application code must perform any necessary patches itself.</p>
+
+<p>If you use ZIP files as your expansion files, the <a href="#ZipLib">APK Expansion Zip
+Library</a> that's included with the APK Expansion Library package includes the ability to merge
+your
+patch file with the main expansion file.</p>
+
+<p class="note"><strong>Note:</strong> Even if you only need to make changes to the patch
+expansion file, you must still update the APK in order for Android Market to perform an update.
+If you don't require code changes in the application, you should simply update the <a
+href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code versionCode}</a> in the
+manifest.</p>
+
+<p>As long as you don't change the main expansion file that's associated with the APK
+in the Android Market Developer Console, users who previously installed your application will not
+download the main expansion file. Existing users receive only the updated APK and the new patch
+expansion file (retaining the previous main expansion file).</p>
+
+<p>Here are a few issues to keep in mind regarding updates to expansion files:</p>
+
+<ul>
+  <li>There can be only two expansion files for your application at a time. One main expansion
+file and one patch expansion file. During an update to a file, Android Market deletes the
+previous version (and so must your application when performing manual updates).</li>
+  <li>When adding a patch expansion file, the Android system does not actually patch your
+application or main expansion file. You must design your application to support the patch data.
+However, the APK Expansion Library package includes a library for using ZIP files
+as expansion files, which merges the data from the patch file into the main expansion file so
+you can easily read all the expansion file data.</li>
+</ul>
+
+
+
+<!-- Tools are not ready.
+     
+<h3>Using OBB tool and APIs</h3>
+
+<pre>
+$ mkobb.sh -d /data/myfiles -k my_secret_key -o /data/data.obb
+$ obbtool a -n com.example.myapp -v 1 -s seed_from_mkobb /data/data.obb
+</pre>
+
+<pre>
+storage = (StorageManager) getSystemService( STORAGE_SERVICE );
+storage.mountObb( obbFilepath, "my_secret_key", myListener );
+obbContentPath = storage.getMountedObbPath( obbFilepath );
+</pre>
+-->
diff --git a/docs/html/guide/market/licensing/adding-licensing.jd b/docs/html/guide/market/licensing/adding-licensing.jd
new file mode 100644
index 0000000..d1fe839
--- /dev/null
+++ b/docs/html/guide/market/licensing/adding-licensing.jd
@@ -0,0 +1,1072 @@
+page.title=Adding Licensing to Your App
+parent.title=Application Licensing
+parent.link=index.html
+@jd:body
+
+
+
+<div id="qv-wrapper">
+<div id="qv">
+  
+  <h2>In this document</h2>
+  <ol>
+  <li><a href="#manifest-permission">Adding the Licensing Permission</a></li>
+  <li><a href="#impl-Policy">Implementing a Policy</a>
+    <ol>
+      <li><a href="#custom-policies">Guidelines for custom policies</a></li>
+      <li><a href="#ServerManagedPolicy">ServerManagedPolicy</a></li>
+      <li><a href="#StrictPolicy">StrictPolicy</a></li>
+    </ol>
+  </li>
+  <li><a href="#impl-Obfuscator">Implementing an Obfuscator</a>
+    <ol>
+      <li><a href="#AESObfuscator">AESObfuscator</a></li>
+    </ol>
+  </li>
+  <li><a href="#impl-lc">Checking the License from an Activity</a>
+    <ol>
+      <li><a href="#lc-overview">Overview of license check and response</a></li>
+      <li><a href="#imports">Add imports</a></li>
+      <li><a href="#lc-impl">Implement LicenseCheckerCallback as a private inner class</a></li>
+      <li><a href="#thread-handler">Create a Handler for posting from LicenseCheckerCallback
+to the UI thread</a></li>
+      <li><a href="#lc-lcc">Instantiate LicenseChecker and LicenseCheckerCallback</a></li>
+      <li><a href="#check-access">Call checkAccess() to initiate the license check</a></li>
+      <li><a href="#account-key">Embed your public key for licensing</a></li>
+      <li><a href="#handler-cleanup">Call your LicenseChecker's onDestroy() method
+to close IPC connections</a></li>
+    </ol>
+  </li>
+  <li><a href="#impl-DeviceLimiter">Implementing a DeviceLimiter</a></li>
+  <li><a href="#app-obfuscation">Obfuscating Your Code</a></li>
+  <li><a href="#app-publishing">Publishing a Licensed Application</a>
+    <ol>
+      <li><a href="#">Removing Copy Protection</a></li>
+    </ol>
+  </li>
+  <li><a href="#support">Where to Get Support</a></li>
+</ol>
+  
+</div>
+</div>
+
+
+
+<p>After you've set up a publisher account and development environment (see <a
+href="setting-up.html">Setting Up for Licensing</a>), you are ready to add license verification to
+your app with the License Verification Library (LVL).</p>
+
+<p>Adding license verification with the LVL involves these tasks:</p>
+
+<ol>
+<li><a href="#manifest-permission">Adding the licensing permission</a> your application's manifest.</li>
+<li><a href="#impl-Policy">Implementing a Policy</a> &mdash; you can choose one of the full implementations provided in the LVL or create your own.</li>
+<li><a href="#impl-Obfuscator">Implementing an Obfuscator</a>, if your {@code Policy} will cache any
+license response data. </li>
+<li><a href="#impl-lc">Adding code to check the license</a> in your application's main
+Activity.</li>
+<li><a href="#impl-DeviceLimiter">Implementing a DeviceLimiter</a> (optional and not recommended for
+most applications).</li>
+</ol>
+
+<p>The sections below describe these tasks. When you are done with the
+integration, you should be able to compile your application successfully and you
+can begin testing, as described in <a
+href="{@docRoot}guide/market/licensing/setting-up.html#test-env">Setting Up the Test
+Environment</a>.</p>
+
+<p>For an overview of the full set of source files included in the LVL, see <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#lvl-summary">Summary of LVL Classes
+and Interfaces</a>.</p>
+
+
+<h2 id="manifest-permission">Adding the Licensing Permission</h2>
+
+<p>To use the Android Market application for sending a license check to the
+server, your application must request the proper permission,
+<code>com.android.vending.CHECK_LICENSE</code>. If your application does
+not declare the licensing permission but attempts to initiate a license check,
+the LVL throws a security exception.</p>
+
+<p>To request the licensing permission in your application, declare a <a
+href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><code>&lt;uses-permission&gt;</code></a>
+element as a child of <code>&lt;manifest&gt;</code>, as follows: </p>
+
+<p style="margin-left:2em;"><code>&lt;uses-permission
+android:name="com.android.vending.CHECK_LICENSE"&gt;</code></p>
+
+<p>For example, here's how the LVL sample application declares the permission:
+</p>
+
+<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
+
+&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" ..."&gt;
+    &lt;!-- Devices &gt;= 3 have version of Android Market that supports licensing. --&gt;
+    &lt;uses-sdk android:minSdkVersion="3" /&gt;
+    &lt;!-- Required permission to check licensing. --&gt;
+    &lt;uses-permission android:name="com.android.vending.CHECK_LICENSE" /&gt;
+    ...
+&lt;/manifest&gt;
+</pre>
+
+<p class="note"><strong>Note:</strong> Currently, you cannot declare the
+<code>CHECK_LICENSE</code> permission in the LVL library project's manifest,
+because the SDK Tools will not merge it into the manifests of dependent
+applications. Instead, you must declare the permission in each dependent
+application's manifest. </p>
+
+
+<h2 id="impl-Policy">Implementing a Policy</h2>
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>ServerManagedPolicy</h2>
+
+<p>The LVL includes a complete {@code Policy} implementation called ServerManagedPolicy
+that makes use of license-management settings provided by the Android Market
+server. </p>
+
+<p style="margin-top:.5em;">Use of ServerManagedPolicy as the basis for your
+Policy is strongly recommended. For more information, see <a
+href="#ServerManagedPolicy">ServerManagedPolicy</a> section, below.</p>
+
+</div>
+</div>
+
+<p>Android Market licensing service does not itself determine whether a
+given user with a given license should be granted access to your application.
+Rather, that responsibility is left to a {@code Policy} implementation that you provide
+in your application.</p>
+
+<p>Policy is an interface declared by the LVL that is designed to hold your
+application's logic for allowing or disallowing user access, based on the result
+of a license check. To use the LVL, your application <em>must</em> provide an
+implementation of {@code Policy}. </p>
+
+<p>The {@code Policy} interface declares two methods, <code>allowAccess()</code> and
+<code>processServerResponse()</code>, which are called by a {@code LicenseChecker}
+instance when processing a response from the license server. It also declares an
+enum called <code>LicenseResponse</code>, which specifies the license response
+value passed in calls to <code>processServerResponse()</code>. </p>
+
+<ul>
+<li><code>processServerResponse()</code> lets you preprocess the raw response
+data received from the licensing server, prior to determining whether to grant
+access.
+
+<p>A typical implementation would extract some or all fields from the license
+response and store the data locally to a persistent store, such as through
+{@link android.content.SharedPreferences} storage, to ensure that the data is
+accessible across application invocations and device power cycles. For example,
+a {@code Policy} would maintain the timestamp of the last successful license check, the
+retry count, the license validity period, and similar information in a
+persistent store, rather than resetting the values each time the application is
+launched.</p>
+
+<p>When storing response data locally, the {@code Policy} must ensure that the data is
+obfuscated (see <a href="#impl-Obfuscator">Implementing an Obfuscator</a>,
+below).</p></li>
+
+<li><code>allowAccess()</code> determines whether to grant the user access to
+your application, based on any available license response data (from the
+licensing server or from cache) or other application-specific information.  For
+example, your implementation of <code>allowAccess()</code> could take into
+account additional criteria, such as usage or other data retrieved from a
+backend server. In all cases, an implementation of <code>allowAccess()</code>
+should only return <code>true</code> if the user is licensed to use the
+application, as determined by the licensing server, or if there is a transient
+network or system problem that prevents the license check from completing. In
+such cases, your implementation can maintain a count of retry responses and
+provisionally allow access until the next license check is complete.</li>
+
+</ul>
+
+<p>To simplify the process of adding licensing to your application and to
+provide an illustration of how a {@code Policy} should be designed, the LVL includes
+two full {@code Policy} implementations that you can use without modification or
+adapt to your needs:</p>
+
+<ul>
+<li><a href="#ServerManagedPolicy">ServerManagedPolicy</a>, a flexible {@code Policy}
+that uses server-provided settings and cached responses to manage access across
+varied network conditions, and</li>
+<li><a href="#StrictPolicy">StrictPolicy</a>, which does not cache any response
+data and allows access <em>only</em> if the server returns a licensed
+response.</li>
+</ul>
+
+<p>For most applications, the use of ServerManagedPolicy is highly
+recommended. ServerManagedPolicy is the LVL default and is integrated with
+the LVL sample application.</p>
+
+
+<h3 id="custom-policies">Guidelines for custom policies</h3>
+
+<p>In your licensing implementation, you can use one of the complete policies
+provided in the LVL (ServerManagedPolicy or StrictPolicy) or you can create a
+custom policy. For any type of custom policy, there are several important design
+points to understand and account for in your implementation.</p>
+
+<p>The licensing server applies general request limits to guard against overuse
+of resources that could result in denial of service. When an application exceeds
+the request limit, the licensing server returns a 503 response, which gets
+passed through to your application as a general server error. This means that no
+license response will be available to the user until the limit is reset, which
+can affect the user for an indefinite period.</p>
+
+<p>If you are designing a custom policy, we recommend that the {@code Policy}:
+<ol>
+<!-- <li>Limits the number of points at which your app calls for a license check
+to the minimum. </li> -->
+<li>Caches (and properly obfuscates) the most recent successful license response
+in local persistent storage.</li>
+<li>Returns the cached response for all license checks, for as long as the
+cached response is valid, rather than making a request to the licensing server.
+Setting the response validity according to the server-provided <code>VT</code>
+extra is highly recommended. See <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#extras">Server Response Extras</a>
+for more information.</li>
+<li>Uses an exponential backoff period, if retrying any requests the result in
+errors. Note that the Android Market client automatically retries failed
+requests, so in most cases there is no need for your {@code Policy} to retry them.</li>
+<li>Provides for a "grace period" that allows the user to access your
+application for a limited time or number of uses, while a license check is being
+retried. The grace period benefits the user by allowing access until the next
+license check can be completed successfully and it benefits you by placing a
+hard limit on access to your application when there is no valid license response
+available.</li>
+</ol>
+
+<p>Designing your {@code Policy} according to the guidelines listed above is critical,
+because it ensures the best possible experience for users while giving you
+effective control over your application even in error conditions. </p>
+
+<p>Note that any {@code Policy} can use settings provided by the licensing server to
+help manage validity and caching, retry grace period, and more. Extracting the
+server-provided settings is straightforward and making use of them is highly
+recommended. See the ServerManagedPolicy implementation for an example of how to
+extract and use the extras. For a list of server settings and information about
+how to use them, see  <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#extras">Server Response
+Extras</a>.</p>
+
+<h3 id="ServerManagedPolicy">ServerManagedPolicy</h3>
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>Server Response Extras</h2>
+
+<p>For certain types of licensing responses, the licensing server appends extra
+settings to the responses, to help the application manage licensing effectively.
+</p>
+
+<p style="margin-top:.5em;">See <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#extras">Server Response Extras</a>
+for
+a list of settings and <code>ServerManagedPolicy.java</code> for information
+about how a {@code Policy} can use the extras.</p>
+
+</div>
+</div>
+
+<p>The LVL includes a full and recommended implementation of the {@code Policy}
+interface called ServerManagedPolicy. The implementation is integrated with the
+LVL classes and serves as the default {@code Policy} in the library. </p>
+
+<p>ServerManagedPolicy provides all of the handling for license and retry
+responses. It caches all of the response data locally in a
+{@link android.content.SharedPreferences} file, obfuscating it with the
+application's {@code Obfuscator} implementation. This ensures that the license response
+data is secure and persists across device power cycles. ServerManagedPolicy
+provides concrete implementations of the interface methods
+<code>processServerResponse()</code> and <code>allowAccess()</code> and also
+includes a set of supporting methods and types for managing license
+responses.</p>
+
+<p>Importantly, a key feature of ServerMangedPolicy is its use of
+server-provided settings as the basis for managing licensing across an
+application's refund period and through varying network and error conditions.
+When an application contacts the Android Market server for a license check, the
+server appends several settings as key-value pairs in the extras field of certain
+license response types. For example, the server provides recommended values for the
+application's license validity period, retry grace period, and maximum allowable
+retry count, among others. ServerManagedPolicy extracts the values from the
+license response in its <code>processServerResponse()</code> method and checks
+them in its <code>allowAccess()</code> method. For a list of the server-provided
+settings used by ServerManagedPolicy, see <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#extras">Server Response
+Extras</a>.</p>
+
+<p>For convenience, best performance, and the benefit of using license settings
+from the Android Market server, <strong>using ServerManagedPolicy as your
+licensing {@code Policy} is strongly recommended</strong>. </p>
+
+<p>If you are concerned about the security of license response data that is
+stored locally in {@link android.content.SharedPreferences}, you can use a stronger obfuscation
+algorithm or design a stricter {@code Policy} that does not store license data. The LVL
+includes an example of such a {@code Policy} &mdash; see <a
+href="#StrictPolicy">StrictPolicy</a> for more information.</p>
+
+<p>To use ServerManagedPolicy, simply import it to your Activity, create an
+instance, and pass a reference to the instance when constructing your
+{@code LicenseChecker}. See <a href="#lc-lcc">Instantiate LicenseChecker and
+LicenseCheckerCallback</a> for more information. </p>
+
+<h3 id="StrictPolicy">StrictPolicy</h3>
+
+<p>The LVL includes an alternative full implementation of the {@code Policy} interface
+called StrictPolicy. The StrictPolicy implementation provides a more restrictive
+Policy than ServerManagedPolicy, in that it does not allow the user to access
+the application unless a license response is received from the server at the
+time of access that indicates that the user is licensed.</p>
+
+<p>The principal feature of StrictPolicy is that it does not store <em>any</em>
+license response data locally, in a persistent store. Because no data is stored,
+retry requests are not tracked and cached responses can not be used to fulfill
+license checks. The {@code Policy} allows access only if:</p>
+
+<ul>
+<li>The license response is received from the licensing server, and </li>
+<li>The license response indicates that the user is licensed to access the
+application. </li>
+</ul>
+
+<p>Using StrictPolicy is appropriate if your primary concern is to ensure that,
+in all possible cases, no user will be allowed to access the application unless
+the user is confirmed to be licensed at the time of use. Additionally, the
+Policy offers slightly more security than ServerManagedPolicy &mdash; since
+there is no data cached locally, there is no way a malicious user could tamper
+with the cached data and obtain access to the application.</p>
+
+<p>At the same time, this {@code Policy} presents a challenge for normal users, since it
+means that they won't be able to access the application when there is no network
+(cell or Wi-Fi) connection available. Another side-effect is that your
+application will send more license check requests to the server, since using a
+cached response is not possible.</p>
+
+<p>Overall, this policy represents a tradeoff of some degree of user convenience
+for absolute security and control over access. Consider the tradeoff carefully
+before using this {@code Policy}.</p>
+
+<p>To use StrictPolicy, simply import it to your Activity, create an instance,
+and pass a reference to it when constructing your {@code LicenseChecker}. See
+<a href="#lc-lcc">Instantiate LicenseChecker and LicenseCheckerCallback</a>
+for more information. </p>
+
+<h2 id="impl-Obfuscator">Implementing an Obfuscator</h2>
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>AESObfuscator</h2>
+
+<p>The LVL includes a full {@code Obfuscator} implementation in the
+<code>AESObfuscator.java</code> file. The {@code Obfuscator} uses AES encryption to
+obfuscate/unobfuscate data. If you are using a {@code Policy} (such as
+ServerManagedPolicy) that caches license response data, using AESObfuscator as
+basis for your {@code Obfuscator} implementation is highly recommended. </p>
+
+</div>
+</div>
+
+<p>A typical {@code Policy} implementation needs to save the license response data for
+an application to a persistent store, so that it is accessible across
+application invocations and device power cycles.  For example, a {@code Policy} would
+maintain the timestamp of the last successful license check, the retry count,
+the license validity period, and similar information in a persistent store,
+rather than resetting the values each time the application is launched. The
+default {@code Policy} included in the LVL, ServerManagedPolicy, stores license response
+data in a {@link android.content.SharedPreferences} instance, to ensure that the
+data is persistent. </p>
+
+<p>Because the {@code Policy} will use stored license response data to determine whether
+to allow or disallow access to the application, it <em>must</em> ensure that any
+stored data is secure and cannot be reused or manipulated by a root user on a
+device. Specifically, the {@code Policy} must always obfuscate the data before storing
+it, using a key that is unique for the application and device. Obfuscating using
+a key that is both application-specific and device-specific is critical, because
+it prevents the obfuscated data from being shared among applications and
+devices.</p>
+
+<p>The LVL assists the application with storing its license response data in a
+secure, persistent manner. First, it provides an {@code Obfuscator}
+interface that lets your application supply the obfuscation algorithm of its
+choice for stored data. Building on that, the LVL provides the helper class
+PreferenceObfuscator, which handles most of the work of calling the
+application's {@code Obfuscator} class and reading and writing the obfuscated data in a
+{@link android.content.SharedPreferences} instance. </p>
+
+<p>The LVL provides a full {@code Obfuscator} implementation called
+AESObfuscator that uses AES encryption to obfuscate data. You can
+use AESObfuscator in your application without modification or you
+can adapt it to your needs. For more information, see the next section.</p>
+
+
+<h3 id="AESObfuscator">AESObfuscator</h3>
+
+<p>The LVL includes a full and recommended implementation of the {@code Obfuscator}
+interface called AESObfuscator. The implementation is integrated with the
+LVL sample application and serves as the default {@code Obfuscator} in the library. </p>
+
+<p>AESObfuscator provides secure obfuscation of data by using AES to
+encrypt and decrypt the data as it is written to or read from storage.
+The {@code Obfuscator} seeds the encryption using three data fields provided
+by the application: </p>
+
+<ol>
+<li>A salt &mdash; an array of random bytes to use for each (un)obfuscation. </li>
+<li>An application identifier string, typically the package name of the application.</li>
+<li>A device identifier string, derived from as many device-specific sources
+as possible, so as to make it as unique.</li>
+</ol>
+
+<p>To use AESObfuscator, first import it to your Activity. Declare a private
+static final array to hold the salt bytes and initialize it to 20 randomly
+generated bytes.</p>
+
+<pre>    ...
+    // Generate 20 random bytes, and put them here.
+    private static final byte[] SALT = new byte[] {
+     -46, 65, 30, -128, -103, -57, 74, -64, 51, 88, -95,
+     -45, 77, -117, -36, -113, -11, 32, -64, 89
+     };
+    ...
+</pre>
+
+<p>Next, declare a variable to hold a device identifier and generate a value for
+it in any way needed. For example, the sample application included in the LVL
+queries the system settings for the
+<code>android.Settings.Secure.ANDROID_ID</code>, which is unique to each device.
+</p>
+
+<p>Note that, depending on the APIs you use, your application might need to
+request additional permissions in order to acquire device-specific information.
+For example, to query the {@link android.telephony.TelephonyManager} to obtain
+the device IMEI or related data, the application will also need to request the
+<code>android.permission.READ_PHONE_STATE</code> permission in its manifest.</p>
+
+<p>Before requesting new permissions for the <em>sole purpose</em> of acquiring
+device-specific information for use in your {@code Obfuscator}, consider
+how doing so might affect your application or its filtering on Android Market
+(since some permissions can cause the SDK build tools to add
+the associated <code>&lt;uses-feature&gt;</code>).</p>
+
+<p>Finally, construct an instance of AESObfuscator, passing the salt,
+application identifier, and device identifier. You can construct the instance
+directly, while constructing your {@code Policy} and {@code LicenseChecker}. For example:</p>
+
+<pre>    ...
+    // Construct the LicenseChecker with a Policy.
+    mChecker = new LicenseChecker(
+        this, new ServerManagedPolicy(this,
+            new AESObfuscator(SALT, getPackageName(), deviceId)),
+        BASE64_PUBLIC_KEY  // Your public licensing key.
+        );
+    ...
+</pre>
+
+<p>For a complete example, see MainActivity in the LVL sample application.</p>
+
+
+<h2 id="impl-lc">Checking the License from an Activity</h2>
+
+<p>Once you've implemented a {@code Policy} for managing access to your application, the
+next step is to add a license check to your application, which initiates a query
+to the licensing server if needed and manages access to the application based on
+the license response. All of the work of adding the license check and handling
+the response takes place in your main {@link android.app.Activity} source file.
+</p>
+
+<p>To add the license check and handle the response, you must:</p>
+
+<ol>
+    <li><a href="#imports">Add imports</a></li>
+    <li><a href="#lc-impl">Implement LicenseCheckerCallback</a> as a private inner class</li>
+    <li><a href="#thread-handler">Create a Handler</a> for posting from LicenseCheckerCallback to the UI thread</li>
+    <li><a href="#lc-lcc">Instantiate LicenseChecker</a> and LicenseCheckerCallback</li>
+    <li><a href="#check-access">Call checkAccess()</a> to initiate the license check</li>
+    <li><a href="#account-key">Embed your public key</a> for licensing</li>
+    <li><a href="#handler-cleanup">Call your LicenseChecker's onDestroy() method</a> to close IPC connections.</li>
+</ol>
+
+<p>The sections below describe these tasks. </p>
+
+<h3 id="lc-overview">Overview of license check and response</h3>
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>Example: MainActivity</h2>
+
+<p>The sample application included with the LVL provides a full example of how
+to initiate a license check and handle the result, in the
+<code>MainActivity.java</code> file.</p>
+
+</div>
+</div>
+
+<p>In most cases, you should add the license check to your application's main
+{@link android.app.Activity}, in the {@link android.app.Activity#onCreate onCreate()} method. This
+ensures that when the user launches your application directly, the license check
+will be invoked immediately. In some cases, you can add license checks in other
+locations as well. For example, if your application includes multiple Activity
+components that other applications can start by {@link android.content.Intent},
+you could add license checks in those Activities.</p>
+
+<p>A license check consists of two main actions: </p>
+
+<ul>
+<li>A call to a method to initiate the license check &mdash; in the LVL, this is
+a call to the <code>checkAccess()</code> method of a {@code LicenseChecker} object that
+you construct.</li>
+<li>A callback that returns the result of the license check. In the LVL, this is
+a <code>LicenseCheckerCallback</code> interface that you implement. The
+interface declares two methods, <code>allow()</code> and
+<code>dontAllow()</code>, which are invoked by the library based on to the
+result of the license check. You implement these two methods with whatever logic
+you need, to allow or disallow the user access to your application. Note that
+these methods do not determine <em>whether</em> to allow access &mdash; that
+determination is the responsibility of your {@code Policy} implementation. Rather, these
+methods simply provide the application behaviors for <em>how</em> to allow and
+disallow access (and handle application errors).
+  <p>The <code>allow()</code> and <code>dontAllow()</code> methods do provide a "reason"
+for their response, which can be one of the {@code Policy} values, {@code LICENSED},
+{@code NOT_LICENSED}, or {@code RETRY}. In particular, you should handle the case in which
+the method receives the {@code RETRY} response for {@code dontAllow()} and provide the user with an
+"Retry" button, which might have happened because the service was unavailable during the
+request.</p></li>
+</ul>
+
+<div style="margin-bottom:2em;">
+
+<img src="{@docRoot}images/licensing_flow.png" style="text-align:left;margin-bottom:0;margin-left:3em;" />
+<div style="margin:.5em 0 1.5em 2em;padding:0"><strong>Figure 6.</strong> Overview of a
+typical license check interaction.</div>
+</div>
+
+<p>The diagram above illustrates how a typical license check takes place: </p>
+
+<ol>
+<li>Code in the application's main Activity instantiates {@code LicenseCheckerCallback}
+and {@code LicenseChecker} objects. When constructing {@code LicenseChecker}, the code passes in
+{@link android.content.Context}, a {@code Policy} implementation to use, and the
+publisher account's public key for licensing as parameters. </li>
+<li>The code then calls the <code>checkAccess()</code> method on the
+{@code LicenseChecker} object. The method implementation calls the {@code Policy} to determine
+whether there is a valid license response cached locally, in
+{@link android.content.SharedPreferences}.
+  <ul>
+    <li>If so, the <code>checkAccess()</code> implementation calls
+  <code>allow()</code>.</li>
+    <li>Otherwise, the {@code LicenseChecker} initiates a license check request that is sent
+  to the licensing server.</li>
+  </ul>
+
+<p class="note"><strong>Note:</strong> The licensing server always returns
+<code>LICENSED</code> when you perform a license check of a draft application.</p>
+</li>
+<li>When a response is received, {@code LicenseChecker} creates a LicenseValidator that
+verifies the signed license data and extracts the fields of the response, then
+passes them to your {@code Policy} for further evaluation.
+  <ul>
+    <li>If the license is valid, the {@code Policy} caches the response in
+{@link android.content.SharedPreferences} and notifies the validator, which then calls the
+<code>allow()</code> method on the {@code LicenseCheckerCallback} object. </li>
+    <li>If the license not valid, the {@code Policy} notifies the validator, which calls
+the <code>dontAllow()</code> method on {@code LicenseCheckerCallback}. </li>
+  </ul>
+</li>
+<li>In case of a recoverable local or server error, such as when the network is
+not available to send the request, {@code LicenseChecker} passes a {@code RETRY} response to
+your {@code Policy} object's <code>processServerResponse()</code> method. 
+  <p>Also, both the {@code allow()} and {@code dontAllow()} callback methods receive a
+<code>reason</code> argument. The {@code allow()} method's reason is usually {@code
+Policy.LICENSED} or {@code Policy.RETRY} and the {@code dontAllow()} reason is usually {@code
+Policy.NOT_LICENSED} or {@code Policy.RETRY}. These response values are useful so you can show
+an appropriate response for the user, such as by providing a "Retry" button when {@code
+dontAllow()} responds with {@code Policy.RETRY}, which might have been because the service was
+unavailable.</p></li>
+<li>In case of a application error, such as when the application attempts to
+check the license of an invalid package name, {@code LicenseChecker} passes an error
+response to the LicenseCheckerCallback's  <code>applicationError()</code>
+method. </li>
+</ol>
+
+<p>Note that, in addition to initiating the license check and handling the
+result, which are described in the sections below, your application also needs
+to provide a <a href="#impl-Policy">Policy implementation</a> and, if the {@code Policy}
+stores response data (such as ServerManagedPolicy), an <a
+href="#impl-Obfuscator">Obfuscator</a> implementation. </p>
+
+
+<h3 id="imports">Add imports</h3>
+
+<p>First, open the class file of the application's main Activity and import
+{@code LicenseChecker} and {@code LicenseCheckerCallback} from the LVL package.</p>
+
+<pre>    import com.android.vending.licensing.LicenseChecker;
+    import com.android.vending.licensing.LicenseCheckerCallback;</pre>
+
+<p>If you are using the default {@code Policy} implementation provided with the LVL,
+ServerManagedPolicy, import it also, together with the AESObfuscator. If you are
+using a custom {@code Policy} or {@code Obfuscator}, import those instead. </p>
+
+<pre>    import com.android.vending.licensing.ServerManagedPolicy;
+    import com.android.vending.licensing.AESObfuscator;</pre>
+
+<h3 id="lc-impl">Implement LicenseCheckerCallback as a private inner class</h3>
+
+<p>{@code LicenseCheckerCallback} is an interface provided by the LVL for handling
+result of a license check. To support licensing using the LVL, you must
+implement {@code LicenseCheckerCallback} and
+its methods to allow or disallow access to the application.</p>
+
+<p>The result of a license check is always a call to one of the
+{@code LicenseCheckerCallback} methods, made based on the validation of the response
+payload, the server response code itself, and any additional processing provided
+by your {@code Policy}. Your application can implement the methods in any way needed. In
+general, it's best to keep the methods simple, limiting them to managing UI
+state and application access. If you want to add further processing of license
+responses, such as by contacting a backend server or applying custom constraints,
+you should consider incorporating that code into your {@code Policy}, rather than
+putting it in the {@code LicenseCheckerCallback} methods. </p>
+
+<p>In most cases, you should declare your implementation of
+{@code LicenseCheckerCallback} as a private class inside your application's main
+Activity class. </p>
+
+<p>Implement the <code>allow()</code> and <code>dontAllow()</code> methods as
+needed. To start with, you can use simple result-handling behaviors in the
+methods, such as displaying the license result in a dialog. This helps you get
+your application running sooner and can assist with debugging. Later, after you
+have determined the exact behaviors you want, you can add more complex handling.
+</p>
+
+<p>Some suggestions for handling unlicensed responses in
+<code>dontAllow()</code> include: </p>
+
+<ul>
+<li>Display a "Try again" dialog to the user, including a button to initiate a
+new license check if the <code>reason</code> supplied is {@code Policy.RETRY}. </li>
+<li>Display a "Purchase this application" dialog, including a button that
+deep-links the user to the application's details page on Market, from which the
+use can purchase the application. For more information on how to set up such
+links, see <a
+href="{@docRoot}guide/publishing/publishing.html#marketintent">Using Intents to
+Launch the Market Application on a Device</a>. </li>
+<li>Display a Toast notification that indicates that the features of the
+application are limited because it is not licensed. </li>
+</ul>
+
+<p>The example below shows how the LVL sample application implements
+{@code LicenseCheckerCallback}, with methods that display the license check result in a
+dialog. </p>
+
+<pre>
+private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
+    public void allow(int reason) {
+        if (isFinishing()) {
+            // Don't update UI if Activity is finishing.
+            return;
+        }
+        // Should allow user access.
+        displayResult(getString(R.string.allow));
+    }
+
+    public void dontAllow(int reason) {
+        if (isFinishing()) {
+            // Don't update UI if Activity is finishing.
+            return;
+        }
+        displayResult(getString(R.string.dont_allow));
+        
+        if (reason == Policy.RETRY) {
+            // If the reason received from the policy is RETRY, it was probably
+            // due to a loss of connection with the service, so we should give the
+            // user a chance to retry. So show a dialog to retry.
+            showDialog(DIALOG_RETRY);
+        } else {
+            // Otherwise, the user is not licensed to use this app.
+            // Your response should always inform the user that the application
+            // is not licensed, but your behavior at that point can vary. You might
+            // provide the user a limited access version of your app or you can
+            // take them to Android Market to purchase the app.
+            showDialog(DIALOG_GOTOMARKET);
+        }
+    }
+}
+</pre>
+
+<p>Additionally, you should implement the <code>applicationError()</code>
+method, which the LVL calls to let your application handle errors that are not
+retryable. For a list of such errors, see <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#server-response-codes">Server
+Response Codes</a> in the <a
+href="guide/market/licensing/licensing-reference.html">Licensing Reference</a>. You can implement
+the method in any way needed. In most cases, the
+method should log the error code and call <code>dontAllow()</code>.</p>
+
+<h3 id="thread-handler">Create a Handler for posting from LicenseCheckerCallback
+to the UI thread</h3>
+
+<p>During a license check, the LVL passes the request to the Android Market
+application, which handles communication with the licensing server. The LVL
+passes the request over asynchronous IPC (using {@link android.os.Binder}) so
+the actual processing and network communication do not take place on a thread
+managed by your application. Similarly, when the Android Market application
+receives the result, it invokes a  callback method over IPC, which in turn
+executes in an IPC thread pool in your application's process.</p>
+
+<p>The {@code LicenseChecker} class manages your application's IPC communication with
+the Android Market application, including the call that sends the request and
+the callback that receives the response. {@code LicenseChecker} also tracks open license
+requests and manages their timeouts. </p>
+
+<p>So that it can handle timeouts properly and also process incoming responses
+without affecting your application's UI thread, {@code LicenseChecker} spawns a
+background thread at instantiation. In the thread it does all processing of
+license check results, whether the result is a response received from the server
+or a timeout error. At the conclusion of processing, the LVL calls your
+{@code LicenseCheckerCallback} methods from the background thread. </p>
+
+<p>To your application, this means that:</p>
+
+<ol>
+<li>Your {@code LicenseCheckerCallback} methods will be invoked, in many cases, from a
+background thread.</li>
+<li>Those methods won't be able to update state or invoke any processing in the
+UI thread, unless you create a Handler in the UI thread and have your callback
+methods post to the Handler.</li>
+</ol>
+
+<p>If you want your {@code LicenseCheckerCallback} methods to update the UI thread,
+instantiate a {@link android.os.Handler} in the main Activity's
+{@link android.app.Activity#onCreate(android.os.Bundle) onCreate()} method,
+as shown below. In this example, the LVL sample application's
+{@code LicenseCheckerCallback} methods (see above) call <code>displayResult()</code> to
+update the UI thread through the Handler's
+{@link android.os.Handler#post(java.lang.Runnable) post()} method.</p>
+
+<pre>private Handler mHandler;
+
+    &#64;Override
+    public void onCreate(Bundle savedInstanceState) {
+        ...
+        mHandler = new Handler();
+    }
+</pre>
+
+<p>Then, in your {@code LicenseCheckerCallback} methods, you can use Handler methods to
+post Runnable or Message objects to the Handler. Here's how the sample
+application included in the LVL posts a Runnable to a Handler in the UI thread
+to display the license status.</p>
+
+<pre>    private void displayResult(final String result) {
+        mHandler.post(new Runnable() {
+            public void run() {
+                mStatusText.setText(result);
+                setProgressBarIndeterminateVisibility(false);
+                mCheckLicenseButton.setEnabled(true);
+            }
+        });
+    }
+</pre>
+
+<h3 id="lc-lcc">Instantiate LicenseChecker and LicenseCheckerCallback</h3>
+
+<p>In the main Activity's
+{@link android.app.Activity#onCreate(android.os.Bundle) onCreate()} method,
+create private instances of LicenseCheckerCallback and {@code LicenseChecker}. You must
+instantiate {@code LicenseCheckerCallback} first, because you need to pass a reference
+to that instance when you call the constructor for {@code LicenseChecker}. </p>
+
+<p>When you instantiate {@code LicenseChecker}, you need to pass in these parameters:</p>
+
+<ul>
+<li>The application {@link android.content.Context}</li>
+<li>A reference to the {@code Policy} implementation to use for the license check. In
+most cases, you would use the default {@code Policy} implementation provided by the LVL,
+ServerManagedPolicy. </li>
+<li>The String variable holding your publisher account's public key for
+licensing. </li>
+</ul>
+
+<p>If you are using ServerManagedPolicy, you won't need to access the class
+directly, so you can instantiate it in the {@code LicenseChecker} constructor,
+as shown in the example below. Note that you need to pass a reference to a new
+Obfuscator instance when you construct ServerManagedPolicy.</p>
+
+<p>The example below shows the instantiation of {@code LicenseChecker} and
+{@code LicenseCheckerCallback} from the <code>onCreate()</code> method of an Activity
+class. </p>
+
+<pre>public class MainActivity extends Activity {
+    ...
+    private LicenseCheckerCallback mLicenseCheckerCallback;
+    private LicenseChecker mChecker;
+
+    &#64;Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        ...
+        // Construct the LicenseCheckerCallback. The library calls this when done.
+        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
+
+        // Construct the LicenseChecker with a Policy.
+        mChecker = new LicenseChecker(
+            this, new ServerManagedPolicy(this,
+                new AESObfuscator(SALT, getPackageName(), deviceId)),
+            BASE64_PUBLIC_KEY  // Your public licensing key.
+            );
+        ...
+    }
+}
+</pre>
+
+
+<p>Note that {@code LicenseChecker} calls the {@code LicenseCheckerCallback} methods from the UI
+thread <em>only</em> if there is valid license response cached locally. If the
+license check is sent to the server, the callbacks always originate from the
+background thread, even for network errors. </p>
+
+
+<h3 id="check-access">Call checkAccess() to initiate the license check</h3>
+
+<p>In your main Activity, add a call to the <code>checkAccess()</code> method of the
+{@code LicenseChecker} instance. In the call, pass a reference to your
+{@code LicenseCheckerCallback} instance as a parameter. If you need to handle any
+special UI effects or state management before the call, you might find it useful
+to call <code>checkAccess()</code> from a wrapper method. For example, the LVL
+sample application calls <code>checkAccess()</code> from a
+<code>doCheck()</code> wrapper method:</p>
+
+<pre>    &#64;Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        ...
+        // Call a wrapper method that initiates the license check
+        doCheck();
+        ...
+    }
+    ...
+    private void doCheck() {
+        mCheckLicenseButton.setEnabled(false);
+        setProgressBarIndeterminateVisibility(true);
+        mStatusText.setText(R.string.checking_license);
+        mChecker.checkAccess(mLicenseCheckerCallback);
+    }
+</pre>
+
+
+<h3 id="account-key">Embed your public key for licensing</h3>
+
+<p>For each publisher account, the Android Market service automatically
+generates a  2048-bit RSA public/private key pair that is used exclusively for
+licensing. The key pair is uniquely associated with the publisher account and is
+shared across all applications that are published through the account. Although
+associated with a publisher account, the key pair is <em>not</em> the same as
+the key that you use to sign your applications (or derived from it).</p>
+
+<p>The Android Market publisher site exposes the public key for licensing to any
+developer signed in to the publisher account, but it keeps the private key
+hidden from all users in a secure location. When an application requests a
+license check for an application published in your account, the licensing server
+signs the license response using the private key of your account's key pair.
+When the LVL receives the response, it uses the public key provided by the
+application to verify the signature of the license response. </p>
+
+<p>To add licensing to an application, you must obtain your publisher account's
+public key for licensing and copy it into your application. Here's how to find
+your account's public key for licensing:</p>
+
+<ol>
+<li>Go to the Android Market <a
+href="http://market.android.com/publish">publisher site</a> and sign in.
+Make sure that you sign in to the account from which the application you are
+licensing is published (or will be published). </li>
+<li>In the account home page, locate the "Edit profile" link and click it. </li>
+<li>In the Edit Profile page, locate the "Licensing" pane, shown below. Your
+public key for licensing is given in the "Public key" text box. </li>
+</ol>
+
+<p>To add the public key to your application, simply copy/paste the key string
+from the text box into your application as the value of the String variable
+<code>BASE64_PUBLIC_KEY</code>. When you are copying, make sure that you have
+selected the entire key string, without omitting any characters. </p>
+
+<p>Here's an example from the LVL sample application:</p>
+
+<pre>    public class MainActivity extends Activity {
+        private static final String BASE64_PUBLIC_KEY = "MIIBIjANBgkqhkiG ... "; //truncated for this example
+    ...
+    }
+</pre>
+
+<h3 id="handler-cleanup">Call your LicenseChecker's onDestroy() method
+to close IPC connections</h3>
+
+<p>Finally, to let the LVL clean up before your application
+{@link android.content.Context} changes, add a call to the {@code LicenseChecker}'s
+<code>onDestroy()</code> method from your Activity's
+{@link android.app.Activity#onDestroy()} implementation. The call causes the
+{@code LicenseChecker} to properly close any open IPC connection to the Android Market
+application's ILicensingService and removes any local references to the service
+and handler.</p>
+
+<p>Failing to call the {@code LicenseChecker}'s <code>onDestroy()</code> method
+can lead to problems over the lifecycle of your application. For example, if the
+user changes screen orientation while a license check is active, the application
+{@link android.content.Context} is destroyed. If your application does not
+properly close the {@code LicenseChecker}'s IPC connection, your application will crash
+when the response is received. Similarly, if the user exits your application
+while a license check is in progress,  your application will crash when the
+response is received, unless it has properly called the
+{@code LicenseChecker}'s <code>onDestroy()</code> method to disconnect from the service.
+</p>
+
+<p>Here's an example from the sample application included in the LVL, where
+<code>mChecker</code> is the {@code LicenseChecker} instance:</p>
+
+<pre>    &#64;Override
+    protected void onDestroy() {
+        super.onDestroy();
+        mChecker.onDestroy();
+        ...
+    }
+</pre>
+
+<p>If you are extending or modifying {@code LicenseChecker}, you might also need to call
+the {@code LicenseChecker}'s <code>finishCheck()</code> method, to clean up any open IPC
+connections.</p>
+
+<h2 id="impl-DeviceLimiter">Implementing a DeviceLimiter</h2>
+
+<p>In some cases, you might want your {@code Policy} to limit the number of actual
+devices that are permitted to use a single license. This would prevent a user
+from moving a licensed application onto a number of devices and using the
+application on those devices under the same account ID. It would also prevent a
+user from "sharing" the application by providing the account information
+associated with the license to other individuals, who could then sign in to that
+account on their devices and access the license to the application. </p>
+
+<p>The LVL supports per-device licensing by providing a
+<code>DeviceLimiter</code> interface, which declares a single method,
+<code>allowDeviceAccess()</code>. When a LicenseValidator is handling a response
+from the licensing server, it calls <code>allowDeviceAccess()</code>, passing a
+user ID string extracted from the response.</p>
+
+<p>If you do not want to support device limitation, <strong>no work is
+required</strong> &mdash; the {@code LicenseChecker} class automatically uses a default
+implementation called NullDeviceLimiter. As the name suggests, NullDeviceLimiter
+is a "no-op" class whose <code>allowDeviceAccess()</code> method simply returns
+a <code>LICENSED</code> response for all users and devices. </p>
+
+<div style="border-left:4px solid #FFCF00;margin:1em;padding: 0 0 0 .5em">
+<p><strong>Caution:</strong> Per-device licensing is <em>not recommended for
+most applications</em> because:</p>
+<ul>
+<li>It requires that you provide a backend server to manage a users and devices
+mapping, and </li>
+<li>It could inadvertently result in a user being denied access to an
+application that they have legitimately purchased on another device.</li>
+</ul>
+</div>
+
+
+
+
+
+
+
+
+
+
+
+<h2 id="app-obfuscation">Obfuscating Your Code</h2>
+
+<p>To ensure the security of your application, particularly for a paid
+application that uses licensing and/or custom constraints and protections, it's
+very important to obfuscate your application code. Properly obfuscating your
+code makes it more difficult for a malicious user to decompile the application's
+bytecode, modify it &mdash; such as by removing the license check &mdash;
+and then recompile it.</p>
+
+<p>Several obfuscator programs are available for Android applications, including
+<a href="http://proguard.sourceforge.net/">ProGuard</a>, which also offers
+code-optimization features. The use of ProGuard or a similar program to obfuscate
+your code is <em>strongly recommended</em> for all applications that use Android
+Market Licensing. </p>
+
+<h2 id="app-publishing">Publishing a Licensed Application</h2>
+
+<p>When you are finished testing your license implementation, you are ready to
+publish the application on Android Market. Follow the normal steps to <a
+href="{@docRoot}guide/publishing/preparing.html">prepare</a>, <a
+href="{@docRoot}guide/publishing/app-signing.html">sign</a>, and then <a
+href="{@docRoot}guide/publishing/publishing.html">publish the application</a>.
+</p>
+
+<h3>Removing Copy Protection</h3>
+
+<p>After uploading your licensed application, remember to remove copy protection
+from the application, if it is currently used. To check and remove copy
+protection, sign in to the publisher site and go the application's upload
+details page. In the Publishing options section, make sure that the Copy
+Protection radio button selection is "Off".</p>
+
+
+<h2 id="support">Where to Get Support</h2>
+
+<p>If you have questions or encounter problems while implementing or deploying
+publishing in your applications, please use the support resources listed in the
+table below. By directing your queries to the correct forum, you can get the
+support you need more quickly. </p>
+
+<p class="table-caption"><strong>Table 2.</strong> Developer support resources
+for Android Market Licensing Service.</p>
+
+<table>
+
+<tr>
+<th>Support Type</th>
+<th>Resource</th>
+<th>Range of Topics</th>
+</tr>
+<tr>
+<td rowspan="2">Development and testing issues</td>
+<td>Google Groups: <a
+href="http://groups.google.com/group/android-developers">android-developers</a>
+</td>
+<td rowspan="2">LVL download and integration, library projects, {@code Policy}
+questions, user experience ideas, handling of responses, {@code Obfuscator}, IPC, test
+environment setup</td>
+</tr>
+<tr>
+<td>Stack Overflow: <a
+href="http://stackoverflow.com/questions/tagged/android">http://stackoverflow.com/questions/tagged/android</a></td>
+</tr>
+<tr>
+<td rowspan="2">Accounts, publishing, and deployment issues</td>
+<td><a href="http://www.google.com/support/forum/p/Android+Market">Android
+Market Help Forum</a></td>
+<td rowspan="2">Publisher accounts, licensing key pair, test accounts, server
+responses, test responses, application deployment and results</td>
+</tr>
+<tr>
+<td><a
+href="http://market.android.com/support/bin/answer.py?answer=186113">Market
+Licensing Support FAQ</a></td>
+</tr>
+<tr>
+<td>LVL issue tracker</td>
+<td><a href="http://code.google.com/p/marketlicensing/issues/">Marketlicensing
+project issue tracker</a></td>
+<td>Bug and issue reports related specifically to the LVL source code classes
+and interface implementations</td>
+</tr>
+
+</table>
+
+<p>For general information about how to post to the groups listed above, see <a
+href="{@docRoot}resources/community-groups.html">Developer Forums</a> document
+in the Resources tab.</p>
+
+
diff --git a/docs/html/guide/market/licensing/index.jd b/docs/html/guide/market/licensing/index.jd
new file mode 100644
index 0000000..f08176d
--- /dev/null
+++ b/docs/html/guide/market/licensing/index.jd
@@ -0,0 +1,61 @@
+page.title=Application Licensing
+@jd:body
+
+
+<p>Android Market offers a licensing service that lets you enforce licensing policies for
+applications that you publish on Android Market. With Android Market Licensing, your application can
+query Android Market at run time to obtain the licensing status for the current user, then allow or
+disallow further use as appropriate. </p>
+
+<p>Using the service, you can apply a flexible licensing policy on an application-by-application
+basis&mdash;each application can enforce licensing in the way most appropriate for it. If necessary,
+an application can apply custom constraints based on the licensing status obtained from Android
+Market. For example, an application can check the licensing status and then apply custom constraints
+that allow the user to run it unlicensed for a specific validity period. An application can also
+restrict use of the application to a specific device, in addition to any other constraints. </p>
+
+<p>The licensing service is a secure means of controlling access to your applications. When an
+application checks the licensing status, the Android Market server signs the licensing status
+response using a key pair that is uniquely associated with the publisher account. Your application
+stores the public key in its compiled <code>.apk</code> file and uses it to verify the licensing
+status response.</p>
+
+<p>Any application that you publish through Android Market can use the Android Market Licensing
+service. No special account or registration is needed. Additionally, because the service uses no
+dedicated framework APIs, you can add licensing to any application that uses a minimum API level of
+3 or higher.</p>
+
+<p class="note"><strong>Note:</strong> The Android Market Licensing service is primarily intended
+for paid applications that wish to verify that the current user did in fact pay for the application
+on Android Market. However, any application (including free apps) may use the licensing service
+to initiate the download of an APK expansion file. In which case, the request that your application
+sends to the licensing service is not to check whether the user paid for the app, but to request the
+URL of the expansion files. For information about downloading expansion files for your application,
+read the guide to <a href="{@docRoot}guide/market/expansion-files.html">APK Expansion Files</a>.</p>
+
+
+<p>To learn more about Android Market's application licensing service and start integrating it into
+your applications, read the following documents:</p>
+
+<dl>
+  <dt><strong><a href="{@docRoot}guide/market/licensing/overview.html">Licensing
+Overview</a></strong></dt>
+    <dd>Describes how the service works and what a typical licensing implementation looks
+like.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/licensing/setting-up.html">Setting Up for
+Licensing</a></strong></dt>
+    <dd>Explains how to set up your Android Market account, development environment, and
+testing environment in order to add licensing to your app.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/licensing/adding-licensing.html">Adding
+Licensing to Your App</a></strong></dt>
+    <dd>Provides a step-by-step guide to add licensing verification to your application.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/licensing/licensing-reference.html">Licensing
+Reference</a></strong></dt>
+    <dd>Provides detailed information about the licensing library's classes and the service response
+codes.</dd>
+</dl>
+
+
+
+
+
diff --git a/docs/html/guide/market/licensing/licensing-reference.jd b/docs/html/guide/market/licensing/licensing-reference.jd
new file mode 100644
index 0000000..ac5d596
--- /dev/null
+++ b/docs/html/guide/market/licensing/licensing-reference.jd
@@ -0,0 +1,439 @@
+page.title=Licensing Reference
+parent.title=Application Licensing
+parent.link=index.html
+@jd:body
+
+
+
+<div id="qv-wrapper">
+<div id="qv">
+  
+  <h2>In this document</h2>
+  <ol>
+    <li><a href="#lvl-summary">LVL Classes and Interfaces</a></li>
+    <li><a href="#server-response-codes">Server Response Codes</a></li>
+    <li><a href="#extras">Server Response Extras</a></li>
+  </ol>
+
+</div>
+</div>
+
+
+<h2 id="lvl-summary">LVL Classes and Interfaces</h2>
+
+<p>Table 1 lists all of the source files in the License Verification
+Library (LVL) available through the Android SDK. All of the files are part of
+the <code>com.android.vending.licensing</code> package.</p>
+
+<p class="table-caption"><strong>Table 1.</strong> Summary of LVL library
+classes and interfaces.</p>
+
+<div style="width:99%">
+<table width="100%">
+
+<tr>
+<th width="15%">Category</th>
+<th width="20%">Name</th>
+<th width="100%">Description</th>
+</tr>
+
+<tr>
+<td rowspan="2">License check and result</td>
+<td>LicenseChecker</td>
+<td>Class that you instantiate (or subclass) to initiate a license check.</td>
+</tr>
+<tr>
+<td><em>LicenseCheckerCallback</em></td>
+<td>Interface that you implement to handle result of the license check.</td>
+</tr>
+
+<tr>
+<td rowspan="3" width="15%">Policy</td>
+<td width="20%"><em>Policy</em></td>
+<td width="100%">Interface that you implement to determine whether to allow
+access to the application, based on the license response. </td>
+</tr>
+<tr>
+<td>ServerManagedPolicy</td>
+<td width="100%">Default {@code Policy} implementation. Uses settings provided by the
+licensing server to manage local storage of license data, license validity,
+retry.</td>
+</tr>
+<tr>
+<td>StrictPolicy</td>
+<td>Alternative {@code Policy} implementation. Enforces licensing based on a direct
+license response from the server only. No caching or request retry.</td>
+</tr>
+
+<tr>
+<td rowspan="2" width="15%">Data obfuscation <br><em>(optional)</em></td>
+<td width="20%"><em>Obfuscator</em></td>
+<td width="100%">Interface that you implement if you are using a {@code Policy} (such as
+ServerManagedPolicy) that caches license response data in a persistent store.
+Applies an obfuscation algorithm to encode and decode data being written or
+read.</td>
+</tr>
+<tr>
+<td>AESObfuscator</td>
+<td>Default Obfuscator implementation that uses AES encryption/decryption
+algorithm to obfuscate/unobfuscate data.</td>
+</tr>
+
+<tr>
+<td rowspan="2" width="15%">Device limitation<br><em>(optional)</em></td>
+<td width="20%"><em>DeviceLimiter</em></td>
+<td width="100%">Interface that you implement if you want to restrict use of an
+application to a specific device. Called from LicenseValidator. Implementing
+DeviceLimiter is not recommended for most applications because it requires a
+backend server and may cause the user to lose access to licensed applications,
+unless designed with care.</td>
+</tr>
+<tr>
+<td>NullDeviceLimiter</td>
+<td>Default DeviceLimiter implementation that is a no-op (allows access to all
+devices).</td>
+</tr>
+
+<tr>
+<td rowspan="6" width="15%">Library core, no integration needed</td>
+<td width="20%">ResponseData</td>
+<td width="100%">Class that holds the fields of a license response.</td>
+</tr>
+<tr>
+<td>LicenseValidator</td>
+<td>Class that decrypts and verifies a response received from the licensing
+server.</td>
+</tr>
+<tr>
+<td>ValidationException</td>
+<td>Class that indicates errors that occur when validating the integrity of data
+managed by an Obfuscator.</td>
+</tr>
+<tr>
+<td>PreferenceObfuscator</td>
+<td>Utility class that writes/reads obfuscated data to the system's
+{@link android.content.SharedPreferences} store.</td>
+</tr>
+<tr>
+<td><em>ILicensingService</em></td>
+<td>One-way IPC interface over which a license check request is passed to the
+Android Market client.</td>
+</tr>
+<tr>
+<td><em>ILicenseResultListener</em></td>
+<td>One-way IPC callback implementation over which the application receives an
+asynchronous response from the licensing server.</td>
+</tr>
+
+</table>
+</div>
+
+
+<h2 id="server-response-codes">Server Response Codes</h2>
+
+<p>Table 2 lists all of the license response codes supported by the
+licensing server. In general, an application should handle all of these response
+codes. By default, the LicenseValidator class in the LVL provides all of the
+necessary handling of these response codes for you. </p>
+
+<p class="table-caption"><strong>Table 2.</strong> Summary of response codes
+returned by the Android Market server in a license response.</p>
+
+<table>
+
+<tr>
+<th>Response Code</th>
+<th>Description</th>
+<th>Signed?</th>
+<th>Extras</th>
+<th>Comments</th>
+</tr>
+<tr>
+<td>{@code LICENSED}</td>
+<td>The application is licensed to the user. The user has purchased the
+application or the application only exists as a draft.</td>
+<td>Yes</td>
+<td><code>VT</code>,&nbsp;<code>GT</code>, <code>GR</code></td>
+<td><em>Allow access according to {@code Policy} constraints.</em></td>
+</tr>
+<tr>
+<td>{@code LICENSED_OLD_KEY}</td>
+<td>The application is licensed to the user, but there is an updated application
+version available that is signed with a different key. </td>
+<td>Yes </td>
+<td><code>VT</code>, <code>GT</code>, <code>GR</code>, <code>UT</code></td>
+<td><em>Optionally allow access according to {@code Policy} constraints.</em>
+<p style="margin-top:.5em;">Can indicate that the key pair used by the installed
+application version is invalid or compromised. The application can allow access
+if needed or inform the user that an upgrade is available and limit further use
+until upgrade.</p>
+</td>
+</tr>
+<tr>
+<td>{@code NOT_LICENSED}</td>
+<td>The application is not licensed to the user.</td>
+<td>No</td>
+<td></td>
+<td><em>Do not allow access.</em></td>
+</tr>
+<tr>
+<td>{@code ERROR_CONTACTING_SERVER}</td>
+<td>Local error &mdash; the Android Market application was not able to reach the
+licensing server, possibly because of network availability problems. </td>
+<td>No</td>
+<td></td>
+<td><em>Retry the license check according to {@code Policy} retry limits.</em></td>
+</tr>
+<tr>
+<td>{@code ERROR_SERVER_FAILURE}</td>
+<td>Server error &mdash; the server could not load the publisher account's key
+pair for licensing.</td>
+<td>No</td>
+<td></td>
+<td><em>Retry the license check according to {@code Policy} retry limits.</em>
+</td>
+</tr>
+<tr>
+<td>{@code ERROR_INVALID_PACKAGE_NAME}</td>
+<td>Local error &mdash; the application requested a license check for a package
+that is not installed on the device. </td>
+<td>No </td>
+<td></td>
+<td><em>Do not retry the license check.</em>
+<p style="margin-top:.5em;">Typically caused by a development error.</p>
+</td>
+</tr>
+<tr>
+<td>{@code ERROR_NON_MATCHING_UID}</td>
+<td>Local error &mdash; the application requested a license check for a package
+whose UID (package, user ID pair) does not match that of the requesting
+application. </td>
+<td>No </td>
+<td></td>
+<td><em>Do not retry the license check.</em>
+<p style="margin-top:.5em;">Typically caused by a development error.</p>
+</td>
+</tr>
+<tr>
+<td>{@code ERROR_NOT_MARKET_MANAGED}</td>
+<td>Server error &mdash; the application (package name) was not recognized by
+Android Market. </td>
+<td>No</td>
+<td></td>
+<td><em>Do not retry the license check.</em>
+<p style="margin-top:.5em;">Can indicate that the application was not published
+through Android Market or that there is an development error in the licensing
+implementation.</p>
+</td>
+</tr>
+
+</table>
+
+<p class="note"><strong>Note:</strong> As documented in <a
+href="{@docRoot}guide/market/licensing/setting-up.html#test-env">
+Setting Up The Testing Environment</a>, the response code can be manually
+overridden for the application developer and any registered test users via the
+Android Market publisher site.
+<br/><br/>
+Additionally, as noted above, applications that are in draft mode (in other
+words, applications that have been uploaded but have <em>never</em> been
+published) will return {@code LICENSED} for all users, even if not listed as a test
+user. Since the application has never been offered for download, it is assumed
+that any users running it must have obtained it from an authorized channel for
+testing purposes.</p>
+
+
+
+
+<h2 id="extras">Server Response Extras</h2>
+
+<p>To assist your application in managing access to the application across the application refund
+period and provide other information, The licensing server includes several pieces of
+information in the license responses. Specifically, the service provides recommended values for the
+application's license validity period, retry grace period, maximum allowable retry count, and other
+settings. If your application uses <a href="{@docRoot}guide/market/expansion-files.html">APK
+expansion files</a>, the response also includes the file names, sizes, and URLs. The server appends
+the settings as key-value pairs in the license response "extras" field. </p>
+
+<p>Any {@code Policy} implementation can extract the extras settings from the license
+response and use them as needed. The LVL default {@code Policy} implementation, <a
+href="{@docRoot}guide/market/licensing/adding-licensing.html#ServerManagedPolicy">{@code
+ServerManagedPolicy}</a>, serves as a working
+implementation and an illustration of how to obtain, store, and use the
+settings. </p>
+
+<p class="table-caption"><strong>Table 3.</strong> Summary of
+license-management settings supplied by the Android Market server in a license
+response.</p>
+
+<table>
+<tr>
+<th>Extra</th><th>Description</th>
+</tr>
+
+<tr>
+  <td>{@code VT}</td>
+  <td>License validity timestamp. Specifies the date/time at which the current
+(cached) license response expires and must be rechecked on the licensing server. See the section
+below about <a href="#VT">License validity period</a>.
+ </td>
+</tr>
+<tr>
+  <td>{@code GT}</td>
+  <td>Grace period timestamp. Specifies the end of the period during which a
+Policy may allow access to the application, even though the response status is
+{@code RETRY}. <p>The value is managed by the server, however a typical value would be 5
+or more days. See the section
+below about <a href="#GTGR">Retry period and maximum retry count</a>.</p></td>
+</tr>
+<tr>
+  <td>{@code GR}</td>
+  <td>Maximum retries count. Specifies how many consecutive {@code RETRY} license checks
+the {@code Policy} should allow, before denying the user access to the application.
+<p>The value is managed by the server, however a typical value would be "10" or
+higher. See the section
+below about <a href="#GTGR">Retry period and maximum retry count</a>.</p></td>
+</tr>
+<tr>
+  <td>{@code UT}</td>
+  <td>Update timestamp. Specifies the day/time when the most recent update to
+this application was uploaded and published. <p>The server returns this extra
+only for {@code LICENSED_OLD_KEYS} responses, to allow the {@code Policy} to determine how much
+time has elapsed since an update was published with new licensing keys before
+denying the user access to the application. </p></td>
+</tr>
+
+
+<!-- APK EXPANSION FILE RESPONSES -->
+
+<tr>
+  <td>{@code FILE_URL1} or {@code FILE_URL2}</td>
+  <td>The URL for an expansion file (1 is for the main file, 2 is the patch file). Use this to
+download the file over HTTP.</td>
+</tr>
+<tr>
+  <td>{@code FILE_NAME1} or {@code FILE_NAME2}</td>
+  <td>The expansion file's name (1 is for the main file, 2 is the patch file). You must use this
+name when saving the file on the device.</td>
+</tr>
+<tr>
+  <td>{@code FILE_SIZE1} or {@code FILE_SIZE2}</td>
+  <td>The size of the file in bytes (1 is for the main file, 2 is the patch file). Use this to
+assist with downloading and to ensure that enough space is available on the device's shared
+storage location before downloading.</td>
+</tr>
+
+</table>
+
+
+
+<h4 id="VT">License validity period</h4>
+
+<p>The Android Market licensing server sets a license validity period for all
+downloaded applications. The period expresses the interval of time over which an
+application's license status should be considered as unchanging and cacheable by
+a licensing {@code Policy} in the application. The licensing server includes the
+validity period in its response to all license checks, appending an
+end-of-validity timestamp to the response as an extra under the key {@code VT}. A
+{@code Policy} can extract the VT key value and use it to conditionally allow access to
+the application without rechecking the license, until the validity period
+expires. </p>
+
+<p>The license validity signals to a licensing {@code Policy} when it must recheck the
+licensing status with the licensing server. It is <em>not</em> intended to imply
+whether an application is actually licensed for use. That is, when an
+application's license validity period expires, this does not mean that the
+application is no longer licensed for use &mdash; rather, it indicates only that
+the {@code Policy} must recheck the licensing status with the server. It follows that,
+as long as the license validity period has not expired, it is acceptable for the
+{@code Policy} to cache the initial license status locally and return the cached license
+status instead of sending a new license check to the server.</p>
+
+<p>The licensing server manages the validity period as a means of helping the
+application properly enforce licensing across the refund period offered by
+Android Market for paid applications. It sets the validity period based on
+whether the application was purchased and, if so, how long ago. Specifically,
+the server sets a validity period as follows:</p>
+
+<ul>
+<li>For a paid application, the server sets the initial license validity period
+so that the license response remains valid for as long as the application is
+refundable. A licensing {@code Policy} in the application may cache the
+result of the initial license check and does not need to recheck the license
+until the validity period has expired.</li>
+<li>When an application is no longer refundable, the server
+sets a longer validity period &mdash; typically a number of days. </li>
+
+<!-- TODO: Verify the following behavior is still true w/ OBB: -->
+<li>For a free application, the server sets the validity period to a very high
+value (<code>long.MAX_VALUE</code>). This ensures that, provided the {@code Policy} has
+cached the validity timestamp locally, it will not need to recheck the
+license status of the application in the future.</li>
+</ul>
+
+<p>The {@code ServerManagedPolicy} implementation uses the extracted timestamp
+(<code>mValidityTimestamp</code>) as a primary condition for determining whether
+to recheck the license status with the server before allowing the user access to
+the application. </p>
+
+
+<h4 id="GTGR">Retry period and maximum retry count</h4>
+
+<p>In some cases, system or network conditions can prevent an application's
+license check from reaching the licensing server, or prevent the server's
+response from reaching the Android Market client application. For example, the
+user might launch an application when there is no cell network or data
+connection available&mdash;such as when on an airplane&mdash;or when the
+network connection is unstable or the cell signal is weak. </p>
+
+<p>When network problems prevent or interrupt a license check, the Android
+Market client notifies the application by returning a {@code RETRY} response code to
+the {@code Policy}'s <code>processServerResponse()</code> method. In the case of system
+problems, such as when the application is unable to bind with Android Market's
+{@code ILicensingService} implementation, the {@code LicenseChecker} library itself calls the
+Policy <code>processServerResonse()</code> method with a {@code RETRY} response code.
+</p>
+
+<p>In general, the {@code RETRY} response code is a signal to the application that an
+error has occurred that has prevented a license check from completing.
+
+<p>The Android Market server helps an application to manage licensing under
+error conditions by setting a retry "grace period" and a recommended maximum
+retries count. The server includes these values in all license check responses,
+appending them as extras under the keys {@code GT} and {@code GR}. </p>
+
+<p>The application {@code Policy} can extract the {@code GT} and {@code GR} extras and use them to
+conditionally allow access to the application, as follows:</p>
+
+<ul>
+<li>For a license check that results in a {@code RETRY} response, the {@code Policy} should
+cache the {@code RETRY} response code and increment a count of {@code RETRY} responses.</li>
+<li>The {@code Policy} should allow the user to access the application, provided that
+either the retry grace period is still active or the maximum retries count has
+not been reached.</li>
+</ul>
+
+<p>The {@code ServerManagedPolicy} uses the server-supplied {@code GT} and {@code GR} values as
+described above. The example below shows the conditional handling of the retry
+responses in the <code>allow()</code> method. The count of {@code RETRY} responses is
+maintained in the <code>processServerResponse()</code> method, not shown. </p>
+
+
+<pre>    
+public boolean allowAccess() {
+    long ts = System.currentTimeMillis();
+    if (mLastResponse == LicenseResponse.LICENSED) {
+        // Check if the LICENSED response occurred within the validity timeout.
+        if (ts &lt;= mValidityTimestamp) {
+            // Cached LICENSED response is still valid.
+            return true;
+        }
+    } else if (mLastResponse == LicenseResponse.RETRY &amp;&amp;
+                ts &lt; mLastResponseTime + MILLIS_PER_MINUTE) {
+        // Only allow access if we are within the retry period or we haven't used up our
+        // max retries.
+        return (ts &lt;= mRetryUntil || mRetryCount &lt;= mMaxRetries);
+    }
+    return false;
+}</pre>
+
diff --git a/docs/html/guide/market/licensing/overview.jd b/docs/html/guide/market/licensing/overview.jd
new file mode 100644
index 0000000..3576e26
--- /dev/null
+++ b/docs/html/guide/market/licensing/overview.jd
@@ -0,0 +1,245 @@
+page.title=Licensing Overview
+parent.title=Application Licensing
+parent.link=index.html
+@jd:body
+
+
+<div id="qv-wrapper">
+<div id="qv">
+  
+  <h2>Quickview</h2>
+  <ul>
+    <li>Licensing allows you to verify your app was purchased from Android Market</li>
+    <li>Your app maintains control of how it enforces its licensing status</li>
+    <li>The service is free for all developers who publish on Android Market</li>
+  </ul>
+  
+  <h2>In this document</h2>
+  <ol>
+  <li><a href="#Secure">License Responses are Secure</a></li>
+  <li><a href="#LVL">Licensing Verification Library</a></li>
+  <li><a href="#Reqs">Requirements and Limitations</a></li>
+  <li><a href="#CopyProtection">Replacement for Copy Protection</a></li>
+</ol>
+  
+</div>
+</div>
+
+
+<p>Android Market Licensing is a network-based service that lets an application query a trusted
+Android Market licensing server to determine whether the application is licensed to the current
+device user. The licensing service is based on the capability of the Android Market licensing server
+to determine whether a given user is licensed to use a given application. Android Market considers a
+user to be licensed if the user is a recorded purchaser of the application.</p>
+
+<p>The request starts when your application makes a request to a service hosted by
+the Android Market client application. The Android Market application then sends a request to
+the licensing server and receives the result. The Android Market application sends
+the result to your application, which can allow or disallow further use of the
+application as needed.</p>
+
+<p class="note"><strong>Note:</strong> If a paid application has been uploaded to Android Market but
+saved only as a draft application (the app is unpublished), the licensing server considers all users
+to be licensed users of the application (because it's not even possible to purchase the app).
+This exception is necessary in order for you to perform testing of your licensing
+implementation.</p>
+
+
+<div class="figure" style="width:469px">
+<img src="{@docRoot}images/licensing_arch.png" alt=""/>
+<p class="img-caption"><strong>Figure 1.</strong> Your application initiates a
+license check through the License Verification Library and the Android Market
+client, which handles communication with the Market server.</p>
+</div>
+
+
+<p>To properly identify the user and determine the license status, the licensing server requires
+information about the application and user&mdash;your application and the Android Market client work
+together to assemble the information and the Android Market client passes it to the server. </p>
+
+<p>To help you add licensing to your application, the Android SDK provides a downloadable set of
+library sources that you can include in your application project: the "Google Market Billing
+package." The License Verification Library (LVL) is a library you can add to your application that
+handles all of the licensing-related communication with the Android Market licensing service. With
+the LVL added to your application, your application can determine its licensing status for the
+current user by simply calling a method and implementing a callback that receives the status
+response.</p>
+
+<p>Your application does not query the licensing server
+directly, but instead calls the Android Market client over remote IPC to
+initiate a license request. In the license request:</p>
+
+<ul>
+<li>Your application provides: its package name, a nonce that is later used to
+validate any response from the server, and a callback over which the
+response can be returned asynchronously.</li>
+<li>The Android Market client collects the necessary information about the user and the device,
+such as the device's primary Google account username, IMSI, and other
+information. It then sends the license check request to the server on behalf of
+your application.</li>
+<li>The Android Market server evaluates the request using all available information, attempting
+to establish the user's identity to a sufficient level of confidence. The server
+then checks the user identity against purchase records for your application and
+returns a license response, which the Android Market client returns to your
+application over the IPC callback.</li>
+</ul>
+
+<p>You can choose when, and how often, you want your application to check its
+license and you have full control over how it handles the response, verifies the
+signed response data, and enforces access controls.</p>
+
+<p>Notice that during a license check, your application does not manage any
+network connections or use any licensing related APIs in the Android platform.</p>
+
+
+
+
+<h2 id="Secure">License Responses are Secure</h2>
+
+<p>To ensure the integrity of each license query, the server signs the license
+response data using an RSA key pair that is shared exclusively between the Android Market
+server and you.</p>
+
+<p>The licensing service generates a single licensing key pair for each
+publisher account and exposes the public key in your account's profile page. You must copy the
+public key from the web site and embed it in your application source code. The server retains the
+private key internally and uses it to sign license responses for the applications you
+publish with that account.</p>
+
+<p>When your application receives a signed response, it uses the embedded public
+key to verify the data. The use of public key cryptography in the licensing
+service makes it possible for the application to detect responses that have been
+tampered with or that are spoofed.</p>
+
+
+
+
+<h2 id="LVL">Licensing Verification Library</h2>
+
+<p>The Android SDK provides a downloadable component called the "Google Market Licensing package,"
+which includes the License Verification Library (LVL). The LVL greatly simplifies the process of
+adding licensing to your application and helps ensure a more secure, robust implementation for your
+application. The LVL provides internal classes that handle most of the standard operations of a
+license query, such as contacting the Android Market client to initiate a license request and
+verifying and validating the responses. It also exposes interfaces that let you easily plug in your
+custom code for defining licensing policy and managing access as needed by your application. The key
+LVL interfaces are: </p>
+
+<dl>
+<dt>{@code Policy}</dt>
+  <dd>Your implementation determines whether to allow access to the
+application, based on the license response received from the server and any
+other data available (such as from a backend server associated with your
+application). The implementation can evaluate the various fields of the license
+response and apply other constraints, if needed. The implementation also lets
+you manage the handling of license checks that result in errors, such as network
+errors.</dd>
+
+<dt>{@code LicenseCheckerCallback}</dt>
+  <dd>Your implementation manages access to the
+application, based on the result of the {@code Policy} object's handling of the license
+response. Your implementation can manage access in any way needed, including
+displaying the license result in the UI or directing the user to purchase the
+application (if not currently licensed).</dd>
+</dl>
+
+
+<p>To help you get started with a {@code Policy}, the LVL provides two fully complete
+{@code Policy} implementations that you can use without modification or adapt to your
+needs:</p>
+
+<dl>
+<dt><a href="adding-licensing.html#ServerManagedPolicy">{@code ServerManagedPolicy}</a></dt>
+  <dd>A flexible {@code Policy}
+that uses settings provided by the licensing server to manage response caching
+and access to the application while the device is offline (such as when the
+user is on an airplane). For most applications, the use of
+{@code ServerManagedPolicy} is highly recommended.</dd>
+
+<dt><a href="adding-licensing.html#StrictPolicy">{@code StrictPolicy}</a></dt>
+  <dd>A restrictive {@code Policy} that
+does not cache any response data and allows the application access <em>only</em>
+when the server returns a licensed response.</dd>
+</dl>
+
+<p>The LVL is available as a downloadable component of the Android SDK. The
+component includes both the LVL itself and an example application that shows how
+the library should be integrated with your application and how your application
+should manage response data, UI interaction, and error conditions. </p>
+
+<p>The LVL sources are provided as an Android <em>library project</em>, which
+means that you can maintain a single set of library sources and share them
+across multiple applications. A full test environment is also available through
+the SDK, so you can develop and test the licensing implementation in your
+applications before publishing them, even if you don't have access to a
+physical device.</p>
+
+
+
+
+<h2 id="Reqs">Requirements and Limitations</h2>
+
+<p>Android Market Licensing is designed to let you apply license controls to
+applications that you publish through Android Market. The service is not
+designed to let you control access to applications that are not published
+through Android Market or that are run on devices that do not offer the Android
+Market client. </p>
+
+<p>Here are some points to keep in mind as you implement licensing in your
+application: </p>
+
+<ul>
+<li>An application can use the service only if the Android Market client is
+installed on its host device and the device is running Android 1.5 (API level 3)
+or higher.</li>
+<li>To complete a license check, the licensing server must be accessible over
+the network. You can implement license caching behaviors to manage access to your application when
+there is no network connectivity. </li>
+<li>The security of your application's licensing controls ultimately relies on
+the design of your implementation itself. The service provides the building
+blocks that let you securely check licensing, but the actual enforcement and
+handling of the license are factors are up to you. By following the best
+practices in the following documents, you can help ensure that your implementation will be
+secure.</li>
+<li>Adding licensing to an application does not affect the way the application
+functions when run on a device that does not offer Android Market.</li>
+<li>You can implement licensing controls for a free app, but only if you're using the service to 
+provide <a
+href="{@docRoot}guide/market/expansion-files.html">APK expansion files</a>.</li>
+</ul>
+
+
+
+<h2 id="CopyProtection">Replacement for Copy Protection</h2>
+
+<p>Android Market Licensing is a flexible, secure mechanism for controlling
+access to your applications. It effectively replaces the Copy Protection
+mechanism offered on Android Market and gives you wider distribution
+potential for your applications. </p>
+
+<ul>
+<li>A limitation of the legacy Copy Protection mechanism on Android Market is
+that applications using it can be installed only on compatible devices that
+provide a secure internal storage environment. For example, a copy-protected
+application cannot be downloaded from Market to a device that provides root
+access, and the application cannot be installed to a device's SD card. </li>
+<li>With Android Market licensing, you can move to a license-based model in
+which access is not bound to the characteristics of the host device, but to your
+publisher account on Android Market and the licensing policy that you define.
+Your application can be installed and controlled on any compatible device on
+any storage, including SD card.</li>
+</ul>
+
+<p>Although no license mechanism can completely prevent all unauthorized use,
+the licensing service lets you control access for most types of normal usage,
+across all compatible devices, locked or unlocked, that run Android 1.5 or
+higher version of the platform.</p>
+
+<p>To begin adding application licensing to your application, continue to <a
+href="{@docRoot}guide/market/licensing/setting-up.html">Setting Up for Licensing</a>.</p>
+
+
+
+
+
+
diff --git a/docs/html/guide/market/licensing/setting-up.jd b/docs/html/guide/market/licensing/setting-up.jd
new file mode 100644
index 0000000..c79f90b
--- /dev/null
+++ b/docs/html/guide/market/licensing/setting-up.jd
@@ -0,0 +1,707 @@
+page.title=Setting Up for Licensing
+parent.title=Application Licensing
+parent.link=index.html
+@jd:body
+
+
+<div id="qv-wrapper">
+<div id="qv">
+  
+  <h2>In this document</h2>
+  <ol>
+  <li><a href="#account">Setting Up a Publisher Account</a></li>
+  <li><a href="#dev-setup">Setting Up the Development Environment</a>
+    <ol>
+      <li><a href="#runtime-setup">Setting up the runtime environment</a></li>
+      <li><a href="#download-lvl">Downloading the LVL</a></li>
+      <li><a href="#lvl-setup">Setting Up the Licensing Verification Library</a></li>
+      <li><a href="#add-library">Including the LVL library project sources in your
+application</a></li>
+    </ol>
+  </li>
+  <li><a href="#test-env">Setting Up the Testing Environment</a>
+    <ol>
+      <li><a href="#test-response">Setting test responses for license checks</a></li>
+      <li><a href="#test-acct-setup">Setting up test accounts</a></li>
+      <li><a href="#acct-signin">Signing in to an authorized account in the runtime
+environment</a></li>
+    </ol>
+  </li>
+</ol>
+</div>
+</div>
+
+<p>Before you start adding license verification to your application, you need to set up your Android
+Market publishing account, your development environment, and test accounts required to verify
+your implementation.</p>
+
+
+<h2 id="account">Setting Up a Publisher Account</h2>
+
+<p>If you don't already have a publisher account for Android Market, you need to register for one
+using your Google account and agree to the terms of service on the Android Market publisher site:</p>
+
+<p style="margin-left:2em;"><a
+href="http://market.android.com/publish">http://market.android.com/publish</a>
+</p>
+
+<p>For more information, see <a
+href="{@docRoot}guide/publishing/publishing.html">Publishing on Android Market</a>.</p>
+
+<p>If you already have a publisher account on Android Market, use your existing
+account to set up licensing.</p>
+
+<p>Using your publisher account on Android Market, you can:</p>
+
+<ul>
+<li>Obtain a public key for licensing</li>
+<li>Debug and test an application's licensing implementation, prior to
+publishing the application</li>
+<li>Publish the applications to which you have added licensing support</li>
+</ul>
+
+<h4>Administrative settings for licensing</h4>
+
+<p>You can manage several
+administrative controls for Android Market licensing on the publisher site. The controls are available
+in the Edit Profile page, in the "Licensing" panel, shown in figure 1. The controls
+let you: </p>
+
+<ul>
+<li>Set up multiple "test accounts," identified by email address. The licensing
+server allows users signed in to test accounts on a device or emulator to send
+license checks and receive static test responses.</li>
+<li>Obtain the account's public key for licensing. When you are implementing
+licensing in an application, you must copy the public key string into the
+application.</li>
+<li>Configure static test responses that the server sends, when it receives a
+license check for an application uploaded to the publisher account, from a user
+signed in to the publisher account or a test account.</li>
+</ul>
+
+
+<img src="{@docRoot}images/licensing_public_key.png" alt=""/>
+<p class="img-caption"><strong>Figure 1.</strong> The Licensing
+panel of your account's Edit Profile page lets you manage administrative
+settings for licensing.</p>
+
+<p>For more information about how to work with test accounts and static test
+responses, see <a href="#test-env">Setting Up a Testing Environment</a>, below.
+
+
+
+<h2 id="dev-setup">Setting Up the Development Environment</h2>
+
+<p>Setting up your environment for licensing involves these tasks:</p>
+
+<ol>
+<li><a href="#runtime-setup">Setting up the runtime environment</a> for development</li>
+<li><a href="#download-lvl">Downloading the LVL</a> into your SDK </li>
+<li><a href="#lvl-setup">Setting up the Licensing Verification Library</a></li>
+<li><a href="#add-library">Including the LVL library project in your application</a></li>
+</ol>
+
+<p>The sections below describe these tasks. When you are done with setup,
+you can begin <a href="{@docRoot}guide/market/licensing/adding-licensing.html">Adding
+Licensing to Your App</a>.</p>
+
+<p>To get started, you need to set up a proper runtime environment on which
+you can run, debug, and test your application's implementation of license
+checking and enforcement. </p>
+
+
+<h3 id="runtime-setup">Setting up the runtime environment</h3>
+
+<p>As described earlier, applications check licensing status not by contacting
+the licensing server directly, but by binding to a service provided by the
+Android Market application and initiating a license check request. The Android
+Market service then handles the direct communication with the licensing server
+and finally routes the response back to your application. To debug and test
+licensing in your application, you need to set up a runtime environment that
+includes the necessary Android Market service, so that your application is able
+to send license check requests to the licensing server. </p>
+
+<p>There are two types of runtime environment that you can use: </p>
+
+<ul>
+<li>An Android-powered device that includes the Android Market application, or</li>
+<li>An Android emulator running the Google APIs Add-on, API level 8 (release 2)
+or higher</li>
+</ul>
+
+<h4 id="runtime-device">Running on a device</h4>
+
+<p>To use an Android-powered device for
+debugging and testing licensing, the device must:</p>
+
+<ul>
+<li>Run a compatible version of Android 1.5 or later (API level
+3 or higher) platform, <em>and</em> </li>
+<li>Run a system image on which the Android Market client application
+is preinstalled. </li>
+</ul>
+
+<p>If Android Market is not preinstalled in the system image, your application won't
+be able to communicate with the Android Market licensing server. </p>
+
+<p>For general information about how to set up a device for use in developing
+Android applications, see <a
+href="{@docRoot}guide/developing/device.html">Using Hardware Devices</a>.</p>
+
+<h4 id="runtime-emulator">Running on an Android emulator</h4>
+
+<p>If you don't have a device available, you can use an Android emulator for debugging and testing
+licensing.</p>
+
+<p>Because the Android platforms provided in the Android SDK <em>do
+not</em> include Android Market, you need to download the Google APIs Add-On
+platform, API level 8 (or higher), from the SDK repository. After downloading
+the add-on, you need to create an AVD configuration that uses that system image.
+</p>
+
+<p>The Google APIs Add-On does not include the full Android Market client.
+However, it does provide: </p>
+
+<ul>
+<li>An Android Market background service that implements the
+<code>ILicensingService</code> remote interface, so that your application can
+send license checks over the network to the licensing server. </li>
+<li>A set of underlying account services that let you add an a Google account on
+the AVD and sign in using your publisher account or test account credentials.
+<p>Signing in using your publisher or test account enables you to debug and test
+your application without having publish it. For more information see <a
+href="#acct-signin">Signing in to an authorized account</a>, below.</p></li>
+</ul>
+
+<p>Several versions of the add-on are available through the SDK Manager, but only
+<strong>Google APIs Add-On, API 8 (release 2) or higher</strong> includes the necessary Android
+Market services.</p>
+
+
+<img src="{@docRoot}images/licensing_gapis_8.png" alt=""/>
+<p class="img-caption"><strong>Figure 2.</strong> Google APIs
+Add-On, API 8 (release 2) or higher lets you debug and test your licensing
+implementation in an emulator.</p>
+
+<p>To set up an emulator for adding licensing to an application, follow
+these steps: </p>
+
+<ol>
+  <li>Launch the Android SDK Manager. </li>
+  <li>In the <strong>Available Packages</strong> panel, select and download the
+SDK component "Google APIs (Google Inc.) - API Level 8" (or higher) from the SDK
+repository, as shown in figure 2.
+  <p>When the download is complete, use the Android SDK Manager to
+create a new AVD based on that component, described next.</p></li>
+  <li>In the <strong>Virtual
+Devices</strong> panel of the Android SDK Manager, click
+<strong>New</strong> and set the configuration details for the new AVD. </li>
+  <li>In the dialog that appears, assign a descriptive name to the AVD and then
+use the "Target" menu to choose the "Google APIs (Google Inc.) - API Level 8" as
+the system image to run on the new AVD. Set the other configuration details as
+needed and then click <strong>Create AVD</strong> to finish. The SDK tools
+create the new AVD configuration, which then appears in the list of available
+Android Virtual Devices.</li>
+</ol>
+
+<p>If you are not familiar with AVDs or how to use them, see <a
+href="{@docRoot}guide/developing/devices/index.html">Managing Virtual Devices</a>.</p>
+
+<h4 id="project-update">Updating your project configuration</h4>
+
+<p>After you set up a runtime environment that meets the requirements described
+above &mdash; either on an actual device or on an emulator &mdash; make sure to
+update your application project or build scripts as needed, so that your compiled
+<code>.apk</code> files that use licensing are deployed into that environment.
+In particular, if you are developing in Eclipse, make sure that you set up a
+Run/Debug Configuration that targets the appropriate device or AVD. </p>
+
+<p>You do not need to make any changes to your application's
+build configuration, provided that the project is already configured to compile
+against a standard Android 1.5 (API level 3) or higher library. For example:
+
+<ul>
+<li>If you have an existing application that is compiled against
+the Android 1.5 library, you do not need to make any changes to your
+build configuration to support licensing. The build target meets the minimum
+requirements for licensing, so you would continue building
+against the same version of the Android platform.</li>
+
+<li>Similarly, if you are building against Android 1.5 (API level 3) but
+are using an emulator running the Google APIs Add-On API 8 as the application's
+runtime environment, there is no need to change your application's build
+configuration. </li>
+</ul>
+
+<p>In general, adding licensing to an application should have no impact
+whatsoever on the application's build configuration.</p>
+
+
+<h3 id="download-lvl">Downloading the LVL</h3>
+
+<p>The License Verification Library (LVL) is a collection of helper classes that
+greatly simplify the work that you need to do to add licensing to your
+application. In all cases, we recommend that you download the LVL and use it as
+the basis for the licensing implementation in your application.</p>
+
+<p>The LVL is available as a downloadable component of the Android SDK. The
+component includes: </p>
+
+<ul>
+<li>The LVL sources, stored inside an Android library project. </li>
+<li>An example application called "sample" that depends on the LVL library
+project. The example illustrates how an application uses the library helper
+classes to check and enforce licensing.</li>
+</ul>
+
+<p>To download the LVL component into your development environment, use the
+Android SDK Manager. Launch the Android SDK Manager and then
+select the "Market Licensing" component, as shown in figure 3.
+Accept the terms and click <strong>Install Selected</strong> to begin the download. </p>
+
+<img src="{@docRoot}images/licensing_package.png" alt=""/>
+<p class="img-caption"><strong>Figure 3.</strong> The Market Licensing package contains the LVL and
+the LVL sample application.</p>
+
+<p>When the download is complete, the Android SDK Manager installs both
+the LVL library project and the example application into these directories: </p>
+
+<p style="margin-left:2em"><code>&lt;<em>sdk</em>&gt;/extras/google/market_licensing/library/</code>
+&nbsp;&nbsp;(the LVL library project)<br />
+<code>&lt;<em>sdk</em>&gt;/extras/google/market_licensing/sample/</code>&nbsp;&nbsp;(the example
+application)</p>
+
+<p>If you aren't familiar with how to download components into your SDK, see the
+<a href="{@docRoot}sdk/adding-components.html">Adding SDK Components</a>
+document. </p>
+
+
+<h3 id="lvl-setup">Setting Up the Licensing Verification Library</h3>
+
+<p>After downloading the LVL to your computer, you need to set it up in your
+development environment, either as an Android library project or by
+copying (or importing) the library sources directly into your existing
+application package. In general, using the LVL as a library project is recommended,
+since it lets you reuse your licensing code across multiple applications and
+maintain it more easily over time. Note that the LVL is not designed to be
+compiled separately and added to an application as a static .jar file. </p>
+
+<h4>Moving the library sources to a new location</h4>
+
+<p>Because you will be customizing the LVL sources to some extent, you should
+make sure to <em>move or copy</em> the library sources (the entire
+directory at <code>&lt;<em>sdk</em>&gt;/market_licensing/library/</code>)
+to a working directory outside of the SDK. You should then use the relocated
+sources as your working set. If you are using a source-code management
+system, add and track the sources that are in the working location rather
+than those in default location in the SDK. </p>
+
+<p>Moving the library sources is important is because, when you later update the
+Market licensing package, the SDK installs the new files to the same location as
+the older files. Moving your working library files to a safe location ensures
+that your work won't be inadvertently overwritten should you download a new
+version of the LVL.</p>
+
+<h4>Creating the LVL as a library project</h4>
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>Working with library projects</h2>
+
+<p>The LVL is provided as an Android library project, which means that you can
+share its code and resources across multiple applications. </p>
+
+<p style="margin-top:.5em;">If you aren't familiar with library projects or how
+to use them, see <a href="{@docRoot}guide/developing/projects/index.html#LibraryProjects">
+Managing Projects</a>.
+</p>
+</div>
+</div>
+
+<p>The recommended way of using the LVL is setting it up as a new Android
+<em>library project</em>. A library project is a type of development project
+that holds shared Android source code and resources. Other Android application
+projects can reference the library project and, at build time, include its
+compiled sources in their <code>.apk</code> files. In the context of licensing,
+this means that you can do most of your licensing development once, in a library
+project, then include the library sources in your various application projects.
+In this way, you can easily maintain a uniform implementation of licensing
+across all of your projects and maintain it centrally. </p>
+
+<p>The LVL is provided as a configured library project &mdash; once you have
+downloaded it, you can start using it right away. </p>
+
+<p>If you are working in Eclipse with ADT, you need to add the LVL to your
+workspace as a new development project, in the same way as you would a new
+application project. </p>
+
+<ol>
+<li>Use the New Project Wizard to create a new
+project from existing sources. Select the LVL's <code>library</code> directory
+(the directory containing the library's AndroidManifest.xml file) as the project
+root.</li>
+<li>When you are creating the library project, you can select any application
+name, package, and set other fields as needed. </li>
+<li>For the library's build target, select Android 1.5 (API level 3) or higher.</li>
+</ol>
+
+<p> When created, the project is
+predefined as a library project in its <code>project.properties</code> file, so
+no further configuration is needed. </p>
+
+<p>For more information about how to create an application project or work with
+library projects in Eclipse, see <a
+href="{@docRoot}guide/developing/projects/projects-eclipse.html">Managing Projects from
+Eclipse with ADT</a>.</p>
+
+
+<h4>Copying the LVL sources to your application</h4>
+
+<p>As an alternative to adding the LVL as a library project, you can copy the
+library sources directly into your application. To do so, copy (or import) the
+LVL's <code>library/src/com</code> directory into your application's
+<code>src/</code> directory.</p>
+
+<p>If you add the LVL sources directly to your application, you can skip the
+next section and start working with the library, as described in <a
+href="{@docRoot}guide/market/licensing/adding-licensing.html">Adding
+Licensing to Your App</a>.</p>
+
+
+<h3 id="add-library">Including the LVL library project sources in your
+application</h3>
+
+<p>If you want to use the LVL sources as a library project, you need to add a
+reference to the LVL library project in your application project properties. This tells
+build tools to include the LVL library project sources in your application at
+compile time. The process for adding a reference to a library project depends
+on your development environment, as described below.</p>
+
+<p> If you are developing in Eclipse with ADT, you should already have added the
+library project to your workspace, as described in the previous section. If you
+haven't done that already, do it now before continuing. </p>
+
+<p>Next, open the application's project properties window, as shown below.
+Select the "Android" properties group and click <strong>Add</strong>, then
+choose the LVL library project (com_android_vending_licensing) and click
+<strong>OK</strong>. For more information, see
+<a href="{@docRoot}guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject">
+Managing Projects from Eclipse with ADT</a></p>.
+
+
+<img src="{@docRoot}images/licensing_add_library.png" alt=""/>
+<p class="img-caption"><strong>Figure 4.</strong> If you are
+working in Eclipse with ADT, you can add the LVL library project to your
+application from the application's project properties.</p>
+
+
+<p>If you are developing using the SDK command-line tools, navigate to the
+directory containing your application project and open the
+<code>project.properties</code> file. Add a line to the file that specifies the
+<code>android.library.reference.&lt;n&gt;</code> key and the path to the
+library. For example: </p>
+
+<pre>android.library.reference.1=path/to/library_project</pre>
+
+<p>Alternatively, you can use this command to update the project
+properties, including the reference to the library project:</p>
+
+<pre class="no-pretty-print" style="color:black">android update lib-project
+--target <em>&lt;target_ID&gt;</em> \
+--path <em>path/to/my/app_project</em> \
+--library <em>path/to/my/library_project</em>
+</pre>
+
+<p>For more information about working with library projects,
+see <a href="{@docRoot}guide/developing/projects/projects-cmdline.html#SettingUpLibraryProject">
+Setting up a Library Project</a>.</p>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<h2 id="test-env">Setting Up the Testing Environment</h2>
+
+<p>The Android Market publisher site provides configuration tools that let you
+and others test licensing on your application before it is published. As you are
+implementing licensing, you can make use of the publisher site tools to test
+your application's Policy and handling of different licensing responses and
+error conditions.</p>
+
+<p>The main components of the test environment for licensing include: </p>
+
+<ul>
+<li>A "Test response" configuration in your publisher account that lets you
+set the static licensing response returned, when the server processes a
+license check for an application uploaded to the publisher account, from a user
+signed in to the publisher account or a test account.</li>
+<li>An optional set of test accounts that will receive the static test
+response when they check the license of an application that you have uploaded
+(regardless whether the application is published or not).</li>
+<li>A runtime environment for the application that includes the Android Market
+application or Google APIs Add-On, on which the user is signed in to the
+publisher account or one of the test accounts.</li>
+</ul>
+
+<p>Setting up the test environment properly involves:</p>
+
+<ol>
+<li><a href="#test-response">Setting static test responses</a> that are returned by the licensing server.</li>
+<li><a href="#test-acct-setup">Setting up test accounts</a> as needed.</li>
+<li><a href="#acct-signin">Signing in</a> properly to an emulator or device, before initiating a license check test.</li>
+</ol>
+
+<p>The sections below provide more information.</p>
+
+
+<h3 id="test-response">Setting test responses for license checks</h3>
+
+<p>Android Market provides a configuration setting in your publisher account
+that lets you override the normal processing of a license check and return a
+specified static response code. The setting is for testing only and applies
+<em>only</em> to license checks for applications that you have uploaded, made by
+any user signed in to an emulator or device using the credentials of the
+publisher account or a registered test account. For other users, the server
+always processes license checks according to normal rules.  </p>
+
+<p>To set a test response for your account, sign in to your publisher account
+and click "Edit Profile". In the Edit Profile page, locate the Test Response
+menu in the Licensing panel, shown below. You can select from the full set of
+valid server response codes to control the response or condition you want to
+test in your application.</p>
+
+<p>In general, you should make sure to test your application's licensing
+implementation with every response code available in the Test Response menu.
+For a description of the codes, see <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#server-response-codes">Server
+Response Codes</a> in the <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html">Licensing Reference</a>.</p>
+
+<img src="{@docRoot}images/licensing_test_response.png" alt=""/>
+<p class="img-caption"><strong>Figure 5.</strong> The Licensing
+panel of your account's Edit Profile page, showing the Test Accounts field and the
+Test Response menu.</p>
+
+<p>Note that the test response that you configure applies account-wide &mdash;
+that is, it applies not to a single application, but to <em>all</em>
+applications associated with the publisher account. If you are testing multiple
+applications at once, changing the test response will affect all of those
+applications on their next license check (if the user is signed in to
+the emulator or device using the publisher account or a test account).</p>
+
+<p>Before you can successfully receive a test response for a license check,
+you must sign in to the device or emulator on which the application
+is installed, and from which it is querying the server. Specifically, you must
+sign using either your publisher account or one of the test accounts that you
+have set up. For more information about test accounts, see the next section.</p>
+
+<p>See <a
+href="{@docRoot}guide/market/licensing/licensing-reference.html#server-response-codes">Server
+Response Codes</a> for a list of
+test responses available and their meanings. </p>
+
+
+<h3 id="test-acct-setup">Setting up test accounts</h3>
+
+<p>In some cases, you might want to let multiple teams of developers test
+licensing on applications that will ultimately be published through your
+publisher account, but without giving them access to your publisher account's
+sign-in credentials. To meet that need, the Android Market publisher site lets
+you set up one or more optional <em>test accounts</em> &mdash; accounts that are
+authorized to query the licensing server and receive static test responses from
+your publisher account.</p>
+
+<p>Test accounts are standard Google accounts that you register on your
+publisher account, such that they will receive the test response for
+applications that you have uploaded. Developers can then sign in to their
+devices or emulators using the test account credentials and initiate license
+checks from installed applications. When the licensing server receives a license
+check from a user of a test account, it returns the static test response
+configured for the publisher account.  </p>
+
+<p>Necessarily, there are limitations on the access and permissions given to
+users signed in through test accounts, including:</p>
+
+<ul>
+<li>Test account users can query the licensing server only for applications that
+are already uploaded to the publisher account. </li>
+<li>Test account users do not have permission to upload applications to your
+publisher account.</li>
+<li>Test account users do not have permission to set the publisher account's
+static test response.</li>
+</ul>
+
+<p>The table below summarizes the differences in capabilities, between the
+publisher account, a test account, and any other account.</p>
+
+<p class="table-caption" id="acct-types-table"><strong>Table 1.</strong>
+Differences in account types for testing licensing.</p>
+
+<table>
+<tr>
+<th>Account Type</th>
+<th>Can check license before upload?</th>
+<th>Can receive test response?</th>
+<th>Can set test response?</th>
+</tr>
+
+<tr>
+<td>Publisher account</td>
+<td>Yes</td>
+<td>Yes</td>
+<td>Yes</td>
+</tr>
+
+<tr>
+<td>Test account</td>
+<td>No</td>
+<td>Yes</td>
+<td>No</td>
+</tr>
+
+<tr>
+<td>Other</td>
+<td>No</td>
+<td>No</td>
+<td>No</td>
+</tr>
+</table>
+
+<h4 id="reg-test-acct">Registering test accounts on the publisher account</h4>
+
+<p>To get started, you need to register each test account in your publisher
+account. As shown in Figure 5, you
+register test accounts in the Licensing panel of your publisher account's Edit
+Profile page. Simply enter the accounts as a comma-delimited list and click
+<strong>Save</strong> to save your profile changes.</p>
+
+<p>You can use any Google account as a test account. If you want to own and
+control the test accounts, you can create the accounts yourself and distribute
+the credentials to your developers or testers.</p>
+
+<h4 id="test-app-upload">Handling application upload and distribution for test
+account users</h4>
+
+<p>As mentioned above, users of test accounts can only receive static test
+responses for applications that are uploaded to the publisher account. Since
+those users do not have permission to upload applications, as the publisher you
+will need to work with those users to collect apps for upload and distribute
+uploaded apps for testing. You can handle collection and distribution in any way
+that is convenient. </p>
+
+<p>Once an application is uploaded and becomes known to the licensing server,
+developers and testers can continue modify the application in their local
+development environment, without having to upload new versions. You only need to
+upload a new version if the local application increments the
+<code>versionCode</code> attribute in the manifest file. </p>
+
+<h4 id="test-key">Distributing your public key to test account users</h4>
+
+<p>The licensing server handles static test responses in the normal way,
+including signing the license response data, adding extras parameters, and so
+on. To support developers who are implementing licensing using test accounts,
+rather than the publisher account, you will need to distribute
+your public key to them. Developers without access to the publisher site do not
+have access to your public key, and without the key they won't be able to
+verify license responses. </p>
+
+<p>Note that if you decide to generate a new licensing key pair for your account
+for some reason, you need to notify all users of test accounts. For
+testers, you can embed the new key in the application package and distribute it
+to users. For developers, you will need to distribute the new key to them
+directly. </p>
+
+
+<h3 id="acct-signin">Signing in to an authorized account in the runtime
+environment</h3>
+
+<p>The licensing service is designed to determine whether a given user is
+licensed to use a given application &mdash; during a license check, the Android
+Market application gathers the user ID from the primary account on the system
+and sends it to the server, together with the package name of the application
+and other information. However, if there is no user information available, the
+license check cannot succeed, so the Android Market application terminates the
+request and returns an error to the application. </p>
+
+<p>During testing, to ensure that your application can successfully query the
+licensing server, you must make sure that you sign in to an account <em>on the
+device or emulator</em> using:</p>
+
+<ul>
+<li>The credentials of a publisher account, or</li>
+<li>The credentials of a test account that is registered with a publisher
+account</li>
+</ul>
+
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>Signing in to a Google account on an emulator</h2>
+
+<p>If you are testing licensing on an emulator, you need to sign in to a Google
+account on the emulator. If you do not see an option to create a new Google
+account, the problem might be that your AVD is running a standard Android system
+image, rather than the Google APIs Add-On, API 8 (release 2) or higher. </p>
+
+<p style="margin-top:.5em;">For more information, see <a
+href="#runtime-setup">Setting up the runtime environment</a>, above.</p>
+
+</div>
+</div>
+
+<p>Signing in using a publisher account offers the advantage of letting your
+applications receive static test responses even before the applications are
+uploaded to the publisher site.</p>
+
+<p>If you are part of a larger organization or are working with external groups
+on applications that will be published through your site, you will more likely
+want to distribute test accounts instead, then use those to sign in during
+testing. </p>
+
+<p>To sign in on a device or emulator, follow the steps below. The preferred
+approach is to sign in as the primary account &mdash; however, if there are
+other accounts already in use on the device or emulator, you can create an
+additional account and sign in to it using the publisher or test account
+credentials.  </p>
+
+<ol>
+<li>Open Settings &gt; Accounts &amp; sync</li>
+<li>Select <strong>Add Account</strong> and choose to add a "Google" account.
+</li>
+<li>Select <strong>Next</strong> and then <strong>Sign in</strong>.</li>
+<li>Enter the username and password of either the publisher account or a test
+account that is registered in the publisher account.</li>
+<li>Select <strong>Sign in</strong>. The system signs you in to the new
+account.</li>
+</ol>
+
+<p>Once you are signed in, you can begin testing licensing in your application
+(if you have completed the LVL integration steps above). When your application
+initiates a license check, it will receive a response containing the static test
+response configured on the publisher account. </p>
+
+<p>Note that, if you are using an emulator, you will need to sign in to the
+publisher account or test account each time you wipe data when restarting the
+emulator.</p>
+
+<p>Once you've completed the setup procedures, continue to <a
+href="{@docRoot}guide/market/licensing/adding-licensing.html">Adding Licensing to Your App</a>.</p>
+
+
+
diff --git a/docs/html/guide/publishing/licensing.html b/docs/html/guide/publishing/licensing.html
new file mode 100644
index 0000000..8e97f32
--- /dev/null
+++ b/docs/html/guide/publishing/licensing.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="refresh"
+content="0;url=http://developer.android.com/guide/market/licensing/index.html">
+<title>Redirecting...</title>
+</head>
+<body>
+<p>You should have been redirected. Please <a
+href="http://developer.android.com/guide/market/licensing/index.html">click here</a>.</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/docs/html/guide/publishing/licensing.jd b/docs/html/guide/publishing/licensing.jd
deleted file mode 100644
index 609241b..0000000
--- a/docs/html/guide/publishing/licensing.jd
+++ /dev/null
@@ -1,2388 +0,0 @@
-page.title=Application Licensing
-@jd:body
-
-<div id="qv-wrapper">
-<div id="qv">
-
-  <h2>Quickview</h2>
-  <ul>
-    <li>Licensing lets you protect your application on any device that includes Android Market.</li>
-    <li>Your app maintains control of how it enforces its licensing status. </li>
-    <li>Adding licensing to an app is straightforward, using the library available through the SDK.</li>
-    <li>The service is free and is available to all developers who publish on Android Market. </li>
-  </ul>
-
-  <h2>In this document</h2>
-  <ol>
-    <li><a href="#account">Setting Up A Publisher Account</a></li>
-    <li><a href="#dev-setup">Setting Up the Development Environment</a></li>
-    <li><a href="#app-integration">Integrating the LVL with Your Application</a>
-    <ol>
-       <li><a href="#add-library">Including the LVL</a></li>
-       <li><a href="#manifest-permission">Adding the licensing permission</a></li>
-       <li><a href="#impl-Policy">Implementing a Policy</a></li>
-       <li><a href="#impl-Obfuscator">Implementing an Obfuscator</a></li>
-       <li><a href="#impl-lc">Checking the license</a></li>
-       <li><a href="#impl-DeviceLimiter">Implementing a DeviceLimiter</a></li>
-    </ol></li>
-    <li><a href="#test-env">Setting Up the Test Environment</a>
-    <ol>
-       <li><a href="#test-response">Test responses</a></li>
-       <li><a href="#test-acct-setup">Test accounts</a></li>
-       <li><a href="#acct-signin">Signing in on a device or emulator</a></li>
-    </ol></li>
-    <li><a href="#app-obfuscation">Obfuscating Your Application</a></li>
-    <li><a href="#app-publishing">Publishing a Licensed Application</a></li>
-    <li><a href="#support">Where to Get Support</a></li>
-  </ol>
-
-  <h2>Appendix</h2>
-  <ol>
-    <li><a href="#lvl-summary">Summary of LVL Classes and Interfaces</a></li>
-    <li><a href="#server-response-codes">Server Response Codes</a></li>
-    <li><a href="#extras">Server Response Extras</a></li>
-  </ol>
-
-</div>
-</div>
-
-<p>Android Market offers a licensing service that lets you enforce licensing
-policies for paid applications that you publish through Android Market. With
-Android Market Licensing, your applications can query Android Market at run time to
-obtain their licensing status for the current user, then allow or disallow
-further use as appropriate. </p>
-
-<p>Using the service, you can apply a flexible licensing policy on an
-application-by-application basis &mdash; each application can enforce licensing
-in the way most appropriate for it. If necessary, an application can apply custom
-constraints based on the licensing status obtained from Android Market.
-For example, an application can check the licensing status and then apply custom
-constraints that allow the user to run it unlicensed for a specific number
-of times, or for a specific validity period. An application can also restrict use of the
-application to a specific device, in addition to any other constraints. </p>
-
-<p>The licensing service is a secure means of controlling access to your
-applications. When an application checks the licensing status, the Market server
-signs the licensing status response using a key pair that is uniquely associated
-with the publisher account. Your application stores the public key in its
-compiled <code>.apk</code> file and uses it to verify the licensing status
-response.</p>
-
-<p>Any application that you publish through Android Market can use the Android
-Market Licensing service. No special account or registration is needed.
-Additionally, because the service uses no dedicated framework APIs, you can add
-licensing to any legacy application that uses a minimum API level of 3 or
-higher.</p>
-
-<p>To help you add licensing to your application, the Android SDK provides
-library sources that you can include in your application project. The
-License Verification Library (LVL) handles all of
-the licensing-related communication with the Android Market client and the
-licensing service. With the LVL integrated, your application can determine its
-licensing status for the current user by simply calling a library checker method
-and implementing a callback that receives the status.</p>
-
-<p>This document explains how the licensing service works and how to add it to
-your application. </p>
-
-
-<h2 id="overview">Overview</h2>
-
-<p>Android Market Licensing is a network-based service that lets an application
-on an Android-powered device query a trusted licensing server, to determine
-whether the application is licensed to the current device user. After receiving
-the server response, the application can then allow or disallow further use of
-the application as needed. In the service, the role of the licensing server is
-to provide the license status for the current user; the application itself is
-responsible for querying the server and conditionally granting access to the
-application. </p>
-
-<h4>Application, Android Market client, and server</h4>
-
-<p>The licensing service is based on the capability of the Android Market server
-to determine whether a given user is licensed to use a given application. The licensing server
-considers a user to be licensed if the user is a recorded purchaser of an application. If a paid
-application has been uploaded to Android Market but saved only as a draft application (in
-other words, the app is unpublished), the licensing server considers all users to be licensed users
-of the application. Keep in mind, you cannot implement Android Market Licensing in a free
-application.</p>
-
-<p>To properly identify
-the user and determine the license status, the server requires information about
-the application and user &mdash; the application and the Android Market client
-work together to assemble the information and pass it to the server. </p>
-
-<p>In the licensing service, an application does not query the licensing server
-directly, but instead calls the Android Market client over remote IPC to
-initiate a license request. In the license request:</p>
-
-<ul>
-<li>The application provides its package name and a nonce that is later used to
-validate any response from the server, as well as a callback over which the
-response can be returned asynchronously.</li>
-<li>The Android Market client, which has greater permissions than the
-application, collects the necessary information about the user and the device,
-such as the device's primary Google account username, IMSI, and other
-information. It then sends the license check request to the server on behalf of
-the application.</li>
-<li>The server evaluates the request using all available information, attempting
-to establish the user's identity to a sufficient level of confidence. The server
-then checks the user identity against purchase records for the application and
-returns a license response, which the Android Market client returns to the
-application over the IPC callback.</li>
-</ul>
-
-<p>Notice that during a license check, the application does not manage any
-network connections or use any licensing related APIs in the Android platform.
-</p>
-
-<div class="figure" style="width:469px">
-<img src="{@docRoot}images/licensing_arch.png" alt=""/>
-<p class="img-caption"><strong>Figure 1.</strong> Your application initiates a
-license check through the LVL and the Android Market
-client, which handles communication with the Market server.</p>
-</div>
-
-<h4>License responses secured through public key cryptography</h4>
-
-<p>To ensure the integrity of each license query, the server signs the license
-response data using an RSA key pair that is shared exclusively between the
-server and the application publisher.</p>
-
-<p>The licensing service generates a single licensing key pair for each
-publisher account and exposes the public key in the account's profile page. The
-publisher copies the public key and embeds it in the application source code,
-then compiles and publishes the <code>.apk.</code> The server retains the
-private key internally and uses it to sign license responses for applications
-published on that account. </p>
-
-<p>When the application receives a signed response, it uses the embedded public
-key to verify the data. The use of public key cryptography in the licensing
-service makes it possible for the application to detect responses that have been
-tampered with or that are spoofed.</p>
-
-<h4>Use of licensing in your application</h4>
-
-<p>To use licensing in your application, add code to the application to
-initiate a license check request and handle the response when it is received.
-You can choose when, and how often, you want your application to check its
-license and you have full control over how it handles the response, verifies the
-signed response data, and enforces access controls. </p>
-
-<p>To simplify the process of adding support for licensing, download and
-integrate the Licensing Verification Library, described below. Integration is
-straightforward.</p>
-
-<p>When you are finished integrating the LVL, use a test environment
-provided by the publisher site to test your application's handling of server
-responses. </p>
-
-<p>Finally, publish the application <code>.apk</code> on Market using the
-normal process. If you previously used the copy-protection provided by Android
-Market, you can remove it from applications that use licensing. </p>
-
-<h4>Licensing Verification Library simplifies implementation</h4>
-
-<p>The Android SDK includes a License Verification Library (LVL) that you can
-download and use as the basis for your application's licensing implementation.
-The LVL greatly simplifies the process of adding licensing to your application
-and helps ensure a more secure, robust implementation for your application. The
-LVL provides internal classes that handle most of the standard operations of a
-license query, such as contacting Android Market to initiate a license request
-and verifying and validating the responses. It also exposes key interfaces that
-let you easily plug in your custom code for defining licensing policy and
-managing access as needed by your application. The key LVL interfaces are: </p>
-
-<ul>
-<li>Policy &mdash; your implementation determines whether to allow access to the
-application, based on the license response received from the server and any
-other data available (such as from a backend server associated with your
-application). The implementation can evaluate the various fields of the license
-response and apply other constraints, if needed. The implementation also lets
-you manage the handling of license checks that result in errors, such as network
-errors.</li>
-<li>LicenseCheckerCallback &mdash; your implementation manages access to the
-application, based on the result of the Policy's handling of the license
-response. Your implementation can manage access in any way needed, including
-displaying the license result in the UI or directing the user to purchase the
-application (if not currently licensed). </li>
-</ul>
-
-<p>To help you get started with a Policy, the LVL provides two fully complete
-Policy implementations that you can use without modification or adapt to your
-needs:</p>
-
-<ul>
-<li><a href="#ServerManagedPolicy">ServerManagedPolicy</a> is a flexible Policy
-that uses settings provided by the licensing server to manage response caching
-and access to the application while the device is offline (such as when the
-user is on an airplane). For most applications, the use of
-ServerManagedPolicy is highly recommended. </li>
-<li><a href="#StrictPolicy">StrictPolicy</a> is a restrictive Policy that
-does not cache any response data and allows the application access <em>only</em>
-when the server returns a licensed response.</li>
-</ul>
-
-<p>The LVL is available as a downloadable component of the Android SDK. The
-component includes both the LVL itself and an example application that shows how
-the library should be integrated with your application and how your application
-should manage response data, UI interaction, and error conditions. </p>
-
-<p>The LVL sources are provided as an Android <em>library project</em>, which
-means that you can maintain a single set of library sources and share them
-across multiple applications. A full test environment is also available through
-the SDK, so you can develop and test the licensing implementation in your
-applications before publishing them, even if you don't have access to a
-physical device.</p>
-
-<h4>Requirements and limitations</h4>
-
-<p>Android Market Licensing is designed to let you apply license controls to
-applications that you publish through Android Market. The service is not
-designed to let you control access to applications that are not published
-through Android Market or that are run on devices that do not offer the Android
-Market client. </p>
-
-<p>Here are some points to keep in mind as you implement licensing in your
-application: </p>
-
-<ul>
-<li>Only paid applications published through Market can use the
-service.</li>
-<li>An application can use the service only if the Android Market client is
-installed on its host device and the device is running Android 1.5 (API level 3)
-or higher.</li>
-<li>To complete a license check, the licensing server must be accessible over
-the network. You can implement license caching behaviors to manage access when
-there is no network connectivity. </li>
-<li>The security of your application's licensing controls ultimately relies on
-the design of your implementation itself. The service provides the building
-blocks that let you securely check licensing, but the actual enforcement and
-handling of the license are factors in your control. By following the best
-practices in this document, you can help ensure that your implementation will be
-secure.</li>
-<li>Adding licensing to an application does not affect the way the application
-functions when run on a device that does not offer Android Market.</li>
-<li>Licensing is currently for paid apps only, since draft apps are
-licensed for all users. If your application is already published as a free app,
-you won't be able to upload a new version that uses licensing.</li>
-</ul>
-
-<h4>Replacement for Copy Protection</h4>
-
-<p>Android Market Licensing is a flexible, secure mechanism for controlling
-access to your applications. It effectively replaces the Copy Protection
-mechanism offered on Android Market and gives you wider distribution
-potential for your applications. </p>
-
-<ul>
-<li>A limitation of the legacy Copy Protection mechanism on Android Market is
-that applications using it can be installed only on compatible devices that
-provide a secure internal storage environment. For example, a copy-protected
-application cannot be downloaded from Market to a device that provides root
-access, and the application cannot be installed to a device's SD card. </li>
-<li>With Android Market licensing, you can move to a license-based model in
-which access is not bound to the characteristics of the host device, but to your
-publisher account on Android Market and the licensing policy that you define.
-Your application can be installed and controlled on any compatible device on
-any storage, including SD card.</li>
-</ul>
-
-<p>Although no license mechanism can completely prevent all unauthorized use,
-the licensing service lets you control access for most types of normal usage,
-across all compatible devices, locked or unlocked, that run Android 1.5 or
-higher version of the platform.</p>
-
-<p>The sections below describe how to add Android Market licensing to your
-applications. </p>
-
-<h2 id="account">Setting Up a Publisher Account</h2>
-
-<p>Android Market licensing lets you manage access to applications that
-users have downloaded from Android Market. To use licensing in an application,
-you need to have a publisher account on Android Market so that you can
-publish the application to users. </p>
-
-<p>If you don't already have a publisher account, you need to register for one
-using your Google account and agree to the terms of service. Once you are
-registered, you can upload applications at your convenience and begin debugging
-and testing your licensing implementation. For more information about publishing
-on Android Market, see <a
-href="{@docRoot}guide/publishing/publishing.html">Publishing Your
-Applications</a></p>
-
-<p>To register as an Android Market developer and set up your publisher account,
-visit the Android Market publisher site:</p>
-
-<p style="margin-left:2em;"><a
-href="http://market.android.com/publish">http://market.android.com/publish</a>
-</p>
-
-<p>If you already have a publisher account on Android Market, use your existing
-account to set up licensing. You <em>do not</em> need to register for a new
-account to support licensing (and doing so is not recommended, especially if you
-are adding licensing support to applications that you have already published).
-In all cases, if you have published applications, you manage licensing for those
-applications through the account on which the applications are published. </p>
-
-<p>Once your publisher account is set up, use the account to:</p>
-
-<ul>
-<li>Obtain a public key for licensing</li>
-<li>Debug and test an application's licensing implementation, prior to
-publishing the application</li>
-<li>Publish the applications to which you have added licensing support</li>
-</ul>
-
-<h4>Administrative settings for licensing</h4>
-
-<p>Once you are signed into your publisher account, you can manage several
-administrative controls for Android Market licensing. The controls are available
-in the Edit Profile page, in the "Licensing" panel, shown below. The controls
-let you: </p>
-
-<ul>
-<li>Set up multiple "test accounts", identified by email address. The licensing
-server allows users signed into test accounts on a device or emulator to send
-license checks and receive static test responses.</li>
-<li>Obtain the account's public key for licensing. When you are implementing
-licensing in an application, you must copy the public key string into the
-application.</li>
-<li>Configure static test responses that the server sends, when it receives a
-license check for an application uploaded to the publisher account, from a user
-signed in to the publisher account or a test account.</li>
-</ul>
-
-<div style="margin-bottom:2em;">
-
-<img src="{@docRoot}images/licensing_public_key.png" style="text-align:left;margin-bottom:0;" />
-<div style="margin:0 2em;padding:0"><strong>Figure 2.</strong> The Licensing
-panel of your account's Edit Profile page lets you manage administrative
-settings for licensing.</div>
-</div>
-
-<p>For more information about how to work with test accounts and static test
-responses, see <a href="#test-env">Setting Up a Testing Environment</a>, below.
-
-<h2 id="dev-setup">Setting Up the Development Environment</h2>
-
-<p>Once you've set up your publisher account on Android Market, the next step is
-to set up your development environment for licensing. </p>
-
-<p>Setting up your environment for licensing involves these tasks:</p>
-
-<ol>
-<li><a href="#download-sdk">Downloading the latest SDK</a>, if you haven't already done so </li>
-<li><a href="#runtime-setup">Setting up the runtime environment</a> for development</li>
-<li><a href="#download-lvl">Downloading the Market Licensing component</a> into your SDK </li>
-<li><a href="#lvl-setup">Setting up the Licensing Verification Library</a></li>
-<li><a href="#add-library">Including the LVL library project in your application</a></li>
-</ol>
-
-<p>The sections below describe these tasks. When you are done with setup,
-you can begin <a href="#app-integration">integrating the LVL into your applications</a>.</p>
-
-<p>To get started, you need to set up a proper runtime environment on which
-you can run, debug and test your application's implementation of license
-checking and enforcement. </p>
-
-
-<h3 id="download-sdk">Downloading the latest SDK</h3>
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>Licensing sample application</h2>
-
-<p>To work with Android Market licensing, you need a functioning Android
-application to which you can add licensing support. </p>
-
-<p style="margin-top:.5em;">If you are new to Android
-and don't yet have a functioning application, the LVL component includes a sample
-application that you can set up as a new application project. The sample provides
-a complete, working example of how licensing works. For more information, see <a
-href="#download-lvl">Downloading the LVL</a>.</p>
-
-</div>
-</div>
-
-<p>If you haven't done so, you need to download the Android SDK before you can
-develop Android applications. The SDK provides the tools that you need to build
-and debug Android applications, including applications that use Android Market
-licensing. For complete information, including installation instructions, see
-the <a href="{@docRoot}sdk/index.html">Android SDK</a>. </p>
-
-<p>If you have already installed the SDK, make sure to update the
-SDK tools and ADT Plugin to the latest versions. You can update the SDK tools
-using the Android SDK and AVD Manager and ADT through <strong>Help</strong> &gt;
-<strong>Software Updates...</strong> in Eclipse. </p>
-
-<p>After you've installed the latest SDK and tools, set up your development
-environment as described below. </p>
-
-
-<h3 id="runtime-setup">Setting up the runtime environment</h3>
-
-<p>As described earlier, applications check licensing status not by contacting
-the licensing server directly, but by binding to a service provided by the
-Android Market application and initiating a license check request. The Android
-Market service then handles the direct communication with the licensing server
-and finally routes the response back to your application. To debug and test
-licensing in your application, you need to set up a runtime environment that
-includes the necessary Android Market service, so that your application is able
-to send license check requests to the licensing server. </p>
-
-<p>There are two types of runtime environment that you can use: </p>
-
-<ul>
-<li>An Android-powered device that includes the Android Market application, or</li>
-<li>An Android emulator running the Google APIs Add-on, API level 8 (release 2)
-or higher</li>
-</ul>
-
-<p>The sections below provide more information. </p>
-
-<h4 id="runtime-device">Running on a device</h4>
-
-<p>You can use an Android-powered device as the runtime environment for
-debugging and testing licensing on your application.</p>
-
-<p>The device you use must:</p>
-
-<ul>
-<li>Run a standard version of the Android 1.5 or later (API level
-3 or higher) platform, <em>and</em> </li>
-<li>Run a system image on which the Android Market client application
-is preinstalled. </li>
-</ul>
-
-<p>If Android Market is not preinstalled in the system image, your application won't
-be able to communicate with the Android Market licensing server. </p>
-
-<p>For general information about how to set up a device for use in developing
-Android applications, see <a
-href="{@docRoot}guide/developing/device.html">Developing on a Device</a>.</p>
-
-<h4 id="runtime-emulator">Running on an Android emulator</h4>
-
-<p>You can also use an Android emulator as your runtime
-environment for debugging and testing licensing.</p>
-
-<p>Because the standard Android platforms provided in the Android SDK <em>do
-not</em> include Android Market, you need to download the Google APIs Add-On
-platform, API Level 8 (or higher), from the SDK repository. After downloading
-the add-on, you need to create an AVD configuration that uses that system image.
-</p>
-
-<p>The Google APIs Add-On does not include the full Android Market client.
-However, it does provide: </p>
-
-<ul>
-<li>An Android Market background service that implements the
-ILicensingService remote interface, so that your application can
-send license checks over the network to the licensing server. </li>
-<li>A set of underlying account services that let you add an a Google account on
-the AVD and sign in using your publisher account or test account credentials.
-Signing in using your publisher or test account enables you to debug and test
-your application without having publish it. For more information see <a
-href="#acct-signin">Signing in to an authorized account</a>, below.</li>
-</ul>
-
-<p>Several versions of the add-on are available in the SDK repository, but only
-<strong>Google APIs Add-On, API 8 (release 2) or higher</strong> version of the
-add-on includes the necessary Android Market services. This means that you
-cannot use Google APIs Add-On API 7 or lower as a runtime environment for
-developing licensing on an emulator.</p>
-
-<div style="margin-bottom:2em;">
-
-<img src="{@docRoot}images/licensing_gapis_8.png" style="text-align:left;margin-bottom:0;" />
-<div style="margin:0 2em;padding:0"><strong>Figure 3.</strong> Google APIs
-Add-On, API 8 (release 2) or higher lets you debug and test your licensing
-implementation in an emulator.</div>
-</div>
-
-<p>To set up an emulator for adding licensing to an application, follow
-these steps: </p>
-
-<ol>
-  <li>Launch the Android SDK and AVD Manager. </li>
-  <li>In the <strong>Available Packages</strong> panel, select and download the
-SDK component "Google APIs (Google Inc.) - API Level 8" (or higher) from the SDK
-repository, as shown in the figure above.
-  <p>When the download is complete, use the Android SDK and AVD Manager to
-create a new AVD based on that component, described next.</p></li>
-  <li>In the <strong>Virtual
-Devices</strong> panel of the Android SDK and AVD Manager, click
-<strong>New</strong> and set the configuration details for the new AVD. </li>
-  <li>In the dialog that appears, assign a descriptive name to the AVD and then
-use the "Target" menu to choose the "Google APIs (Google Inc.) - API Level 8" as
-the system image to run on the new AVD. Set the other configuration details as
-needed and then click <strong>Create AVD</strong> to finish. The SDK tools
-create the new AVD configuration, which then appears in the list of available
-Android Virtual Devices.</li>
-</ol>
-
-<p>If you are not familiar with AVDs or how to use them, see <a
-href="{@docRoot}guide/developing/devices/index.html">Managing Virtual Devices</a>.</p>
-
-<h4 id="project-update">Updating your project configuration</h4>
-
-<p>After you set up a runtime environment that meets the requirements described
-above &mdash; either on an actual device or on an emulator &mdash; make sure to
-update your application project or build scripts as needed, so that your compiled
-<code>.apk</code> files that use licensing are deployed into that environment.
-In particular, if you are developing in Eclipse, make sure that you set up a
-Run/Debug Configuration that targets the appropriate device or AVD. </p>
-
-<p>You do not need to make any changes to your application's
-build configuration, provided that the project is already configured to compile
-against a standard Android 1.5 (API level 3) or higher library. For example:
-
-<ul>
-<li>If you have an existing application that is compiled against
-the Android 1.5 library, you do not need to make any changes to your
-build configuration to support licensing. The build target meets the minimum
-requirements for licensing, so you would continue building
-against the same version of the Android platform.</li>
-
-<li>Similarly, if you are building against Android 1.5 (API level 3) but
-are using an emulator running the Google APIs Add-On API 8 as the application's
-runtime environment, there is no need to change your application's build
-configuration. </li>
-</ul>
-
-<p>In general, adding licensing to an application should have no impact
-whatsoever on the application's build configuration.</p>
-
-
-<h3 id="download-lvl">Downloading the LVL</h3>
-
-<p>The License Verification Library (LVL) is a collection of helper classes that
-greatly simplify the work that you need to do to add licensing to your
-application. In all cases, we recommend that you download the LVL and use it as
-the basis for the licensing implementation in your application.</p>
-
-<p>The LVL is available as a downloadable component of the Android SDK. The
-component includes: </p>
-
-<ul>
-<li>The LVL sources, stored inside an Android library project. </li>
-<li>An example application called "sample" that depends on the LVL library
-project. The example illustrates how an application uses the library helper
-classes to check and enforce licensing.</li>
-</ul>
-
-<p>To download the LVL component into your development environment, use the
-Android SDK and AVD Manager. Launch the Android SDK and AVD Manager and then
-select the "Market Licensing" component, as shown in the figure below.
-Accept the terms and click <strong>Install Selected</strong> to begin the download. </p>
-
-<div style="margin-bottom:2em;">
-
-<img src="{@docRoot}images/licensing_package.png" style="text-align:left;margin-bottom:0;" />
-<div style="margin:0 2em;padding:0"><strong>Figure 4.</strong> The Market
-Licensing package contains the LVL and the LVL sample application. </div>
-</div>
-
-<p>When the download is complete, the Android SDK and AVD Manager installs both
-the LVL library project and the example application into these directories: </p>
-
-<p style="margin-left:2em"><code>&lt;<em>sdk</em>&gt;/extras/google/market_licensing/library/</code>
-&nbsp;&nbsp;(the LVL library project)<br />
-<code>&lt;<em>sdk</em>&gt;/extras/google/market_licensing/sample/</code>&nbsp;&nbsp;(the example
-application)</p>
-
-<p>If you aren't familiar with how to download components into your SDK, see the
-<a href="{@docRoot}sdk/adding-components.html">Adding SDK Components</a>
-document. </p>
-
-
-<h3 id="lvl-setup">Setting Up the Licensing Verification Library</h3>
-
-<p>After downloading the LVL to your computer, you need to set it up in your
-development environment, either as an Android library project or by
-copying (or importing) the library sources directly into your existing
-application package. In general, using the LVL as a library project is recommended,
-since it lets you reuse your licensing code across multiple applications and
-maintain it more easily over time. Note that the LVL is not designed to be
-compiled separately and added to an application as a static .jar file. </p>
-
-<h4>Moving the library sources to a new location</h4>
-
-<p>Because you will be customizing the LVL sources to some extent, you should
-make sure to <em>move or copy</em> the library sources (the entire
-directory at <code>&lt;<em>sdk</em>&gt;/market_licensing/library/</code>)
-to a working directory outside of the SDK. You should then use the relocated
-sources as your working set. If you are using a source-code management
-system, add and track the sources that are in the working location rather
-than those in default location in the SDK. </p>
-
-<p>Moving the library sources is important is because, when you later update the
-Market licensing package, the SDK installs the new files to the same location as
-the older files. Moving your working library files to a safe location ensures
-that your work won't be inadvertently overwritten should you download a new
-version of the LVL.</p>
-
-<h4>Creating the LVL as a library project</h4>
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>Working with library projects</h2>
-
-<p>The LVL is provided as an Android library project, which means that you can
-share its code and resources across multiple applications. </p>
-
-<p style="margin-top:.5em;">If you aren't familiar with library projects or how
-to use them, see <a href="{@docRoot}guide/developing/projects/index.html#LibraryProjects">
-Managing Projects</a>.
-</p>
-</div>
-</div>
-
-<p>The recommended way of using the LVL is setting it up as a new Android
-<em>library project</em>. A library project is a type of development project
-that holds shared Android source code and resources. Other Android application
-projects can reference the library project and, at build time, include its
-compiled sources in their <code>.apk</code> files. In the context of licensing,
-this means that you can do most of your licensing development once, in a library
-project, then include the library sources in your various application projects.
-In this way, you can easily maintain a uniform implementation of licensing
-across all of your projects and maintain it centrally. </p>
-
-<p>The LVL is provided as a configured library project &mdash; once you have
-downloaded it, you can start using it right away. </p>
-
-<p>If you are working in Eclipse with ADT, you need to add the LVL to your
-workspace as a new development project, in the same way as you would a new
-application project. </p>
-
-<ol>
-<li>Use the New Project Wizard to create a new
-project from existing sources. Select the LVL's <code>library</code> directory
-(the directory containing the library's AndroidManifest.xml file) as the project
-root.</li>
-<li>When you are creating the library project, you can select any application
-name, package, and set other fields as needed. </li>
-<li>For the library's build target, select Android 1.5 (API level 3) or higher.</li>
-</ol>
-
-<p> When created, the project is
-predefined as a library project in its <code>project.properties</code> file, so
-no further configuration is needed. </p>
-
-<p>For more information about how to create an application project or work with
-library projects in Eclipse, see <a
-href="{@docRoot}guide/developing/projects/projects-eclipse.html">Managing Projects from
-Eclipse with ADT</a></p>.
-
-<h4>Copying the LVL sources to your application</h4>
-
-<p>As an alternative to adding the LVL as a library project, you can copy the
-library sources directly into your application. To do so, copy (or import) the
-LVL's <code>library/src/com</code> directory into your application's
-<code>src/</code> directory.</p>
-
-<p>If you add the LVL sources directly to your application, you can skip the
-next section and start working with the library, as described in <a
-href="#app-integration"></a>.</p>
-
-
-<h3 id="add-library">Including the LVL library project sources in your
-application</h3>
-
-<p>If you want to use the LVL sources as a library project, you need to add a
-reference to the LVL library project in your application project properties. This tells
-build tools to include the LVL library project sources in your application at
-compile time. The process for adding a reference to a library project depends
-on your development environment, as described below.</p>
-
-<p> If you are developing in Eclipse with ADT, you should already have added the
-library project to your workspace, as described in the previous section. If you
-haven't done that already, do it now before continuing. </p>
-
-<p>Next, open the application's project properties window, as shown below.
-Select the "Android" properties group and click <strong>Add</strong>, then
-choose the LVL library project (com_android_vending_licensing) and click
-<strong>OK</strong>. For more information, see
-<a href="{@docRoot}guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject">
-Managing Projects from Eclipse with ADT</a></p>.
-
-<div style="margin-bottom:2em;">
-
-<img src="{@docRoot}images/licensing_add_library.png" style="text-align:left;margin-bottom:0;" />
-<div style="margin:0 2em;padding:0"><strong>Figure 5.</strong> If you are
-working in Eclipse with ADT, you can add the LVL library project to your
-application from the application's project properties.</div>
-</div>
-
-<p>If you are developing using the SDK command-line tools, navigate to the
-directory containing your application project and open the
-<code>project.properties</code> file. Add a line to the file that specifies the
-<code>android.library.reference.&lt;n&gt;</code> key and the path to the
-library. For example: </p>
-
-<pre>android.library.reference.1=path/to/library_project</pre>
-
-<p>Alternatively, you can use this command to update the project
-properties, including the reference to the library project:</p>
-
-<pre class="no-pretty-print" style="color:black">android update lib-project
---target <em>&lt;target_ID&gt;</em> \
---path <em>path/to/my/app_project</em> \
---library <em>path/to/my/library_project</em>
-</pre>
-
-<p>For more information about working with library projects,
-see <a href="{@docRoot}guide/developing/projects/projects-cmdline.html#SettingUpLibraryProject">
-Managing Projects from the Command Line</a></p>.
-
-
-<h2 id="app-integration">Integrating the LVL with Your Application</h2>
-
-<p>Once you've followed the steps above to set up a publisher account and
-development environment, you are ready to begin integrating the LVL with your
-application. </p>
-
-<p>Integrating the LVL with your application code involves these tasks:</p>
-
-<ol>
-<li><a href="#manifest-permission">Adding the licensing permission</a> your application's manifest.</li>
-<li><a href="#impl-Policy">Implementing a Policy</a> &mdash; you can choose one of the full implementations provided in the LVL or create your own.</li>
-<li><a href="#impl-Obfuscator">Implementing an Obfuscator</a>, if your Policy will cache any license response data. </li>
-<li><a href="#impl-lc">Adding code to check the license</a> in your application's main Activity</li>
-<li><a href="#impl-DeviceLimiter">Implementing a DeviceLimiter</a> (optional and not recommended for most applications)</li>
-</ol>
-
-<p>The sections below describe these tasks. When you are done with the
-integration, you should be able to compile your application successfully and you
-can begin testing, as described in <a href="#test-env">Setting Up the Test
-Environment</a>.</p>
-
-<p>For an overview of the full set of source files included in the LVL, see <a
-href="#lvl-summary">Summary of LVL Classes and Interfaces</a>.</p>
-
-
-<h3 id="manifest-permission">Adding the licensing permission to your
-AndroidManifest.xml</h3>
-
-<p>To use the Android Market application for sending a license check to the
-server, your application must request the proper permission,
-<code>com.android.vending.CHECK_LICENSE</code>. If your application does
-not declare the licensing permission but attempts to initiate a license check,
-the LVL throws a security exception.</p>
-
-<p>To request the licensing permission in your application, declare a <a
-href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><code>&lt;uses-permission&gt;</code></a>
-element as a child of <code>&lt;manifest&gt;</code>, as follows: </p>
-
-<p style="margin-left:2em;"><code>&lt;uses-permission
-android:name="com.android.vending.CHECK_LICENSE"&gt;</code></p>
-
-<p>For example, here's how the LVL sample application declares the permission:
-</p>
-
-<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
-
-&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" ..."&gt;
-    &lt;!-- Devices &gt;= 3 have version of Android Market that supports licensing. --&gt;
-    &lt;uses-sdk android:minSdkVersion="3" /&gt;
-    &lt;!-- Required permission to check licensing. --&gt;
-    &lt;uses-permission android:name="com.android.vending.CHECK_LICENSE" /&gt;
-    ...
-&lt;/manifest&gt;
-</pre>
-
-<p class="note"><strong>Note:</strong> Currently, you cannot declare the
-<code>CHECK_LICENSE</code> permission in the LVL library project's manifest,
-because the SDK Tools will not merge it into the manifests of dependent
-applications. Instead, you must declare the permission in each dependent
-application's manifest. </p>
-
-
-<h3 id="impl-Policy">Implementing a Policy</h3>
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>ServerManagedPolicy</h2>
-
-<p>The LVL includes a complete Policy implementation called ServerManagedPolicy
-that makes use of license-management settings provided by the Android Market
-server. </p>
-
-<p style="margin-top:.5em;">Use of ServerManagedPolicy as the basis for your
-Policy is strongly recommended. For more information, see <a
-href="#ServerManagedPolicy">ServerManagedPolicy</a> section, below.</p>
-
-</div>
-</div>
-
-<p>Android Market licensing service does not itself determine whether a
-given user with a given license should be granted access to your application.
-Rather, that responsibility is left to a Policy implementation that you provide
-in your application.</p>
-
-<p>Policy is an interface declared by the LVL that is designed to hold your
-application's logic for allowing or disallowing user access, based on the result
-of a license check. To use the LVL, your application <em>must</em> provide an
-implementation of Policy. </p>
-
-<p>The Policy interface declares two methods, <code>allowAccess()</code> and
-<code>processServerResponse()</code>, which are called by a LicenseChecker
-instance when processing a response from the license server. It also declares an
-enum called <code>LicenseResponse</code>, which specifies the license response
-value passed in calls to <code>processServerResponse()</code>. </p>
-
-<ul>
-<li><code>processServerResponse()</code> lets you preprocess the raw response
-data received from the licensing server, prior to determining whether to grant
-access.
-
-<p>A typical implementation would extract some or all fields from the license
-response and store the data locally to a persistent store, such as through
-{@link android.content.SharedPreferences} storage, to ensure that the data is
-accessible across application invocations and device power cycles. For example,
-a Policy would maintain the timestamp of last successful license check, the
-retry count, the license validity period, and similar information in a
-persistent store, rather than resetting the values each time the application is
-launched.</p>
-
-<p>When storing response data locally, the Policy must ensure that the data is
-obfuscated (see <a href="#impl-Obfuscator">Implementing an Obfuscator</a>,
-below).</p></li>
-
-<li><code>allowAccess()</code> determines whether to grant the user access to
-your application, based on any available license response data (from the
-licensing server or from cache) or other application-specific information.  For
-example, your implementation of <code>allowAccess()</code> could take into
-account additional criteria, such as usage or other data retrieved from a
-backend server. In all cases, an implementation of <code>allowAccess()</code>
-should only return <code>true</code> if the user is licensed to use the
-application, as determined by the licensing server, or if there is a transient
-network or system problem that prevents the license check from completing. In
-such cases, your implementation can maintain a count of retry responses and
-provisionally allow access until the next license check is complete.</li>
-
-</ul>
-
-<p>To simplify the process of adding licensing to your application and to
-provide an illustration of how a Policy should be designed, the LVL includes
-two full Policy implementations that you can use without modification or
-adapt to your needs:</p>
-
-<ul>
-<li><a href="#ServerManagedPolicy">ServerManagedPolicy</a>, a flexible Policy
-that uses server-provided settings and cached responses to manage access across
-varied network conditions, and</li>
-<li><a href="#StrictPolicy">StrictPolicy</a>, which does not cache any response
-data and allows access <em>only</em> if the server returns a licensed
-response.</li>
-</ul>
-
-<p>For most applications, the use of ServerManagedPolicy is highly
-recommended. ServerManagedPolicy is the LVL default and is integrated with
-the LVL sample application.</p>
-
-
-<h4 id="custom-policies">Guidelines for custom policies</h4>
-
-<p>In your licensing implementation, you can use one of the complete policies
-provided in the LVL (ServerManagedPolicy or StrictPolicy) or you can create a
-custom policy. For any type of custom policy, there are several important design
-points to understand and account for in your implementation.</p>
-
-<p>The licensing server applies general request limits to guard against overuse
-of resources that could result in denial of service. When an application exceeds
-the request limit, the licensing server returns a 503 response, which gets
-passed through to your application as a general server error. This means that no
-license response will be available to the user until the limit is reset, which
-can affect the user for an indefinite period.</p>
-
-<p>If you are designing a custom policy, we recommend that the Policy:
-<ol>
-<!-- <li>Limits the number of points at which your app calls for a license check
-to the minimum. </li> -->
-<li>Caches (and properly obfuscates) the most recent successful license response
-in local persistent storage.</li>
-<li>Returns the cached response for all license checks, for as long as the
-cached response is valid, rather than making a request to the licensing server.
-Setting the response validity according to the server-provided <code>VT</code>
-extra is highly recommended. See <a href="#extras">Server Response Extras</a>
-for more information.</li>
-<li>Uses an exponential backoff period, if retrying any requests the result in
-errors. Note that the Android Market client automatically retries failed
-requests, so in most cases there is no need for your Policy to retry them.</li>
-<li>Provides for a "grace period" that allows the user to access your
-application for a limited time or number of uses, while a license check is being
-retried. The grace period benefits the user by allowing access until the next
-license check can be completed successfully and it benefits you by placing a
-hard limit on access to your application when there is no valid license response
-available.</li>
-</ol>
-
-<p>Designing your Policy according to the guidelines listed above is critical,
-because it ensures the best possible experience for users while giving you
-effective control over your application even in error conditions. </p>
-
-<p>Note that any Policy can use settings provided by the licensing server to
-help manage validity and caching, retry grace period, and more. Extracting the
-server-provided settings is straightforward and making use of them is highly
-recommended. See the ServerManagedPolicy implementation for an example of how to
-extract and use the extras. For a list of server settings and information about
-how to use them, see  <a href="#extras">Server Response Extras</a> in the
-Appendix of this document.</p>
-
-<h4 id="ServerManagedPolicy">ServerManagedPolicy</h4>
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>Server Response Extras</h2>
-
-<p>For certain types of licensing responses, the licensing server appends extra
-settings to the responses, to help the application manage licensing effectively.
-</p>
-
-<p style="margin-top:.5em;">See <a href="#extras">Server Response Extras</a> for
-a list of settings and <code>ServerManagedPolicy.java</code> for information
-about how a Policy can use the extras.</p>
-
-</div>
-</div>
-
-<p>The LVL includes a full and recommended implementation of the Policy
-interface called ServerManagedPolicy. The implementation is integrated with the
-LVL classes and serves as the default Policy in the library. </p>
-
-<p>ServerManagedPolicy provides all of the handling for license and retry
-responses. It caches all of the response data locally in a
-{@link android.content.SharedPreferences} file, obfuscating it with the
-application's Obfuscator implementation. This ensures that the license response
-data is secure and persists across device power cycles. ServerManagedPolicy
-provides concrete implementations of the interface methods
-<code>processServerResponse()</code> and <code>allowAccess()</code> and also
-includes a set of supporting methods and types for managing license
-responses.</p>
-
-<p>Importantly, a key feature of ServerMangedPolicy is its use of
-server-provided settings as the basis for managing licensing across an
-application's refund period and through varying network and error conditions.
-When an application contacts the Android Market server for a license check, the
-server appends several settings as key-value pairs in the extras field of certain
-license response types. For example, the server provides recommended values for the
-application's license validity period, retry grace period, and maximum allowable
-retry count, among others. ServerManagedPolicy extracts the values from the
-license response in its <code>processServerResponse()</code> method and checks
-them in its <code>allowAccess()</code> method. For a list of the server-provided
-settings used by ServerManagedPolicy, see <a href="#extras">Server Response
-Extras</a> in the Appendix of this document.</p>
-
-<p>For convenience, best performance, and the benefit of using license settings
-from the Android Market server, <strong>using ServerManagedPolicy as your
-licensing Policy is strongly recommended</strong>. </p>
-
-<p>If you are concerned about the security of license response data that is
-stored locally in SharedPreferences, you can use a stronger obfuscation
-algorithm or design a stricter Policy that does not store license data. The LVL
-includes an example of such a Policy &mdash; see <a
-href="#StrictPolicy">StrictPolicy</a> for more information.</p>
-
-<p>To use ServerManagedPolicy, simply import it to your Activity, create an
-instance, and pass a reference to the instance when constructing your
-LicenseChecker. See <a href="#lc-lcc">Instantiate LicenseChecker and
-LicenseCheckerCallback</a> for more information. </p>
-
-<h4 id="StrictPolicy">StrictPolicy</h4>
-
-<p>The LVL includes an alternative full implementation of the Policy interface
-called StrictPolicy. The StrictPolicy implementation provides a more restrictive
-Policy than ServerManagedPolicy, in that it does not allow the user to access
-the application unless a license response is received from the server at the
-time of access that indicates that the user is licensed.</p>
-
-<p>The principal feature of StrictPolicy is that it does not store <em>any</em>
-license response data locally, in a persistent store. Because no data is stored,
-retry requests are not tracked and cached responses can not be used to fulfill
-license checks. The Policy allows access only if:</p>
-
-<ul>
-<li>The license response is received from the licensing server, and </li>
-<li>The license response indicates that the user is licensed to access the
-application. </li>
-</ul>
-
-<p>Using StrictPolicy is appropriate if your primary concern is to ensure that,
-in all possible cases, no user will be allowed to access the application unless
-the user is confirmed to be licensed at the time of use. Additionally, the
-Policy offers slightly more security than ServerManagedPolicy &mdash; since
-there is no data cached locally, there is no way a malicious user could tamper
-with the cached data and obtain access to the application.</p>
-
-<p>At the same time, this Policy presents a challenge for normal users, since it
-means that they won't be able to access the application when there is no network
-(cell or wi-fi) connection available. Another side-effect is that your
-application will send more license check requests to the server, since using a
-cached response is not possible.</p>
-
-<p>Overall, this policy represents a tradeoff of some degree of user convenience
-for absolute security and control over access. Consider the tradeoff carefully
-before using this Policy.</p>
-
-<p>To use StrictPolicy, simply import it to your Activity, create an instance,
-and pass a reference to it when constructing your LicenseChecker. See
-<a href="#lc-lcc">Instantiate LicenseChecker and LicenseCheckerCallback</a>
-for more information. </p>
-
-<h3 id="impl-Obfuscator">Implementing an Obfuscator</h3>
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>AESObfuscator</h2>
-
-<p>The LVL includes a full Obfuscator implementation in the
-<code>AESObfuscator.java</code> file. The Obfuscator uses AES encryption to
-obfuscate/unobfuscate data. If you are using a Policy (such as
-ServerManagedPolicy) that caches license response data, using AESObfuscator as
-basis for your Obfuscator implementation is highly recommended. </p>
-
-</div>
-</div>
-
-<p>A typical Policy implementation needs to save the license response data for
-an application to a persistent store, so that it is accessible across
-application invocations and device power cycles.  For example, a Policy would
-maintain the timestamp of the last successful license check, the retry count,
-the license validity period, and similar information in a persistent store,
-rather than resetting the values each time the application is launched. The
-default Policy included in the LVL, ServerManagedPolicy, stores license response
-data in a {@link android.content.SharedPreferences} instance, to ensure that the
-data is persistent. </p>
-
-<p>Because the Policy will use stored license response data to determine whether
-to allow or disallow access to the application, it <em>must</em> ensure that any
-stored data is secure and cannot be reused or manipulated by a root user on a
-device. Specifically, the Policy must always obfuscate the data before storing
-it, using a key that is unique for the application and device. Obfuscating using
-a key that is both application-specific and device-specific is critical, because
-it prevents the obfuscated data from being shared among applications and
-devices.</p>
-
-<p>The LVL assists the application with storing its license response data in a
-secure, persistent manner. First, it provides an Obfuscator
-interface that lets your application supply the obfuscation algorithm of its
-choice for stored data. Building on that, the LVL provides the helper class
-PreferenceObfuscator, which handles most of the work of calling the
-application's Obfuscator class and reading and writing the obfuscated data in a
-SharedPreferences instance. </p>
-
-<p>The LVL provides a full Obfuscator implementation called
-AESObfuscator that uses AES encryption to obfuscate data. You can
-use AESObfuscator in your application without modification or you
-can adapt it to your needs. For more information, see the next section.</p>
-
-
-<h4 id="AESObfuscator">AESObfuscator</h4>
-
-<p>The LVL includes a full and recommended implementation of the Obfuscator
-interface called AESObfuscator. The implementation is integrated with the
-LVL sample application and serves as the default Obfuscator in the library. </p>
-
-<p>AESObfuscator provides secure obfuscation of data by using AES to
-encrypt and decrypt the data as it is written to or read from storage.
-The Obfuscator seeds the encryption using three data fields provided
-by the application: </p>
-
-<ol>
-<li>A salt &mdash; an array of random bytes to use for each (un)obfuscation. </li>
-<li>An application identifier string, typically the package name of the application.</li>
-<li>A device identifier string, derived from as many device-specific sources
-as possible, so as to make it as unique.</li>
-</ol>
-
-<p>To use AESObfuscator, first import it to your Activity. Declare a private
-static final array to hold the salt bytes and initialize it to 20 randomly
-generated bytes.</p>
-
-<pre>    ...
-    // Generate 20 random bytes, and put them here.
-    private static final byte[] SALT = new byte[] {
-     -46, 65, 30, -128, -103, -57, 74, -64, 51, 88, -95,
-     -45, 77, -117, -36, -113, -11, 32, -64, 89
-     };
-    ...
-</pre>
-
-<p>Next, declare a variable to hold a device identifier and generate a value for
-it in any way needed. For example, the sample application included in the LVL
-queries the system settings for the
-<code>android.Settings.Secure.ANDROID_ID</code>, which is unique to each device.
-</p>
-
-<p>Note that, depending on the APIs you use, your application might need to
-request additional permissions in order to acquire device-specific information.
-For example, to query the {@link android.telephony.TelephonyManager} to obtain
-the device IMEI or related data, the application will also need to request the
-<code>android.permission.READ_PHONE_STATE</code> permission in its manifest.</p>
-
-<p>Before requesting new permissions for the <em>sole purpose</em> of acquiring
-device-specific information for use in your Obfuscator, consider
-how doing so might affect your application or its filtering on Android Market
-(since some permissions can cause the SDK build tools to add
-the associated <code>&lt;uses-feature&gt;</code>).</p>
-
-<p>Finally, construct an instance of AESObfuscator, passing the salt,
-application identifier, and device identifier. You can construct the instance
-directly, while constructing your Policy and LicenseChecker. For example:</p>
-
-<pre>    ...
-    // Construct the LicenseChecker with a Policy.
-    mChecker = new LicenseChecker(
-        this, new ServerManagedPolicy(this,
-            new AESObfuscator(SALT, getPackageName(), deviceId)),
-        BASE64_PUBLIC_KEY  // Your public licensing key.
-        );
-    ...
-</pre>
-
-<p>For a complete example, see MainActivity in the LVL sample application.</p>
-
-
-<h3 id="impl-lc">Checking the license from your application's main Activity</h3>
-
-<p>Once you've implemented a Policy for managing access to your application, the
-next step is to add a license check to your application, which initiates a query
-to the licensing server if needed and manages access to the application based on
-the license response. All of the work of adding the license check and handling
-the response takes place in your main {@link android.app.Activity} source file.
-</p>
-
-<p>To add the license check and handle the response, you must:</p>
-
-<ol>
-    <li><a href="#imports">Add imports</a></li>
-    <li><a href="#lc-impl">Implement LicenseCheckerCallback</a> as a private inner class</li>
-    <li><a href="#thread-handler">Create a Handler</a> for posting from LicenseCheckerCallback to the UI thread</li>
-    <li><a href="#lc-lcc">Instantiate LicenseChecker</a> and LicenseCheckerCallback</li>
-    <li><a href="#check-access">Call checkAccess()</a> to initiate the license check</li>
-    <li><a href="#account-key">Embed your public key</a> for licensing</li>
-    <li><a href="#handler-cleanup">Call your LicenseChecker's onDestroy() method</a> to close IPC connections.</li>
-</ol>
-
-<p>The sections below describe these tasks. </p>
-
-<h4 id="lc-overview">Overview of license check and response</h4>
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>Example: MainActivity</h2>
-
-<p>The sample application included with the LVL provides a full example of how
-to initiate a license check and handle the result, in the
-<code>MainActivity.java</code> file.</p>
-
-</div>
-</div>
-
-<p>In most cases, you should add the license check to your application's main
-{@link android.app.Activity}, in the <code>onCreate()</code> method. This
-ensures that when the user launches your application directly, the license check
-will be invoked immediately. In some cases, you can add license checks in other
-locations as well. For example, if your application includes multiple Activity
-components that other applications can start by {@link android.content.Intent},
-you could add license checks in those Activities.</p>
-
-<p>A license check consists of two main actions: </p>
-
-<ul>
-<li>A call to a method to initiate the license check &mdash; in the LVL, this is
-a call to the <code>checkAccess()</code> method of a LicenseChecker object that
-you construct.</li>
-<li>A callback that returns the result of the license check. In the LVL, this is
-a <code>LicenseCheckerCallback</code> interface that you implement. The
-interface declares two methods, <code>allow()</code> and
-<code>dontAllow()</code>, which are invoked by the library based on to the
-result of the license check. You implement those two methods with whatever logic
-you need, to allow or disallow the user access to your application. Note that
-these methods do not determine <em>whether</em> to allow access &mdash; that
-determination is the responsibility of your Policy implementation. Rather, these
-methods simply provide the application behaviors for <em>how</em> to allow and
-disallow access (and handle application errors).</li>
-</ul>
-
-<div style="margin-bottom:2em;">
-
-<img src="{@docRoot}images/licensing_flow.png" style="text-align:left;margin-bottom:0;margin-left:3em;" />
-<div style="margin:.5em 0 1.5em 2em;padding:0"><strong>Figure 6.</strong> Overview of a
-typical license check interaction.</div>
-</div>
-
-<p>The diagram above illustrates how a typical license check takes place: </p>
-
-<ol>
-<li>Code in the application's main Activity instantiates LicenseCheckerCallback
-and LicenseChecker objects. When constructing LicenseChecker, the code passes in
-{@link android.content.Context}, a Policy implementation to use, and the
-publisher account's public key for licensing as parameters. </li>
-<li>The code then calls the <code>checkAccess()</code> method on the
-LicenseChecker object. The method implementation calls the Policy to determine
-whether there is a valid license response cached locally, in
-{@link android.content.SharedPreferences}.
-<ul>
-<li>If so, the <code>checkAccess()</code> implementation calls
-<code>allow()</code>.</li>
-<li>Otherwise, the LicenseChecker initiates a license check request that is sent
-to the licensing server.</li>
-</ul>
-<p class="note"><strong>Note:</strong> The licensing server always returns
-<code>LICENSED</code> when you perform a license check of a draft application.</p>
-</li>
-<li>When a response is received, LicenseChecker creates a LicenseValidator that
-verifies the signed license data and extracts the fields of the response, then
-passes them to your Policy for further evaluation.
-  <ul>
-    <li>If the license is valid, the Policy caches the response in
-SharedPreferences and notifies the validator, which then calls the
-<code>allow()</code> method on the LicenseCheckerCallback object. </li>
-    <li>If the license not valid, the Policy notifies the validator, which calls
-the <code>dontAllow()</code> method on LicenseCheckerCallback. </li>
-  </ul>
-</li>
-<li>In case of a recoverable local or server error, such as when the network is
-not available to send the request, LicenseChecker passes a RETRY response to
-your Policy's <code>processServerResponse()</code> method. </li>
-<li>In case of a application error, such as when the application attempts to
-check the license of an invalid package name, LicenseChecker passes an error
-response to the LicenseCheckerCallback's  <code>applicationError()</code>
-method. </li>
-</ol>
-
-<p>Note that, in addition to initiating the license check and handling the
-result, which are described in the sections below, your application also needs
-to provide a <a href="#impl-Policy">Policy implementation</a> and, if the Policy
-stores response data (such as ServerManagedPolicy), an <a
-href="#impl-Obfuscator">Obfuscator</a> implementation. </p>
-
-
-<h4 id="imports">Add imports</h4>
-
-<p>First, open the class file of the application's main Activity and import
-LicenseChecker and LicenseCheckerCallback from the LVL package.</p>
-
-<pre>    import com.android.vending.licensing.LicenseChecker;
-    import com.android.vending.licensing.LicenseCheckerCallback;</pre>
-
-<p>If you are using the default Policy implementation provided with the LVL,
-ServerManagedPolicy, import it also, together with the AESObfuscator. If you are
-using a custom Policy or Obfuscator, import those instead. </p>
-
-<pre>    import com.android.vending.licensing.ServerManagedPolicy;
-    import com.android.vending.licensing.AESObfuscator;</pre>
-
-<h4 id="lc-impl">Implement LicenseCheckerCallback as a private inner class</h4>
-
-<p>LicenseCheckerCallback is an interface provided by the LVL for handling
-result of a license check. To support licensing using the LVL, you must
-implement LicenseCheckerCallback and
-its methods to allow or disallow access to the application.</p>
-
-<p>The result of a license check is always a call to one of the
-LicenseCheckerCallback methods, made based on the validation of the response
-payload, the server response code itself, and any additional processing provided
-by your Policy. Your application can implement the methods in any way needed. In
-general, it's best to keep the methods simple, limiting them to managing UI
-state and application access. If you want to add further processing of license
-responses, such as by contacting a backend server or applying custom constraints,
-you should consider incorporating that code into your Policy, rather than
-putting it in the LicenseCheckerCallback methods. </p>
-
-<p>In most cases, you should declare your implementation of
-LicenseCheckerCallback as a private class inside your application's main
-Activity class. </p>
-
-<p>Implement the <code>allow()</code> and <code>dontAllow()</code> methods as
-needed. To start with, you can use simple result-handling behaviors in the
-methods, such as displaying the license result in a dialog. This helps you get
-your application running sooner and can assist with debugging. Later, after you
-have determined the exact behaviors you want, you can add more complex handling.
-</p>
-
-<p>Some suggestions for handling unlicensed responses in
-<code>dontAllow()</code> include: </p>
-
-<ul>
-<li>Display a "Try again" dialog to the user, including a button to initiate a
-new license check. </li>
-<li>Display a "Purchase this application" dialog, including a button that
-deep-links the user to the application's details page on Market, from which the
-use can purchase the application. For more information on how to set up such
-links, see <a
-href="{@docRoot}guide/publishing/publishing.html#marketintent">Using Intents to
-Launch the Market Application on a Device</a>. </li>
-<li>Display a Toast notification that indicates that the features of the
-application are limited because it is not licensed. </li>
-</ul>
-
-<p>The example below shows how the LVL sample application implements
-LicenseCheckerCallback, with methods that display the license check result in a
-dialog. </p>
-
-<pre>    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
-        public void allow() {
-            if (isFinishing()) {
-                // Don't update UI if Activity is finishing.
-                return;
-            }
-            // Should allow user access.
-            displayResult(getString(R.string.allow));
-        }
-
-        public void dontAllow() {
-            if (isFinishing()) {
-                // Don't update UI if Activity is finishing.
-                return;
-            }
-            displayResult(getString(R.string.dont_allow));
-            // Should not allow access. An app can handle as needed,
-            // typically by informing the user that the app is not licensed
-            // and then shutting down the app or limiting the user to a
-            // restricted set of features.
-            // In this example, we show a dialog that takes the user to Market.
-            showDialog(0);
-        }
-    }
-</pre>
-
-<p>Additionally, you should implement the <code>applicationError()</code>
-method, which the LVL calls to let your application handle errors that are not
-retryable. For a list of such errors, see <a
-href="#server-response-codes">Server Response Codes</a> in the Appendix of this
-document. You can implement the method in any way needed. In most cases, the
-method should log the error code and call <code>dontAllow()</code>.</p>
-
-<h4 id="thread-handler">Create a Handler for posting from LicenseCheckerCallback
-to the UI thread</h4>
-
-<p>During a license check, the LVL passes the request to the Android Market
-application, which handles communication with the licensing server. The LVL
-passes the request over asynchronous IPC (using {@link android.os.Binder}) so
-the actual processing and network communication do not take place on a thread
-managed by your application. Similarly, when the Android Market application
-receives the result, it invokes a  callback method over IPC, which in turn
-executes in an IPC thread pool in your application's process.</p>
-
-<p>The LicenseChecker class manages your application's IPC communication with
-the Android Market application, including the call that sends the request and
-the callback that receives the response. LicenseChecker also tracks open license
-requests and manages their timeouts. </p>
-
-<p>So that it can handle timeouts properly and also process incoming responses
-without affecting your application's UI thread, LicenseChecker spawns a
-background thread at instantiation. In the thread it does all processing of
-license check results, whether the result is a response received from the server
-or a timeout error. At the conclusion of processing, the LVL calls your
-LicenseCheckerCallback methods from the background thread. </p>
-
-<p>To your application, this means that:</p>
-
-<ol>
-<li>Your LicenseCheckerCallback methods will be invoked, in many cases, from a
-background thread.</li>
-<li>Those methods won't be able to update state or invoke any processing in the
-UI thread, unless you create a Handler in the UI thread and have your callback
-methods post to the Handler.</li>
-</ol>
-
-<p>If you want your LicenseCheckerCallback methods to update the UI thread,
-instantiate a {@link android.os.Handler} in the main Activity's
-{@link android.app.Activity#onCreate(android.os.Bundle) onCreate()} method,
-as shown below. In this example, the LVL sample application's
-LicenseCheckerCallback methods (see above) call <code>displayResult()</code> to
-update the UI thread through the Handler's
-{@link android.os.Handler#post(java.lang.Runnable) post()} method.</p>
-
-<pre>private Handler mHandler;
-
-    &#64;Override
-    public void onCreate(Bundle savedInstanceState) {
-        ...
-        mHandler = new Handler();
-    }
-</pre>
-
-<p>Then, in your LicenseCheckerCallback methods, you can use Handler methods to
-post Runnable or Message objects to the Handler. Here's how the sample
-application included in the LVL posts a Runnable to a Handler in the UI thread
-to display the license status.</p>
-
-<pre>    private void displayResult(final String result) {
-        mHandler.post(new Runnable() {
-            public void run() {
-                mStatusText.setText(result);
-                setProgressBarIndeterminateVisibility(false);
-                mCheckLicenseButton.setEnabled(true);
-            }
-        });
-    }
-</pre>
-
-<h4 id="lc-lcc">Instantiate LicenseChecker and LicenseCheckerCallback</h4>
-
-<p>In the main Activity's
-{@link android.app.Activity#onCreate(android.os.Bundle) onCreate()} method,
-create private instances of LicenseCheckerCallback and LicenseChecker. You must
-instantiate LicenseCheckerCallback first, because you need to pass a reference
-to that instance when you call the contructor for LicenseChecker. </p>
-
-<p>When you instantiate LicenseChecker, you need to pass in these parameters:</p>
-
-<ul>
-<li>The application {@link android.content.Context}</li>
-<li>A reference to the Policy implementation to use for the license check. In
-most cases, you would use the default Policy implementation provided by the LVL,
-ServerManagedPolicy. </li>
-<li>The String variable holding your publisher account's public key for
-licensing. </li>
-</ul>
-
-<p>If you are using ServerManagedPolicy, you won't need to access the class
-directly, so you can instantiate it in the LicenseChecker constructor,
-as shown in the example below. Note that you need to pass a reference to a new
-Obfuscator instance when you construct ServerManagedPolicy.</p>
-
-<p>The example below shows the instantiation of LicenseChecker and
-LicenseCheckerCallback from the <code>onCreate()</code> method of an Activity
-class. </p>
-
-<pre>public class MainActivity extends Activity {
-    ...
-    private LicenseCheckerCallback mLicenseCheckerCallback;
-    private LicenseChecker mChecker;
-
-    &#64;Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        ...
-        // Construct the LicenseCheckerCallback. The library calls this when done.
-        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
-
-        // Construct the LicenseChecker with a Policy.
-        mChecker = new LicenseChecker(
-            this, new ServerManagedPolicy(this,
-                new AESObfuscator(SALT, getPackageName(), deviceId)),
-            BASE64_PUBLIC_KEY  // Your public licensing key.
-            );
-        ...
-    }
-}
-</pre>
-
-
-<p>Note that LicenseChecker calls the LicenseCheckerCallback methods from the UI
-thread <em>only</em> if there is valid license response cached locally. If the
-license check is sent to the server, the callbacks always originate from the
-background thread, even for network errors. </p>
-
-
-<h4 id="check-access">Call checkAccess() to initiate the license check</h4>
-
-<p>In your main Activity, add a call to the <code>checkAccess()</code> method of the
-LicenseChecker instance. In the call, pass a reference to your
-LicenseCheckerCallback instance as a parameter. If you need to handle any
-special UI effects or state management before the call, you might find it useful
-to call <code>checkAccess()</code> from a wrapper method. For example, the LVL
-sample application calls <code>checkAccess()</code> from a
-<code>doCheck()</code> wrapper method:</p>
-
-<pre>    &#64;Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        ...
-        // Call a wrapper method that initiates the license check
-        doCheck();
-        ...
-    }
-    ...
-    private void doCheck() {
-        mCheckLicenseButton.setEnabled(false);
-        setProgressBarIndeterminateVisibility(true);
-        mStatusText.setText(R.string.checking_license);
-        mChecker.checkAccess(mLicenseCheckerCallback);
-    }
-</pre>
-
-
-<h4 id="account-key">Embed your public key for licensing</h4>
-
-<p>For each publisher account, the Android Market service automatically
-generates a  2048-bit RSA public/private key pair that is used exclusively for
-licensing. The key pair is uniquely associated with the publisher account and is
-shared across all applications that are published through the account. Although
-associated with a publisher account, the key pair is <em>not</em> the same as
-the key that you use to sign your applications (or derived from it).</p>
-
-<p>The Android Market publisher site exposes the public key for licensing to any
-developer signed in to the publisher account, but it keeps the private key
-hidden from all users in a secure location. When an application requests a
-license check for an application published in your account, the licensing server
-signs the license response using the private key of your account's key pair.
-When the LVL receives the response, it uses the public key provided by the
-application to verify the signature of the license response. </p>
-
-<p>To add licensing to an application, you must obtain your publisher account's
-public key for licensing and copy it into your application. Here's how to find
-your account's public key for licensing:</p>
-
-<ol>
-<li>Go to the Android Market <a
-href="http://market.android.com/publish">publisher site</a> and sign in.
-Make sure that you sign in to the account from which the application you are
-licensing is published (or will be published). </li>
-<li>In the account home page, locate the "Edit profile" link and click it. </li>
-<li>In the Edit Profile page, locate the "Licensing" pane, shown below. Your
-public key for licensing is given in the "Public key" text box. </li>
-</ol>
-
-<p>To add the public key to your application, simply copy/paste the key string
-from the text box into your application as the value of the String variable
-<code>BASE64_PUBLIC_KEY</code>. When you are copying, make sure that you have
-selected the entire key string, without omitting any characters. </p>
-
-<p>Here's an example from the LVL sample application:</p>
-
-<pre>    public class MainActivity extends Activity {
-        private static final String BASE64_PUBLIC_KEY = "MIIBIjANBgkqhkiG ... "; //truncated for this example
-    ...
-    }
-</pre>
-
-<h4 id="handler-cleanup">Call your LicenseChecker's onDestroy() method
-to close IPC connections</h4>
-
-<p>Finally, to let the LVL clean up before your application
-{@link android.content.Context} changes, add a call to the LicenseChecker's
-<code>onDestroy()</code> method from your Activity's
-{@link android.app.Activity#onDestroy()} implementation. The call causes the
-LicenseChecker to properly close any open IPC connection to the Android Market
-application's ILicensingService and removes any local references to the service
-and handler.</p>
-
-<p>Failing to call the LicenseChecker's <code>onDestroy()</code> method
-can lead to problems over the lifecycle of your application. For example, if the
-user changes screen orientation while a license check is active, the application
-{@link android.content.Context} is destroyed. If your application does not
-properly close the LicenseChecker's IPC connection, your application will crash
-when the response is received. Similarly, if the user exits your application
-while a license check is in progress,  your application will crash when the
-response is received, unless it has properly called the
-LicenseChecker's <code>onDestroy()</code> method to disconnect from the service.
-</p>
-
-<p>Here's an example from the sample application included in the LVL, where
-<code>mChecker</code> is the LicenseChecker instance:</p>
-
-<pre>    &#64;Override
-    protected void onDestroy() {
-        super.onDestroy();
-        mChecker.onDestroy();
-        ...
-    }
-</pre>
-
-<p>If you are extending or modifying LicenseChecker, you might also need to call
-the LicenseChecker's <code>finishCheck()</code> method, to clean up any open IPC
-connections.</p>
-
-<h3 id="impl-DeviceLimiter">Implementing a DeviceLimiter</h3>
-
-<p>In some cases, you might want your Policy to limit the number of actual
-devices that are permitted to use a single license. This would prevent a user
-from moving a licensed application onto a number of devices and using the
-application on those devices under the same account ID. It would also prevent a
-user from "sharing" the application by providing the account information
-associated with the license to other individuals, who could then sign in to that
-account on their devices and access the license to the application. </p>
-
-<p>The LVL supports per-device licensing by providing a
-<code>DeviceLimiter</code> interface, which declares a single method,
-<code>allowDeviceAccess()</code>. When a LicenseValidator is handling a response
-from the licensing server, it calls <code>allowDeviceAccess()</code>, passing a
-user ID string extracted from the response.</p>
-
-<p>If you do not want to support device limitation, <strong>no work is
-required</strong> &mdash; the LicenseChecker class automatically uses a default
-implementation called NullDeviceLimiter. As the name suggests, NullDeviceLimiter
-is a "no-op" class whose <code>allowDeviceAccess()</code> method simply returns
-a <code>LICENSED</code> response for all users and devices. </p>
-
-<div style="border-left:4px solid #FFCF00;margin:1em;padding: 0 0 0 .5em">
-<p><strong>Caution:</strong> Per-device licensing is <em>not recommended for
-most applications</em> because:</p>
-<ul>
-<li>It requires that you provide a backend server to manage a users and devices
-mapping, and </li>
-<li>It could inadvertently result in a user being denied access to an
-application that they have legitimately purchased on another device.</li>
-</ul>
-</div>
-
-
-<h2 id="test-env">Setting Up the Testing Environment</h2>
-
-<p>The Android Market publisher site provides configuration tools that let you
-and others test licensing on your application before it is published. As you are
-implementing licensing, you can make use of the publisher site tools to test
-your application's Policy and handling of different licensing responses and
-error conditions.</p>
-
-<p>The main components of the test environment for licensing include: </p>
-
-<ul>
-<li>A "Test response" configuration in your publisher account that lets you
-set the static licensing response returned, when the server processes a
-license check for an application uploaded to the publisher account, from a user
-signed in to the publisher account or a test account.</li>
-<li>An optional set of test accounts that will receive the static test
-response when they check the license of an application that you have uploaded
-(regardless whether the application is published or not).</li>
-<li>A runtime environment for the application that includes the Android Market
-application or Google APIs Add-On, on which the user is signed in to the
-publisher account or one of the test accounts.</li>
-</ul>
-
-<p>Setting up the test environment properly involves:</p>
-
-<ol>
-<li><a href="#test-response">Setting static test responses</a> that are returned by the licensing server.</li>
-<li><a href="#test-acct-setup">Setting up test accounts</a> as needed.</li>
-<li><a href="#acct-signin">Signing in</a> properly to an emulator or device, before initiating a license check test.</li>
-</ol>
-
-<p>The sections below provide more information.</p>
-
-
-<h3 id="test-response">Setting test responses for license checks</h3>
-
-<p>Android Market provides a configuration setting in your publisher account
-that lets you override the normal processing of a license check and return a
-specified static response code. The setting is for testing only and applies
-<em>only</em> to license checks for applications that you have uploaded, made by
-any user signed in to an emulator or device using the credentials of the
-publisher account or a registered test account. For other users, the server
-always processes license checks according to normal rules.  </p>
-
-<p>To set a test response for your account, sign in to your publisher account
-and click "Edit Profile". In the Edit Profile page, locate the Test Response
-menu in the Licensing panel, shown below. You can select from the full set of
-valid server response codes to control the response or condition you want to
-test in your application.</p>
-
-<p>In general, you should make sure to test your application's licensing
-implementation with every response code available in the Test Response menu.
-For a description of the codes, see <a href="#server-response-codes">Server
-Response Codes</a> in the Appendix of this document.</p>
-
-<div style="margin-bottom:2em;" id="licensing_test_response">
-
-<img src="{@docRoot}images/licensing_test_response.png" style="text-align:left;margin-bottom:0;" />
-<div style="margin:0 2em;padding:0"><strong>Figure 7.</strong> The Licensing
-panel of your account's Edit Profile page, showing the Test Accounts field and the
-Test Response menu.</div>
-</div>
-
-<p>Note that the test response that you configure applies account-wide &mdash;
-that is, it applies not to a single application, but to <em>all</em>
-applications associated with the publisher account. If you are testing multiple
-applications at once, changing the test response will affect all of those
-applications on their next license check (if the user is signed into
-the emulator or device using the publisher account or a test account).</p>
-
-<p>Before you can successfully receive a test response for a license check,
-you must sign in to the device or emulator on which the application
-is installed, and from which it is querying the server. Specifically, you must
-sign using either your publisher account or one of the test accounts that you
-have set up. For more information about test accounts, see the next section.</p>
-
-<p>See <a href="#server-response-codes">Server Response Codes</a> for a list of
-test responses available and their meanings. </p>
-
-
-<h3 id="test-acct-setup">Setting up test accounts</h3>
-
-<p>In some cases, you might want to let multiple teams of developers test
-licensing on applications that will ultimately be published through your
-publisher account, but without giving them access to your publisher account's
-sign-in credentials. To meet that need, the Android Market publisher site lets
-you set up one or more optional <em>test accounts</em> &mdash; accounts that are
-authorized to query the licensing server and receive static test responses from
-your publisher account.</p>
-
-<p>Test accounts are standard Google accounts that you register on your
-publisher account, such that they will receive the test response for
-applications that you have uploaded. Developers can then sign in to their
-devices or emulators using the test account credentials and initiate license
-checks from installed applications. When the licensing server receives a license
-check from a user of a test account, it returns the static test response
-configured for the publisher account.  </p>
-
-<p>Necessarily, there are limitations on the access and permissions given to
-users signed in through test accounts, including:</p>
-
-<ul>
-<li>Test account users can query the licensing server only for applications that
-are already uploaded to the publisher account. </li>
-<li>Test account users do not have permission to upload applications to your
-publisher account.</li>
-<li>Test account users do not have permission to set the publisher account's
-static test response.</li>
-</ul>
-
-<p>The table below summarizes the differences in capabilities, between the
-publisher account, a test account, and any other account.</p>
-
-<p class="table-caption" id="acct-types-table"><strong>Table 1.</strong>
-Differences in account types for testing licensing.</p>
-
-<table>
-<tr>
-<th>Account Type</th>
-<th>Can check license before upload?</th>
-<th>Can receive test response?</th>
-<th>Can set test response?</th>
-</tr>
-
-<tr>
-<td>Publisher account</td>
-<td>Yes</td>
-<td>Yes</td>
-<td>Yes</td>
-</tr>
-
-<tr>
-<td>Test account</td>
-<td>No</td>
-<td>Yes</td>
-<td>No</td>
-</tr>
-
-<tr>
-<td>Other</td>
-<td>No</td>
-<td>No</td>
-<td>No</td>
-</tr>
-</table>
-
-<h4 id="reg-test-acct">Registering test accounts on the publisher account</h4>
-
-<p>To get started, you need to register each test account in your publisher
-account. As shown in <a href="#licensing_test_response">Figure 7</a>, above, you
-register test accounts in the Licensing panel of your publisher account's Edit
-Profile page. Simply enter the accounts as a comma-delimited list and click
-<strong>Save</strong> to save your profile changes.</p>
-
-<p>You can use any Google account as a test account. If you want to own and
-control the test accounts, you can create the accounts yourself and distribute
-the credentials to your developers or testers.</p>
-
-<h4 id="test-app-upload">Handling application upload and distribution for test
-account users</h4>
-
-<p>As mentioned above, users of test accounts can only receive static test
-responses for applications that are uploaded to the publisher account. Since
-those users do not have permission to upload applications, as the publisher you
-will need to work with those users to collect apps for upload and distribute
-uploaded apps for testing. You can handle collection and distribution in any way
-that is convenient. </p>
-
-<p>Once an application is uploaded and becomes known to the licensing server,
-developers and testers can continue modify the application in their local
-development environment, without having to upload new versions. You only need to
-upload a new version if the local application increments the
-<code>versionCode</code> attribute in the manifest file. </p>
-
-<h4 id="test-key">Distributing your public key to test account users</h4>
-
-<p>The licensing server handles static test responses in the normal way,
-including signing the license response data, adding extras parameters, and so
-on. To support developers who are implementing licensing using test accounts,
-rather than the publisher account, you will need to distribute
-your public key to them. Developers without access to the publisher site do not
-have access to your public key, and without the key they won't be able to
-verify license responses. </p>
-
-<p>Note that if you decide to generate a new licensing key pair for your account
-for some reason, you need to notify all users of test accounts. For
-testers, you can embed the new key in the application package and distribute it
-to users. For developers, you will need to distribute the new key to them
-directly. </p>
-
-
-<h3 id="acct-signin">Signing in to an authorized account in the runtime
-environment</h3>
-
-<p>The licensing service is designed to determine whether a given user is
-licensed to use a given application &mdash; during a license check, the Android
-Market application gathers the user ID from the primary account on the system
-and sends it to the server, together with the package name of the application
-and other information. However, if there is no user information available, the
-license check cannot succeed, so the Android Market application terminates the
-request and returns an error to the application. </p>
-
-<p>During testing, to ensure that your application can successfully query the
-licensing server, you must make sure that you sign in to an account <em>on the
-device or emulator</em> using:</p>
-
-<ul>
-<li>The credentials of a publisher account, or</li>
-<li>The credentials of a test account that is registered with a publisher
-account</li>
-</ul>
-
-
-<div class="sidebox-wrapper">
-<div class="sidebox">
-<h2>Signing in to a Google account on an emulator</h2>
-
-<p>If you are testing licensing on an emulator, you need to sign in to a Google
-account on the emulator. If you do not see an option to create a new Google
-account, the problem might be that your AVD is running a standard Android system
-image, rather than the Google APIs Add-On, API 8 (release 2) or higher. </p>
-
-<p style="margin-top:.5em;">For more information, see <a
-href="#runtime-setup">Setting up the runtime environment</a>, above.</p>
-
-</div>
-</div>
-
-<p>Signing in using a publisher account offers the advantage of letting your
-applications receive static test responses even before the applications are
-uploaded to the publisher site.</p>
-
-<p>If you are part of a larger organization or are working with external groups
-on applications that will be published through your site, you will more likely
-want to distribute test accounts instead, then use those to sign in during
-testing. </p>
-
-<p>To sign in on a device or emulator, follow the steps below. The preferred
-approach is to sign in as the primary account &mdash; however, if there are
-other accounts already in use on the device or emulator, you can create an
-additional account and sign in to it using the publisher or test account
-credentials.  </p>
-
-<ol>
-<li>Open Settings &gt; Accounts &amp; sync</li>
-<li>Select <strong>Add Account</strong> and choose to add a "Google" account.
-</li>
-<li>Select <strong>Next</strong> and then <strong>Sign in</strong>.</li>
-<li>Enter the username and password of either the publisher account or a test
-account that is registered in the publisher account.</li>
-<li>Select <strong>Sign in</strong>. The system signs you in to the new
-account.</li>
-</ol>
-
-<p>Once you are signed in, you can begin testing licensing in your application
-(if you have completed the LVL integration steps above). When your application
-initiates a license check, it will receive a response containing the static test
-response configured on the publisher account. </p>
-
-<p>Note that, if you are using an emulator, you will need to sign in to the
-publisher account or test account each time you wipe data when restarting the
-emulator.</p>
-
-<div style="margin:2em 1em 1em 1em;">
-
-<img src="{@docRoot}images/licensing_device_signin.png" style="text-align:left;" />
-<div style="margin:.25em 1.25em;padding:0"><strong>Figure 8.</strong> Example of
-setting up a Google account on a device or emulator.</div>
-</div>
-
-<h2 id="app-obfuscation">Obfuscating Your Application</h2>
-
-<p>To ensure the security of your application, particularly for a paid
-application that uses licensing and/or custom constraints and protections, it's
-very important to obfuscate your application code. Properly obfuscating your
-code makes it more difficult for a malicious user to decompile the application's
-bytecode, modify it &mdash; such as by removing the license check &mdash;
-and then recompile it.</p>
-
-<p>Several obfuscator programs are available for Android applications, including
-<a href="http://proguard.sourceforge.net/">ProGuard</a>, which also offers
-code-optimization features. The use of ProGuard or a similar program to obfuscate
-your code is <em>strongly recommended</em> for all applications that use Android
-Market Licensing. </p>
-
-<h2 id="app-publishing">Publishing a Licensed Application</h2>
-
-<p>When you are finished testing your license implementation, you are ready to
-publish the application on Android Market. Follow the normal steps to <a
-href="{@docRoot}guide/publishing/preparing.html">prepare</a>, <a
-href="{@docRoot}guide/publishing/app-signing.html">sign</a>, and then <a
-href="{@docRoot}guide/publishing/publishing.html">publish the application</a>.
-</p>
-
-<h4>Removing Copy Protection</h4>
-
-<p>After uploading your licensed application, remember to remove copy protection
-from the application, if it is currently used. To check and remove copy
-protection, sign in to the publisher site and go the application's upload
-details page. In the Publishing options section, make sure that the Copy
-Protection radio button selection is "Off".</p>
-
-<h4>Considerations for Free Apps</h4>
-
-<p>Licensing is currently supported only for paid applications. If you already
-published your application as free, you won't be able to upload an updated
-version that includes licensing (that is, an application that uses the same
-package name and that includes the <a href="#manifest-permission">licensing
-permission</a>). Here are some points to keep in mind:</p>
-
-<ul>
-<li>If you want to offer a free version of your application that provides a
-reduced feature set (or that offers the full feature set for trial period), the
-free version of your application must not include the licensing permission and
-must use a different package name than the paid version of the app.</li>
-<li>If you want to offer a paid version of your free application that uses
-licensing, you can do so under a new package name.</li>
-</ul>
-
-<h2 id="support">Where to Get Support</h2>
-
-<p>If you have questions or encounter problems while implementing or deploying
-publishing in your applications, please use the support resources listed in the
-table below. By directing your queries to the correct forum, you can get the
-support you need more quickly. </p>
-
-<p class="table-caption"><strong>Table 2.</strong> Developer support resources
-for Android Market Licensing Service.</p>
-
-<table>
-
-<tr>
-<th>Support Type</th>
-<th>Resource</th>
-<th>Range of Topics</th>
-</tr>
-<tr>
-<td rowspan="2">Development and testing issues</td>
-<td>Google Groups: <a
-href="http://groups.google.com/group/android-developers">android-developers</a>
-</td>
-<td rowspan="2">LVL download and integration, library projects, Policy
-questions, user experience ideas, handling of responses, Obfuscator, IPC, test
-environment setup</td>
-</tr>
-<tr>
-<td>Stack Overflow: <a
-href="http://stackoverflow.com/questions/tagged/android">http://stackoverflow.com/questions/tagged/android</a></td>
-</tr>
-<tr>
-<td rowspan="2">Accounts, publishing, and deployment issues</td>
-<td><a href="http://www.google.com/support/forum/p/Android+Market">Android
-Market Help Forum</a></td>
-<td rowspan="2">Publisher accounts, licensing key pair, test accounts, server
-responses, test responses, application deployment and results</td>
-</tr>
-<tr>
-<td><a
-href="http://market.android.com/support/bin/answer.py?answer=186113">Market
-Licensing Support FAQ</a></td>
-</tr>
-<tr>
-<td>LVL issue tracker</td>
-<td><a href="http://code.google.com/p/marketlicensing/issues/">Marketlicensing
-project issue tracker</a></td>
-<td>Bug and issue reports related specifically to the LVL source code classes
-and interface implementations</td>
-</tr>
-
-</table>
-
-<p>For general information about how to post to the groups listed above, see <a
-href="{@docRoot}resources/community-groups.html">Developer Forums</a> document
-in the Resources tab.</p>
-
-<h2 id="lvl-summary">Summary of LVL Classes and Interfaces</h2>
-
-<p>The table below lists all of the source files in the License Verification
-Library (LVL) available through the Android SDK. All of the files are part of
-the <code>com.android.vending.licensing</code> package.</p>
-
-<p class="table-caption"><strong>Table A-1.</strong> Summary of LVL library
-classes and interfaces.</p>
-
-<div style="width:99%">
-<table width="100%">
-
-<tr>
-<th width="15%">Category</th>
-<th width="20%">Name</th>
-<th width="100%">Description</th>
-</tr>
-
-<tr>
-<td rowspan="2">License check and result</td>
-<td>LicenseChecker</td>
-<td>Class that you instantiate (or subclass) to initiate a license check.</td>
-</tr>
-<tr>
-<td><em>LicenseCheckerCallback</em></td>
-<td>Interface that you implement to handle result of the license check.</td>
-</tr>
-
-<tr>
-<td rowspan="3" width="15%">Policy</td>
-<td width="20%"><em>Policy</em></td>
-<td width="100%">Interface that you implement to determine whether to allow
-access to the application, based on the license response. </td>
-</tr>
-<tr>
-<td>ServerManagedPolicy</td>
-<td width="100%">Default Policy implementation. Uses settings provided by the
-licensing server to manage local storage of license data, license validity,
-retry.</td>
-</tr>
-<tr>
-<td>StrictPolicy</td>
-<td>Alternative Policy implementation. Enforces licensing based on a direct
-license response from the server only. No caching or request retry.</td>
-</tr>
-
-<tr>
-<td rowspan="2" width="15%">Data obfuscation <br><em>(optional)</em></td>
-<td width="20%"><em>Obfuscator</em></td>
-<td width="100%">Interface that you implement if you are using a Policy (such as
-ServerManagedPolicy) that caches license response data in a persistent store.
-Applies an obfuscation algorithm to encode and decode data being written or
-read.</td>
-</tr>
-<tr>
-<td>AESObfuscator</td>
-<td>Default Obfuscator implementation that uses AES encryption/decryption
-algorithm to obfuscate/unobfuscate data.</td>
-</tr>
-
-<tr>
-<td rowspan="2" width="15%">Device limitation<br><em>(optional)</em></td>
-<td width="20%"><em>DeviceLimiter</em></td>
-<td width="100%">Interface that you implement if you want to restrict use of an
-application to a specific device. Called from LicenseValidator. Implementing
-DeviceLimiter is not recommended for most applications because it requires a
-backend server and may cause the user to lose access to licensed applications,
-unless designed with care.</td>
-</tr>
-<tr>
-<td>NullDeviceLimiter</td>
-<td>Default DeviceLimiter implementation that is a no-op (allows access to all
-devices).</td>
-</tr>
-
-<tr>
-<td rowspan="6" width="15%">Library core, no integration needed</td>
-<td width="20%">ResponseData</td>
-<td width="100%">Class that holds the fields of a license response.</td>
-</tr>
-<tr>
-<td>LicenseValidator</td>
-<td>Class that decrypts and verifies a response received from the licensing
-server.</td>
-</tr>
-<tr>
-<td>ValidationException</td>
-<td>Class that indicates errors that occur when validating the integrity of data
-managed by an Obfuscator.</td>
-</tr>
-<tr>
-<td>PreferenceObfuscator</td>
-<td>Utility class that writes/reads obfuscated data to the system's
-{@link android.content.SharedPreferences} store.</td>
-</tr>
-<tr>
-<td><em>ILicensingService</em></td>
-<td>One-way IPC interface over which a license check request is passed to the
-Android Market client.</td>
-</tr>
-<tr>
-<td><em>ILicenseResultListener</em></td>
-<td>One-way IPC callback implementation over which the application receives an
-asynchronous response from the licensing server.</td>
-</tr>
-
-</table>
-</div>
-
-
-<h2 id="server-response-codes">Server Response Codes</h2>
-
-<p>The table below lists all of the license response codes supported by the
-licensing server. In general, an application should handle all of these response
-codes. By default, the LicenseValidator class in the LVL provides all of the
-necessary handling of these response codes for you. </p>
-
-<p class="table-caption"><strong>Table A-2.</strong> Summary of response codes
-returned by the Android Market server in a license response.</p>
-
-<table>
-
-<tr>
-<th>Response Code</th>
-<th>Description</th>
-<th>Signed?</th>
-<th>Extras</th>
-<th>Comments</th>
-</tr>
-<tr>
-<td>LICENSED</td>
-<td>The application is licensed to the user. The user has purchased the
-application or the application only exists as a draft.</td>
-<td>Yes</td>
-<td><code>VT</code>,&nbsp;<code>GT</code>, <code>GR</code></td>
-<td><em>Allow access according to Policy constraints.</em></td>
-</tr>
-<tr>
-<td>LICENSED_OLD_KEY</td>
-<td>The application is licensed to the user, but there is an updated application
-version available that is signed with a different key. </td>
-<td>Yes </td>
-<td><code>VT</code>, <code>GT</code>, <code>GR</code>, <code>UT</code></td>
-<td><em>Optionally allow access according to Policy constraints.</em>
-<p style="margin-top:.5em;">Can indicate that the key pair used by the installed
-application version is invalid or compromised. The application can allow access
-if needed or inform the user that an upgrade is available and limit further use
-until upgrade.</p>
-</td>
-</tr>
-<tr>
-<td>NOT_LICENSED</td>
-<td>The application is not licensed to the user.</td>
-<td>No</td>
-<td></td>
-<td><em>Do not allow access.</em></td>
-</tr>
-<tr>
-<td>ERROR_CONTACTING_SERVER</td>
-<td>Local error &mdash; the Android Market application was not able to reach the
-licensing server, possibly because of network availability problems. </td>
-<td>No</td>
-<td></td>
-<td><em>Retry the license check according to Policy retry limits.</em></td>
-</tr>
-<tr>
-<td>ERROR_SERVER_FAILURE</td>
-<td>Server error &mdash; the server could not load the publisher account's key
-pair for licensing.</td>
-<td>No</td>
-<td></td>
-<td><em>Retry the license check according to Policy retry limits.</em>
-</td>
-</tr>
-<tr>
-<td>ERROR_INVALID_PACKAGE_NAME</td>
-<td>Local error &mdash; the application requested a license check for a package
-that is not installed on the device. </td>
-<td>No </td>
-<td></td>
-<td><em>Do not retry the license check.</em>
-<p style="margin-top:.5em;">Typically caused by a development error.</p>
-</td>
-</tr>
-<tr>
-<td>ERROR_NON_MATCHING_UID</td>
-<td>Local error &mdash; the application requested a license check for a package
-whose UID (package, user ID pair) does not match that of the requesting
-application. </td>
-<td>No </td>
-<td></td>
-<td><em>Do not retry the license check.</em>
-<p style="margin-top:.5em;">Typically caused by a development error.</p>
-</td>
-</tr>
-<tr>
-<td>ERROR_NOT_MARKET_MANAGED</td>
-<td>Server error &mdash; the application (package name) was not recognized by
-Android Market. </td>
-<td>No</td>
-<td></td>
-<td><em>Do not retry the license check.</em>
-<p style="margin-top:.5em;">Can indicate that the application was not published
-through Android Market or that there is an development error in the licensing
-implementation.</p>
-</td>
-</tr>
-
-</table>
-
-<p class="note"><strong>Note:</strong> As documented in <a href="#test-env">
-Setting Up The Testing Environment</a>, the response code can be manually
-overridden for the application developer and any registered test users via the
-Android Market publisher site.
-<br/><br/>
-Additionally, as noted above, applications that are in draft mode (in other
-words, applicaitons that have been uploaded but have <em>never</em> been
-published) will return LICENSED for all users, even if not listed as a test
-user. Since the application has never been offered for download, it is assumed
-that any users running it must have obtained it from an authorized channel for
-testing purposes.</p>
-
-<h2 id="extras">Server Response Extras</h2>
-
-<p>The licensing server includes several settings in certain types of license
-responses, to assist the application and its Policy in managing access to the
-application across the 24-hour refund period and other conditions. Specifically,
-the server provides recommended values for the application's license validity
-period, retry grace period, maximum allowable retry count, and other settings.
-The server appends the settings as key-value pairs in the license response
-"extras" field. </p>
-
-<p>Any Policy implementation can extract the extras settings from the license
-response and use them as needed. The LVL default Policy implementation, <a
-href="#ServerManagedPolicy">ServerManagedPolicy</a>, serves as a working
-implementation and an illustration of how to obtain, store, and use the
-settings. </p>
-
-<p class="table-caption"><strong>Table A-3.</strong> Summary of
-license-management settings supplied by the Android Market server in a license
-response.</p>
-
-<table>
-<tr>
-<th>Extra</th><th>Description</th>
-</tr>
-
-<tr>
-  <td>VT</td>
-  <td>License validity timestamp. Specifies the date/time at which the current
-(cached) license response expires and must be rechecked on the licensing server.
- </td>
-</tr>
-<tr>
-  <td>GT</td>
-  <td>Grace period timestamp. Specifies the end of the period during which a
-Policy may allow access to the application, even though the response status is
-RETRY. <p>The value is managed by the server, however a typical value would be 5
-or more days.</p></td>
-</tr>
-<tr>
-  <td>GR</td>
-  <td>Maximum retries count. Specifies how many consecutive RETRY license checks
-the Policy should allow, before denying the user access to the application.
-<p>The value is managed by the server, however a typical value would be "10" or
-higher.</p></td>
-</tr>
-<tr>
-  <td>UT</td>
-  <td>Update timestamp. Specifies the day/time when the most recent update to
-this application was uploaded and published. <p>The server returns this extra
-only for LICENSED_OLD_KEYS responses, to allow the Policy to determine how much
-time has elapsed since an update was published with new licensing keys before
-denying the user access to the application. </p></td>
-</tr>
-
-</table>
-
-<p>The sections below provide more information about the server-provided
-settings and how to use them. </p>
-
-<h4>License validity period</h4>
-
-<p>The Android Market licensing server sets a license validity period for all
-downloaded applications. The period expresses the interval of time over which an
-application's license status should be considered as unchanging and cacheable by
-a licensing Policy in the application. The licensing server includes the
-validity period in its response to all license checks, appending an
-end-of-validity timestamp to the response as an extra under the key "VT". A
-Policy can extract the VT key value and use it to conditionally allow access to
-the application without rechecking the license, until the validity period
-expires. </p>
-
-<p>The license validity signals to a licensing Policy when it must recheck the
-licensing status with the licensing server. It is <em>not</em> intended to imply
-whether an application is actually licensed for use. That is, when an
-application's license validity period expires, this does not mean that the
-application is no longer licensed for use &mdash; rather, it indicates only that
-the Policy must recheck the licensing status with the server. It follows that,
-as long as the license validity period is not expired, it is acceptable for the
-Policy to cache the initial license status locally and return the cached license
-status instead of sending a new license check to the server.</p>
-
-<p>The licensing server manages the validity period as a means of helping the
-application properly enforce licensing across the refund period offered by
-Android Market for paid applications. It sets the validity period based on
-whether the application was purchased and, if so, how long ago. Specifically,
-the server sets a validity period as follows:</p>
-
-<ul>
-<li>For a paid application, the server sets the initial license validity period
-so that the license response remains valid for as long as the application is
-refundable. A licensing Policy in the application may cache the
-result of the initial license check and does not need to recheck the license
-until the validity period has expired.</li>
-<li>When an application is no longer refundable, the server
-sets a longer validity period &mdash; typically a number of days. </li>
-<li>For a free application, the server sets the validity period to a very high
-value (<code>long.MAX_VALUE</code>). This ensures that, provided the Policy has
-cached the validity timestamp locally, it will not need to recheck the
-license status of the application in the future.</li>
-</ul>
-
-<p>The ServerManagedPolicy implementation uses the extracted timestamp
-(<code>mValidityTimestamp</code>) as a primary condition for determining whether
-to recheck the license status with the server before allowing the user access to
-the application. </p>
-
-<h4>Retry period and maximum retry count</h4>
-
-<p>In some cases, system or network conditions can prevent an application's
-license check from reaching the licensing server, or prevent the server's
-response from reaching the Android Market client application. For example, the
-user might launch an application when there is no cell network or data
-connection available &mdash; such as when on an airplane &mdash; or when the
-network connection is unstable or the cell signal is weak. </p>
-
-<p>When network problems prevent or interrupt a license check, the Android
-Market client notifies the application by returning a "RETRY" response code to
-the Policy's <code>processServerResponse()</code> method. In the case of system
-problems, such as when the application is unable to bind with Android Market's
-ILicensingService implementation, the LicenseChecker library itself calls the
-Policy <code>processServerResonse()</code> method with a "RETRY" response code.
-</p>
-
-<p>In general, the RETRY response code is a signal to the application that an
-error has occurred that has prevented a license check from completing.
-
-<p>The Android Market server helps an application to manage licensing under
-error conditions by setting a retry "grace period" and a recommended maximum
-retries count. The server includes these values in all license check responses,
-appending them as extras under the keys "GT" and "GR". </p>
-
-<p>The application Policy can extract the GT and GR extras and use them to
-conditionally allow access to the application, as follows:</p>
-
-<ul>
-<li>For a license check that results in a RETRY response, the Policy should
-cache the RETRY response code and increment a count of RETRY responses.</li>
-<li>The Policy should allow the user to access the application, provided that
-either the retry grace period is still active or the maximum retries count has
-not been reached.</li>
-</ul>
-
-<p>The ServerManagedPolicy uses the server-supplied GT and GR values as
-described above. The example below shows the conditional handling of the retry
-responses in the <code>allow()</code> method. The count of RETRY responses is
-maintained in the <code>processServerResponse()</code> method, not shown. </p>
-
-
-<pre>    public boolean allowAccess() {
-        long ts = System.currentTimeMillis();
-        if (mLastResponse == LicenseResponse.LICENSED) {
-            // Check if the LICENSED response occurred within the validity timeout.
-            if (ts &lt;= mValidityTimestamp) {
-                // Cached LICENSED response is still valid.
-                return true;
-            }
-        } else if (mLastResponse == LicenseResponse.RETRY &amp;&amp;
-                   ts &lt; mLastResponseTime + MILLIS_PER_MINUTE) {
-            // Only allow access if we are within the retry period or we haven't used up our
-            // max retries.
-            return (ts &lt;= mRetryUntil || mRetryCount &lt;= mMaxRetries);
-        }
-        return false;
-    }</pre>
-
diff --git a/docs/html/guide/publishing/preparing.jd b/docs/html/guide/publishing/preparing.jd
index 83aa5ee..c355479 100644
--- a/docs/html/guide/publishing/preparing.jd
+++ b/docs/html/guide/publishing/preparing.jd
@@ -291,7 +291,8 @@
 releasing your app through Android Market.</p>
 
 <p>For more information about Android Market Licensing Service and how to use it in your
-application, see <a href="{@docRoot}guide/publishing/licensing.html">Application Licensing</a>.</p>
+application, see <a href="{@docRoot}guide/market/licensing/index.html">Application
+Licensing</a>.</p>
 
 <h2 id="publishing-build">Building Your Application for Release</h2>
 
diff --git a/docs/html/guide/publishing/publishing.jd b/docs/html/guide/publishing/publishing.jd
index 49b34d8..27a87f9 100644
--- a/docs/html/guide/publishing/publishing.jd
+++ b/docs/html/guide/publishing/publishing.jd
@@ -74,7 +74,7 @@
 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>
+<a href="{@docRoot}guide/market/licensing/index.html">application licensing</a>.</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
@@ -254,7 +254,7 @@
 
 <p>For complete information about Android Market Licensing Service and how to
 use it in your application, read <a
-href="{@docRoot}guide/publishing/licensing.html">Application Licensing</a>.</p>
+href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a>.</p>
 
 <h2 id="marketinappbilling">Using Android Market In-app Billing</h2>
 
diff --git a/docs/html/guide/publishing/publishing_overview.jd b/docs/html/guide/publishing/publishing_overview.jd
index 79199c5..c94d201 100755
--- a/docs/html/guide/publishing/publishing_overview.jd
+++ b/docs/html/guide/publishing/publishing_overview.jd
@@ -130,7 +130,8 @@
 identify market trends, and control who your applications are being distributed to. You also have
 access to several revenue-enhancing features that are not available anywhere else, 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>. This rich array of tools
+href="{@docRoot}guide/market/licensing/index.html">application licensing</a>. This rich array of
+tools
 and features, coupled with numerous end-user community features, makes Android Market the premier
 marketplace for selling and buying Android applications.</p>
 
diff --git a/docs/html/guide/topics/fundamentals/activities.jd b/docs/html/guide/topics/fundamentals/activities.jd
index 8736aa8..b79136c 100644
--- a/docs/html/guide/topics/fundamentals/activities.jd
+++ b/docs/html/guide/topics/fundamentals/activities.jd
@@ -62,7 +62,7 @@
 activity can then start another activity in order to perform different actions. Each time a new
 activity starts, the previous activity is stopped, but the system preserves the activity
 in a stack (the "back stack"). When a new activity starts, it is pushed onto the back stack and
-takes user focus. The back stack abides to the basic "last in, first out" queue mechanism,
+takes user focus. The back stack abides to the basic "last in, first out" stack mechanism,
 so, when the user is done with the current activity and presses the <em>Back</em> button, it
 is popped from the stack (and destroyed) and the previous activity resumes. (The back stack is
 discussed more in the <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks
diff --git a/docs/html/guide/topics/fundamentals/fragments.jd b/docs/html/guide/topics/fundamentals/fragments.jd
index 281cb9d..2a22394 100644
--- a/docs/html/guide/topics/fundamentals/fragments.jd
+++ b/docs/html/guide/topics/fundamentals/fragments.jd
@@ -129,7 +129,7 @@
 
 <p>For example&mdash;to continue with the news application example&mdash;the application can embed
 two fragments in <em>Activity A</em>, when running on a tablet-sized device. However, on a
-handset-sized screen, there's not be enough room for both fragments, so <em>Activity A</em> includes
+handset-sized screen, there's not enough room for both fragments, so <em>Activity A</em> includes
 only the fragment for the list of articles, and when the user selects an article, it starts
 <em>Activity B</em>, which includes the second fragment to read the article. Thus, the application
 supports both tablets and handsets by reusing fragments in different combinations, as illustrated in
diff --git a/docs/html/guide/topics/manifest/manifest-element.jd b/docs/html/guide/topics/manifest/manifest-element.jd
index d737a67..c970c72 100644
--- a/docs/html/guide/topics/manifest/manifest-element.jd
+++ b/docs/html/guide/topics/manifest/manifest-element.jd
@@ -152,7 +152,7 @@
 
 <p class="caution"><strong>Caution:</strong> If your application uses the Android Market's Copy 
   Protection feature, it cannot be installed to a device's SD card. However, if you use Android 
-  Market's <a href="{@docRoot}guide/publishing/licensing.html">Application Licensing</a> instead, 
+  Market's <a href="{@docRoot}guide/market/licensing/index.html">Application Licensing</a> instead, 
   your application <em>can</em> be installed to internal or external storage, including SD cards.</p>
 
 <p class="note"><strong>Note:</strong> By default, your application will be installed on the
diff --git a/docs/html/guide/topics/wireless/bluetooth.jd b/docs/html/guide/topics/wireless/bluetooth.jd
index 76da08e..0567799 100644
--- a/docs/html/guide/topics/wireless/bluetooth.jd
+++ b/docs/html/guide/topics/wireless/bluetooth.jd
@@ -249,12 +249,20 @@
 <p>A dialog will appear requesting user permission to enable Bluetooth, as shown
 in Figure 1. If the user responds "Yes," the system will begin to enable Bluetooth
 and focus will return to your application once the process completes (or fails).</p> 
-<p>If enabling Bluetooth succeeds, your Activity will receive the {@link
+
+<p>The {@code REQUEST_ENABLE_BT} constant passed to {@link
+android.app.Activity#startActivityForResult(Intent,int) startActivityForResult()} is a locally
+defined integer (which must be greater than 0), that the system passes back to you in your
+{@link
+android.app.Activity#onActivityResult(int,int,Intent) onActivityResult()} implementation as the
+<code>requestCode</code> parameter.</p>
+
+<p>If enabling Bluetooth succeeds, your activity receives the {@link
 android.app.Activity#RESULT_OK} result code in the {@link
 android.app.Activity#onActivityResult(int,int,Intent) onActivityResult()}
 callback. If Bluetooth was not enabled
-due to an error (or the user responded "No") then the result code will be {@link
-android.app.Activity#RESULT_CANCELED}.</p> 
+due to an error (or the user responded "No") then the result code is {@link
+android.app.Activity#RESULT_CANCELED}.</p>
 </li> 
 </ol> 
  
@@ -431,11 +439,11 @@
  
 <p>A dialog will be displayed, requesting user permission to make the device
 discoverable, as shown in Figure 2. If the user responds "Yes," then the device
-will become discoverable for the specified amount of time. Your Activity will
+will become discoverable for the specified amount of time. Your activity will
 then receive a call to the {@link android.app.Activity#onActivityResult(int,int,Intent)
 onActivityResult())} callback, with the result code equal to the duration that the device
 is discoverable. If the user responded "No" or if an error occurred, the result code will
-be Activity.RESULT_CANCELLED.</p> 
+be {@link android.app.Activity#RESULT_CANCELED}.</p> 
  
 <p class="note"><strong>Note:</strong> If Bluetooth has not been enabled on the device,
 then enabling device discoverability will automatically enable Bluetooth.</p> 
@@ -568,7 +576,7 @@
 </ol> 
  
 <p>The {@link android.bluetooth.BluetoothServerSocket#accept()} call should not
-be executed in the main Activity UI thread because it is a blocking call and
+be executed in the main activity UI thread because it is a blocking call and
 will prevent any other interaction with the application. It usually makes
 sense to do all work with a {@link android.bluetooth.BluetoothServerSocket} or {@link
 android.bluetooth.BluetoothSocket} in a new
@@ -696,7 +704,7 @@
 12 seconds), then it will throw an exception.</p> 
 <p>Because {@link
 android.bluetooth.BluetoothSocket#connect()} is a blocking call, this connection
-procedure should always be performed in a thread separate from the main Activity
+procedure should always be performed in a thread separate from the main activity
 thread.</p> 
 <p class="note">Note: You should always ensure that the device is not performing
 device discovery when you call {@link
@@ -838,7 +846,7 @@
             try {
                 // Read from the InputStream
                 bytes = mmInStream.read(buffer);
-                // Send the obtained bytes to the UI Activity
+                // Send the obtained bytes to the UI activity
                 mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
                         .sendToTarget();
             } catch (IOException e) {
@@ -847,14 +855,14 @@
         }
     }
  
-    /* Call this from the main Activity to send data to the remote device */
+    /* Call this from the main activity to send data to the remote device */
     public void write(byte[] bytes) {
         try {
             mmOutStream.write(bytes);
         } catch (IOException e) { }
     }
  
-    /* Call this from the main Activity to shutdown the connection */
+    /* Call this from the main activity to shutdown the connection */
     public void cancel() {
         try {
             mmSocket.close();
@@ -866,12 +874,12 @@
 <p>The constructor acquires the necessary streams and once executed, the thread
 will wait for data to come through the InputStream. When {@link
 java.io.InputStream#read(byte[])} returns with
-bytes from the stream, the data is sent to the main Activity using a member
+bytes from the stream, the data is sent to the main activity using a member
 Handler from the parent class. Then it goes back and waits for more bytes from
 the stream.</p> 
  
 <p>Sending outgoing data is as simple as calling the thread's
-<code>write()</code> method from the main Activity and passing in the bytes to
+<code>write()</code> method from the main activity and passing in the bytes to
 be sent. This method then simply calls {@link
 java.io.OutputStream#write(byte[])} to send the data to the remote device.</p> 
  
diff --git a/docs/html/resources/dashboard/opengl.jd b/docs/html/resources/dashboard/opengl.jd
index d55ab2b..6978d62 100644
--- a/docs/html/resources/dashboard/opengl.jd
+++ b/docs/html/resources/dashboard/opengl.jd
@@ -57,7 +57,7 @@
 <div class="dashboard-panel">
 
 <img alt="" width="400" height="250"
-src="http://chart.googleapis.com/chart?cht=p&chs=400x250&chco=c4df9b,6fad0c&chl=GL%201.1%20only|GL%202.0%20%26%201.1&chd=t%3A10.7,89.3" />
+src="http://chart.googleapis.com/chart?cht=p&chs=400x250&chco=c4df9b,6fad0c&chl=GL%201.1%20only|GL%202.0%20%26%201.1&chd=t%3A10.8,89.2" />
 
 <table>
 <tr>
@@ -66,14 +66,14 @@
 </tr>
 <tr>
 <td>1.1 only</th>
-<td>10.7%</td>
+<td>10.8%</td>
 </tr>
 <tr>
 <td>2.0 &amp; 1.1</th>
-<td>89.3%</td>
+<td>89.2%</td>
 </tr>
 </table>
 
-<p><em>Data collected during a 7-day period ending on February 1, 2012</em></p>
+<p><em>Data collected during a 7-day period ending on March 4, 2012</em></p>
 </div>
 
diff --git a/docs/html/resources/dashboard/platform-versions.jd b/docs/html/resources/dashboard/platform-versions.jd
index 4ea52af..9631059 100644
--- a/docs/html/resources/dashboard/platform-versions.jd
+++ b/docs/html/resources/dashboard/platform-versions.jd
@@ -52,7 +52,7 @@
 <div class="dashboard-panel">
 
 <img alt="" height="250" width="470"
-src="http://chart.apis.google.com/chart?&cht=p&chs=460x250&chd=t:0.6,1.0,7.6,27.8,0.5,58.1,0.1,1.4,1.9,0.3,0.7&chl=Android%201.5|Android%201.6|Android%202.1|Android%202.2|Android%202.3|Android%202.3.3|Android%203.0|Android%203.1|Android%203.2|Android%204.0|Android%204.0.3&chco=c4df9b,6fad0c" />
+src="http://chart.apis.google.com/chart?&cht=p&chs=460x250&chd=t:0.1,0.4,0.8,6.6,25.2,0.5,61.4,1.1,2.1,0.4,1.2&chl=Android%201.5|Android%201.6|Android%202.1|Android%202.2|Android%202.3|Android%202.3.3|Android%203.1|Android%203.2|Android%204.0|Android%204.0.3&chco=c4df9b,6fad0c" />
 
 <table>
 <tr>
@@ -61,25 +61,25 @@
   <th>API Level</th>
   <th>Distribution</th>
 </tr>
-<tr><td><a href="{@docRoot}sdk/android-1.5.html">Android 1.5</a></td><td>Cupcake</td>  <td>3</td><td>0.6%</td></tr>
-<tr><td><a href="{@docRoot}sdk/android-1.6.html">Android 1.6</a></td><td>Donut</td>    <td>4</td><td>1.0%</td></tr>
-<tr><td><a href="{@docRoot}sdk/android-2.1.html">Android 2.1</a></td><td>Eclair</td>   <td>7</td><td>7.6%</td></tr>
-<tr><td><a href="{@docRoot}sdk/android-2.2.html">Android 2.2</a></td><td>Froyo</td>    <td>8</td><td>27.8%</td></tr>
+<tr><td><a href="{@docRoot}sdk/android-1.5.html">Android 1.5</a></td><td>Cupcake</td>  <td>3</td><td>0.4%</td></tr>
+<tr><td><a href="{@docRoot}sdk/android-1.6.html">Android 1.6</a></td><td>Donut</td>    <td>4</td><td>0.8%</td></tr>
+<tr><td><a href="{@docRoot}sdk/android-2.1.html">Android 2.1</a></td><td>Eclair</td>   <td>7</td><td>6.6%</td></tr>
+<tr><td><a href="{@docRoot}sdk/android-2.2.html">Android 2.2</a></td><td>Froyo</td>    <td>8</td><td>25.3%</td></tr>
 <tr><td><a href="{@docRoot}sdk/android-2.3.html">Android 2.3 -<br/>
                              Android 2.3.2</a></td><td rowspan="2">Gingerbread</td>    <td>9</td><td>0.5%</td></tr>
 <tr><td><a href="{@docRoot}sdk/android-2.3.3.html">Android 2.3.3 -<br/>
-      Android 2.3.7</a></td><!-- Gingerbread -->                                       <td>10</td><td>58.1%</td></tr>
+      Android 2.3.7</a></td><!-- Gingerbread -->                                       <td>10</td><td>61.5%</td></tr>
 <tr><td><a href="{@docRoot}sdk/android-3.0.html">Android 3.0</a></td>
                                                    <td rowspan="3">Honeycomb</td>      <td>11</td><td>0.1%</td></tr>
-<tr><td><a href="{@docRoot}sdk/android-3.1.html">Android 3.1</a></td><!-- Honeycomb --><td>12</td><td>1.4%</td></tr>
-<tr><td><a href="{@docRoot}sdk/android-3.2.html">Android 3.2</a></td><!-- Honeycomb --><td>13</td><td>1.9%</td></tr> 
+<tr><td><a href="{@docRoot}sdk/android-3.1.html">Android 3.1</a></td><!-- Honeycomb --><td>12</td><td>1.1%</td></tr>
+<tr><td><a href="{@docRoot}sdk/android-3.2.html">Android 3.2</a></td><!-- Honeycomb --><td>13</td><td>2.1%</td></tr> 
 <tr><td><a href="{@docRoot}sdk/android-4.0.html">Android 4.0 -<br/>
                                                Android 4.0.2</a></td>
-                                                <td rowspan="2">Ice Cream Sandwich</td><td>14</td><td>0.3%</td></tr> 
-<tr><td><a href="{@docRoot}sdk/android-4.0.3.html">Android 4.0.3</a></td><!-- ICS     --><td>15</td><td>0.7%</td></tr> 
+                                                <td rowspan="2">Ice Cream Sandwich</td><td>14</td><td>0.4%</td></tr> 
+<tr><td><a href="{@docRoot}sdk/android-4.0.3.html">Android 4.0.3</a></td><!-- ICS     --><td>15</td><td>1.2%</td></tr> 
 </table>
 
-<p><em>Data collected during a 14-day period ending on February 1, 2012</em></p>
+<p><em>Data collected during a 14-day period ending on March 5, 2012</em></p>
 <!--
 <p style="font-size:.9em">* <em>Other: 0.1% of devices running obsolete versions</em></p>
 -->
@@ -108,9 +108,9 @@
 <div class="dashboard-panel">
 
 <img alt="" height="250" width="660" style="padding:5px;background:#fff"
-src="http://chart.apis.google.com/chart?&cht=lc&chs=660x250&chxt=x,x,y,r&chxr=0,0,12|1,0,12|2,0,100|3,0,100&chxl=0%3A%7C08/01%7C08/15%7C09/01%7C09/15%7C10/01%7C10/15%7C11/01%7C11/15%7C12/01%7C12/15%7C01/01%7C01/15%7C02/01%7C1%3A%7C2011%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C2012%7C%7C2012%7C2%3A%7C0%25%7C25%25%7C50%25%7C75%25%7C100%25%7C3%3A%7C0%25%7C25%25%7C50%25%7C75%25%7C100%25&chxp=0,0,1,2,3,4,5,6,7,8,9,10,11,12&chxtc=0,5&chd=t:98.2,98.1,97.9,97.9,97.7,97.6,97.5,99.4,99.4,99.2,98.6,98.4,98.5|96.9,96.9,96.9,96.9,96.6,96.6,96.5,98.6,98.6,98.5,98.0,97.8,97.9|94.9,95.0,95.1,95.2,95.1,95.4,95.2,97.2,97.3,97.3,96.9,96.8,96.9|79.6,80.5,81.8,82.7,83.3,84.4,84.6,87.0,87.7,88.1,88.4,88.8,89.2|23.7,26.9,30.6,34.1,37.8,40.8,43.5,48.4,52.4,55.2,57.9,59.7,61.3|0.0,0.0,0.0,0.0,0.0,0.0,0.0,2.0,2.3,2.6,3.2,3.2,3.3|0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.2,1.3,1.7,1.8,1.9&chm=b,c3df9b,0,1,0|b,b6dc7d,1,2,0|tAndroid%202.1,5b831d,2,0,15,,t::-5|b,aadb5e,2,3,0|tAndroid%202.2,496c13,3,0,15,,t::-5|b,9ddb3d,3,4,0|tAndroid%202.3.3,38540b,4,0,15,,t::-5|b,91da1e,4,5,0|b,80c414,5,6,0|B,6fad0c,6,7,0&chg=7,25&chdl=Android%201.5|Android%201.6|Android%202.1|Android%202.2|Android%202.3.3|Android%203.1|Android%203.2&chco=add274,a0d155,94d134,84c323,73ad18,62960f,507d08" />
+src="http://chart.apis.google.com/chart?&cht=lc&chs=660x250&chxt=x,x,y,r&chxr=0,0,12|1,0,12|2,0,100|3,0,100&chxl=0%3A%7C09/01%7C09/15%7C10/01%7C10/15%7C11/01%7C11/15%7C12/01%7C12/15%7C01/01%7C01/15%7C02/01%7C02/15%7C03/01%7C1%3A%7C2011%7C%7C%7C%7C%7C%7C%7C%7C2012%7C%7C%7C%7C2012%7C2%3A%7C0%25%7C25%25%7C50%25%7C75%25%7C100%25%7C3%3A%7C0%25%7C25%25%7C50%25%7C75%25%7C100%25&chxp=0,0,1,2,3,4,5,6,7,8,9,10,11,12&chxtc=0,5&chd=t:97.9,97.9,97.7,97.6,97.5,99.4,99.4,99.2,98.9,98.8,99.2,98.9,98.9|96.9,96.9,96.6,96.6,96.5,98.6,98.6,98.5,98.3,98.2,98.6,98.4,98.4|95.1,95.2,95.1,95.4,95.2,97.2,97.3,97.3,97.2,97.2,97.6,97.5,97.6|81.8,82.7,83.3,84.4,84.6,87.0,87.7,88.1,88.7,89.2,89.9,90.3,90.8|30.6,34.1,37.8,40.8,43.5,48.4,52.4,55.2,58.2,60.1,62.0,63.7,65.2|0.0,0.0,0.0,0.0,0.0,2.0,2.3,2.6,3.5,3.6,4.0,4.1,4.3|0.0,0.0,0.0,0.0,0.0,1.0,1.2,1.3,2.0,2.2,2.6,3.0,3.2|0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.3,0.4,0.7,0.8,1.1&chm=b,c3df9b,0,1,0|b,b8dc82,1,2,0|tAndroid%202.1,608920,2,0,15,,t::-5|b,addb67,2,3,0|tAndroid%202.2,517617,3,0,15,,t::-5|b,a3db4b,3,4,0|tAndroid%202.3.3,426210,4,0,15,,t::-5|b,98dc2e,4,5,0|b,8cd41b,5,6,0|b,7ec113,6,7,0|B,6fad0c,7,8,0&chg=7,25&chdl=Android%201.5|Android%201.6|Android%202.1|Android%202.2|Android%202.3.3|Android%203.1|Android%203.2|Android%204.0.3&chco=add274,a2d15a,97d13e,8bcb28,7dba1e,6ea715,5f920e,507d08" />
 
-<p><em>Last historical dataset collected during a 14-day period ending on February 1, 2012</em></p>
+<p><em>Last historical dataset collected during a 14-day period ending on March 5, 2012</em></p>
 
 
 </div><!-- end dashboard-panel -->
diff --git a/docs/html/resources/dashboard/screens.jd b/docs/html/resources/dashboard/screens.jd
index ae5cdc7..6c04f7e 100644
--- a/docs/html/resources/dashboard/screens.jd
+++ b/docs/html/resources/dashboard/screens.jd
@@ -60,7 +60,7 @@
 <div class="dashboard-panel">
 
 <img alt="" width="400" height="250"
-src="http://chart.googleapis.com/chart?cht=p&chs=400x250&chco=c4df9b,6fad0c&chl=Xlarge%20/%20mdpi|Large%20/%20ldpi|Large%20/%20mdpi|Normal%20/%20hdpi|Normal%20/%20ldpi|Normal%20/%20mdpi|Normal%20/%20xhdpi|Small%20/%20hdpi|Small%20/%20ldpi&chd=t%3A4.8,0.2,2.9,67.1,0.7,18.4,1.8,2.5,1.6" />
+src="http://chart.googleapis.com/chart?cht=p&chs=400x250&chco=c4df9b,6fad0c&chl=Xlarge%20/%20mdpi|Large%20/%20ldpi|Large%20/%20mdpi|Normal%20/%20hdpi|Normal%20/%20ldpi|Normal%20/%20mdpi|Normal%20/%20xhdpi|Small%20/%20hdpi|Small%20/%20ldpi&chd=t%3A4.9,0.2,2.8,66.4,0.7,18.5,2.5,2.4,1.7" />
 
 <table>
 <tr>
@@ -71,31 +71,31 @@
 <th scope="col">xhdpi</th>
 </tr>
 <tr><th scope="row">small</th> 
-<td>1.6%</td>     <!-- small/ldpi -->
+<td>1.7%</td>     <!-- small/ldpi -->
 <td></td>     <!-- small/mdpi -->
-<td>2.5%</td> <!-- small/hdpi -->
+<td>2.4%</td> <!-- small/hdpi -->
 <td></td>     <!-- small/xhdpi -->
 </tr> 
 <tr><th scope="row">normal</th> 
 <td>0.7%</td>  <!-- normal/ldpi -->
-<td>18.4%</td> <!-- normal/mdpi -->
-<td>67.1%</td> <!-- normal/hdpi -->
-<td>1.8%</td>      <!-- normal/xhdpi -->
+<td>18.5%</td> <!-- normal/mdpi -->
+<td>66.3%</td> <!-- normal/hdpi -->
+<td>2.5%</td>      <!-- normal/xhdpi -->
 </tr> 
 <tr><th scope="row">large</th> 
 <td>0.2%</td>     <!-- large/ldpi -->
-<td>2.9%</td> <!-- large/mdpi -->
+<td>2.8%</td> <!-- large/mdpi -->
 <td></td>     <!-- large/hdpi -->
 <td></td>     <!-- large/xhdpi -->
 </tr> 
 <tr><th scope="row">xlarge</th> 
 <td></td>     <!-- xlarge/ldpi -->
-<td>4.8%</td> <!-- xlarge/mdpi -->
+<td>4.9%</td> <!-- xlarge/mdpi -->
 <td></td>     <!-- xlarge/hdpi -->
 <td></td>     <!-- xlarge/xhdpi -->
 </tr> 
 </table>
 
-<p><em>Data collected during a 7-day period ending on February 1, 2012</em></p>
+<p><em>Data collected during a 7-day period ending on March 4, 2012</em></p>
 </div>
 
diff --git a/docs/html/resources/tutorials/notepad/notepad-ex2.jd b/docs/html/resources/tutorials/notepad/notepad-ex2.jd
index ed06778..1334d7a 100644
--- a/docs/html/resources/tutorials/notepad/notepad-ex2.jd
+++ b/docs/html/resources/tutorials/notepad/notepad-ex2.jd
@@ -87,7 +87,7 @@
     menu callback used for the options menu. Here, we add just one line, which will add a menu item
     to delete a note. Call <code>menu.add()</code> like so:
       <pre>
-public void onCreateContextMenu(Menu menu, View v, ContextMenuInfo menuInfo) {
+public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
     super.onCreateContextMenu(menu, v, menuInfo);
     menu.add(0, DELETE_ID, 0, R.string.menu_delete);
 }</pre>
diff --git a/docs/html/resources/tutorials/views/hello-formstuff.jd b/docs/html/resources/tutorials/views/hello-formstuff.jd
index b9f6c16..1ddd1df 100644
--- a/docs/html/resources/tutorials/views/hello-formstuff.jd
+++ b/docs/html/resources/tutorials/views/hello-formstuff.jd
@@ -91,31 +91,30 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:padding="10dp"
-        android:background="@drawable/android_button" />
+        android:background="@drawable/android_button"
+        android:onClick="onButtonClicked"/>
 </pre>
 	<p>The <code>android:background</code> attribute specifies the drawable resource to use for the
 button background (which, when saved at <code>res/drawable/android.xml</code>, is
 referenced as <code>@drawable/android</code>). This replaces the normal background image
-used for buttons throughout the system. In order for the drawable to change its image based on
-the button state, the image must be applied to the background.</p>
+applied by the system with the drawable created above, which changes its image based on
+the button state.</p>
+    <p>The attribute <code>android:onClick</code> specifies the name of a method in your activity 
+that the system should call when the user clicks the button. You'll create that method next.</p>
 </li>
 
 <li>To make the button do something when pressed, add the following
-code at the end of the {@link android.app.Activity#onCreate(Bundle) onCreate()} method:
+method inside your {@link android.app.Activity} class:
 <pre>
-final Button button = (Button) findViewById(R.id.button);
-button.setOnClickListener(new OnClickListener() {
-    public void onClick(View v) {
-        // Perform action on clicks
-        Toast.makeText(HelloFormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
-    }
-});
+public void onButtonClicked(View v) {
+    // Do something when the button is clicked
+    Toast.makeText(HelloFormStuff.this, "Button clicked", Toast.LENGTH_SHORT).show();
+}
 </pre>
-<p>This captures the {@link android.widget.Button} from the layout, then adds an {@link
-android.view.View.OnClickListener}. The {@link android.view.View.OnClickListener}
-must implement the {@link android.view.View.OnClickListener#onClick(View)} callback method, which
-defines the action to be made when the button is clicked. In this example, a
-{@link android.widget.Toast} message will be displayed.</p>
+<p>When you specify this kind of method, which is used in your layout file with the {@code
+android:onClick} attribute, the method must be <code>public</code>, have a <code>void</code> return
+value, and accept a single {@code android.view.View} parameter. When the system calls this method,
+it passes the {@code android.view.View} that was clicked.</p>
 </li>
 <li>Now run the application.</li>
 </ol>
@@ -183,34 +182,33 @@
     &lt;CheckBox android:id="@+id/checkbox"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="check it out" />
+        android:text="check it out"
+        android:onClick="onCheckboxClicked"/>
 </pre>
+    <p>The attribute <code>android:onClick</code> specifies the name of a method in your activity 
+that the system should call when the user clicks the check box. You'll create that method next.</p>
 </li>
-<li>To do something when the state is changed, add the following code
-to the end of the {@link android.app.Activity#onCreate(Bundle) onCreate()} method:
+<li>To do something when the state is changed, add the following method inside your {@link
+android.app.Activity} class:</p>
+
 <pre>
-final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
-checkbox.setOnClickListener(new OnClickListener() {
-    public void onClick(View v) {
-        // Perform action on clicks, depending on whether it's now checked
-        if (((CheckBox) v).isChecked()) {
-            Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
-        } else {
-            Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
-        }
+public void onCheckboxClicked(View v) {
+    // Perform action on clicks, depending on whether it's now checked
+    if (((CheckBox) v).isChecked()) {
+        Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
+    } else {
+        Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
     }
-});
+}
 </pre>
-<p>This captures the {@link android.widget.CheckBox} element from the layout, then adds an {@link
-android.view.View.OnClickListener}. The {@link android.view.View.OnClickListener} must implement the
-{@link android.view.View.OnClickListener#onClick(View)} callback method, which
-defines the action to be made when the checkbox is clicked. When clicked, {@link
-android.widget.CompoundButton#isChecked()} is called to check the new state of the check box. If it
-has been checked, then a {@link android.widget.Toast} displays the message "Selected", otherwise it
-displays "Not selected". Note that the {@link android.view.View} object that is passed in the {@link
-android.view.View.OnClickListener#onClick(View)} callback must be cast to a {@link
-android.widget.CheckBox} because the {@link android.widget.CompoundButton#isChecked()} method is
-not defined by the parent {@link android.view.View} class. The {@link android.widget.CheckBox}
+
+<p>When you specify this kind of method, which is used in your layout file with the {@code
+android:onClick}
+attribute, the method must be <code>public</code>, have a <code>void</code> return value, and
+accept a single {@code android.view.View} parameter. When the system calls this method, it
+passes the {@code android.view.View} that was clicked. In this example, the {@code
+android.view.View} is cast to a {@link android.widget.CheckBox} to determine whether the widget
+has been checked or unchecked. The {@link android.widget.CheckBox} widget
 handles its own state changes, so you only need to query the current state.</p>
 </li>
 <li>Run it.</li>
@@ -240,44 +238,44 @@
       &lt;RadioButton android:id="@+id/radio_red"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
-          android:text="Red" />
+          android:text="Red"
+          android:onClick="onRadioButtonClicked"/>
       &lt;RadioButton android:id="@+id/radio_blue"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
-          android:text="Blue" />
+          android:text="Blue"
+          android:onClick="onRadioButtonClicked"/>
     &lt;/RadioGroup>
 </pre>
 <p>It's important that the {@link android.widget.RadioButton}s are grouped together by the {@link
 android.widget.RadioGroup} element so that no more than one can be selected at a time. This logic
 is automatically handled by the Android system. When one {@link android.widget.RadioButton} within
 a group is selected, all others are automatically deselected.</p>
+    <p>The attribute <code>android:onClick</code> specifies the name of a method in your activity 
+that the system should call when the user clicks the radio button. You'll create that method
+next.</p>
 </li>
 
-<li>To do something when each {@link android.widget.RadioButton} is selected, you need an
-{@link android.view.View.OnClickListener}. In this case, you want the listener to be re-usable, so
-add the following code to create a new member in the <code>HelloFormStuff</code> Activity:
+<li>To do something when each {@link android.widget.RadioButton} is selected, add the following
+method inside your {@link android.app.Activity} class:</p>
+
 <pre>
-private OnClickListener radio_listener = new OnClickListener() {
-    public void onClick(View v) {
-        // Perform action on clicks
-        RadioButton rb = (RadioButton) v;
-        Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
-    }
-};
+public void onRadioButtonClicked(View v) {
+    // Perform action on clicks
+    RadioButton rb = (RadioButton) v;
+    Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
+}
 </pre>
-<p>First, the {@link android.view.View} that is passed to the {@link
-android.view.View.OnClickListener#onClick(View)} method is cast into a RadioButton. Then a
-{@link android.widget.Toast} message displays the selected radio button's text.</p>
-<li>Now, at the bottom of the {@link android.app.Activity#onCreate(Bundle) onCreate()} method, add
-the following:
-<pre>
-  final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
-  final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
-  radio_red.setOnClickListener(radio_listener);
-  radio_blue.setOnClickListener(radio_listener);
-</pre>
-<p>This captures each of the {@link android.widget.RadioButton}s from the layout and adds the
-newly-created {@link android.view.View.OnClickListener} to each.</p>
+
+<p>When you specify this kind of method, which is used in your layout file with the {@code
+android:onClick}
+attribute, the method must be <code>public</code>, have a <code>void</code> return value, and
+accept a single {@code android.view.View} parameter. When the system calls this method, it
+passes the {@code android.view.View} that was clicked.</p>
+<p>Because each {@link android.widget.RadioButton} widget is grouped into a {@link
+android.widget.RadioGroup}, each widget handles its own state changes when a new button is
+selected.</p>
+</li>
 <li>Run the application.</li>
 </ol>
 
@@ -303,31 +301,35 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textOn="Vibrate on"
-        android:textOff="Vibrate off"/>
+        android:textOff="Vibrate off"
+        android:onClick="onToggleClicked"/>
 </pre>
   <p>The attributes <code>android:textOn</code> and <code>android:textOff</code> specify the text
 for the button when the button has been toggled on or off. The default values are "ON" and
 "OFF".</p>
+    <p>The attribute <code>android:onClick</code> specifies the name of a method in your activity 
+that the system should call when the user clicks the button. You'll create that method next.</p>
 </li>
-<li>To do something when the state is changed, add the following code
-to the end of the {@link android.app.Activity#onCreate(Bundle) onCreate()} method:
+<li>To do something when the user clicks the button, add the following
+method inside your {@link android.app.Activity} class:</p>
+
 <pre>
-final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
-togglebutton.setOnClickListener(new OnClickListener() {
-    public void onClick(View v) {
-        // Perform action on clicks
-        if (togglebutton.isChecked()) {
-            Toast.makeText(HelloFormStuff.this, "Checked", Toast.LENGTH_SHORT).show();
-        } else {
-            Toast.makeText(HelloFormStuff.this, "Not checked", Toast.LENGTH_SHORT).show();
-        }
+public void onToggleClicked(View v) {
+    // Perform action on clicks
+    if (((ToggleButton) v).isChecked()) {
+        Toast.makeText(HelloFormStuff.this, "Toggle on", Toast.LENGTH_SHORT).show();
+    } else {
+        Toast.makeText(HelloFormStuff.this, "Toggle off", Toast.LENGTH_SHORT).show();
     }
-});
+}
 </pre>
-<p>This captures the {@link android.widget.ToggleButton} element from the layout, then adds an
-{@link android.view.View.OnClickListener}. The {@link android.view.View.OnClickListener} must
-implement the {@link android.view.View.OnClickListener#onClick(View)} callback method, which
-defines the action to perform when the button is clicked. In this example, the callback
+
+<p>When you specify this kind of method, which is used in your layout file with the {@code
+android:onClick}
+attribute, the method must be <code>public</code>, have a <code>void</code> return value, and
+accept a single {@code android.view.View} parameter. When the system calls this method, it
+passes the {@code android.view.View} that was clicked.</p>
+<p>In this example, the callback
 method checks the new state of the button, then shows a {@link android.widget.Toast} message that
 indicates the current state.</p>
 
diff --git a/docs/html/resources/tutorials/views/hello-mapview.jd b/docs/html/resources/tutorials/views/hello-mapview.jd
index ac5e826..7a0bedf 100644
--- a/docs/html/resources/tutorials/views/hello-mapview.jd
+++ b/docs/html/resources/tutorials/views/hello-mapview.jd
@@ -208,7 +208,7 @@
   new class constructor:
 <pre>
 public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
-  super(defaultMarker);
+  super(boundCenterBottom(defaultMarker));
   mContext = context;
 }
 </pre>
diff --git a/docs/html/sitemap.txt b/docs/html/sitemap.txt
index cfbda2b..958fe56 100644
--- a/docs/html/sitemap.txt
+++ b/docs/html/sitemap.txt
@@ -108,7 +108,7 @@
 http://developer.android.com/guide/topics/testing/contentprovider_testing.html
 http://developer.android.com/guide/topics/testing/service_testing.html
 http://developer.android.com/guide/topics/testing/what_to_test.html
-http://developer.android.com/guide/publishing/licensing.html
+http://developer.android.com/guide/market/licensing/index.html
 http://developer.android.com/guide/market/billing/index.html
 http://developer.android.com/guide/market/billing/billing_about.html
 http://developer.android.com/guide/market/billing/billing_overview.html
diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp
index cf58177..191648c 100644
--- a/drm/jni/android_drm_DrmManagerClient.cpp
+++ b/drm/jni/android_drm_DrmManagerClient.cpp
@@ -57,29 +57,16 @@
 };
 
 String8 Utility::getStringValue(JNIEnv* env, jobject object, const char* fieldName) {
-    String8 dataString("");
-
     /* Look for the instance field with the name fieldName */
     jfieldID fieldID
         = env->GetFieldID(env->GetObjectClass(object), fieldName , "Ljava/lang/String;");
 
     if (NULL != fieldID) {
         jstring valueString = (jstring) env->GetObjectField(object, fieldID);
-
-        if (NULL != valueString && valueString != env->NewStringUTF("")) {
-            char* bytes = const_cast< char* > (env->GetStringUTFChars(valueString, NULL));
-
-            const int length = strlen(bytes) + 1;
-            char *data = new char[length];
-            strncpy(data, bytes, length);
-            dataString = String8(data);
-
-            env->ReleaseStringUTFChars(valueString, bytes);
-            delete [] data; data = NULL;
-        } else {
-            ALOGV("Failed to retrieve the data from the field %s", fieldName);
-        }
+        return Utility::getStringValue(env, valueString);
     }
+
+    String8 dataString("");
     return dataString;
 }
 
@@ -102,24 +89,16 @@
 
 char* Utility::getByteArrayValue(
             JNIEnv* env, jobject object, const char* fieldName, int* dataLength) {
-    char* data = NULL;
+
     *dataLength = 0;
 
     jfieldID fieldID = env->GetFieldID(env->GetObjectClass(object), fieldName , "[B");
 
     if (NULL != fieldID) {
         jbyteArray byteArray = (jbyteArray) env->GetObjectField(object, fieldID);
-        if (NULL != byteArray) {
-            jint length = env->GetArrayLength(byteArray);
-
-            *dataLength = length;
-            if (0 < *dataLength) {
-                data = new char[length];
-                env->GetByteArrayRegion(byteArray, (jint)0, length, (jbyte *) data);
-            }
-        }
+        return Utility::getByteArrayValue(env, byteArray, dataLength);
     }
-    return data;
+    return NULL;
 }
 
 char* Utility::getByteArrayValue(JNIEnv* env, jbyteArray byteArray, int* dataLength) {
@@ -419,7 +398,7 @@
                                 Utility::getStringValue(env, contentPath));
     }
 
-    delete mData; mData = NULL;
+    delete[] mData; mData = NULL;
     ALOGV("saveRights - Exit");
     return result;
 }
@@ -510,7 +489,7 @@
                 processedData, env->NewStringUTF(pDrmInfoStatus->mimeType.string()));
     }
 
-    delete mData; mData = NULL;
+    delete[] mData; mData = NULL;
     delete pDrmInfoStatus; pDrmInfoStatus = NULL;
 
     ALOGV("processDrmInfo - Exit");
@@ -675,7 +654,7 @@
                              statusCode, dataArray, pDrmConvertedStatus->offset);
     }
 
-    delete mData; mData = NULL;
+    delete[] mData; mData = NULL;
     delete pDrmConvertedStatus; pDrmConvertedStatus = NULL;
 
     ALOGV("convertData - Exit");
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index b0c581a..4fbeb38 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -299,7 +299,7 @@
 
     /* obtains a buffer of "frameCount" frames. The buffer must be
      * filled entirely. If the track is stopped, obtainBuffer() returns
-     * STOPPED instead of NO_ERROR as long as there are buffers availlable,
+     * STOPPED instead of NO_ERROR as long as there are buffers available,
      * at which point NO_MORE_BUFFERS is returned.
      * Buffers will be returned until the pool (buffercount())
      * is exhausted, at which point obtainBuffer() will either block
@@ -317,13 +317,14 @@
 
 
     /* As a convenience we provide a read() interface to the audio buffer.
-     * This is implemented on top of lockBuffer/unlockBuffer.
+     * This is implemented on top of obtainBuffer/releaseBuffer.
      */
             ssize_t     read(void* buffer, size_t size);
 
-    /* Return the amount of input frames lost in the audio driver since the last call of this function.
-     * Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call.
-     * Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers.
+    /* Return the amount of input frames lost in the audio driver since the last call of this
+     * function.  Audio driver is expected to reset the value to 0 and restart counting upon
+     * returning the current value by this function call.  Such loss typically occurs when the
+     * user space process is blocked longer than the capacity of audio driver buffers.
      * Unit: the number of input audio frames
      */
             unsigned int  getInputFramesLost() const;
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp
index d761680..f0641e0 100644
--- a/libs/gui/BufferQueue.cpp
+++ b/libs/gui/BufferQueue.cpp
@@ -828,6 +828,7 @@
         buffer->mTransform = mSlots[buf].mTransform;
         buffer->mScalingMode = mSlots[buf].mScalingMode;
         buffer->mFrameNumber = mSlots[buf].mFrameNumber;
+        buffer->mTimestamp = mSlots[buf].mTimestamp;
         buffer->mBuf = buf;
         mSlots[buf].mAcquireCalled = true;
 
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index 0ef8469..123695a 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -20,6 +20,7 @@
 #include <utils/String8.h>
 
 #include "Caches.h"
+#include "DisplayListRenderer.h"
 #include "Properties.h"
 #include "LayerRenderer.h"
 
@@ -199,6 +200,13 @@
         LayerRenderer::destroyLayer(layer);
     }
     mLayerGarbage.clear();
+
+    count = mDisplayListGarbage.size();
+    for (size_t i = 0; i < count; i++) {
+        DisplayList* displayList = mDisplayListGarbage.itemAt(i);
+        delete displayList;
+    }
+    mDisplayListGarbage.clear();
 }
 
 void Caches::deleteLayerDeferred(Layer* layer) {
@@ -206,6 +214,11 @@
     mLayerGarbage.push(layer);
 }
 
+void Caches::deleteDisplayListDeferred(DisplayList* displayList) {
+    Mutex::Autolock _l(mGarbageLock);
+    mDisplayListGarbage.push(displayList);
+}
+
 void Caches::flush(FlushMode mode) {
     FLUSH_LOGD("Flushing caches (mode %d)", mode);
 
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index f8c7bcc..65ff9ad 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -90,6 +90,8 @@
 // Caches
 ///////////////////////////////////////////////////////////////////////////////
 
+class DisplayList;
+
 class ANDROID_API Caches: public Singleton<Caches> {
     Caches();
 
@@ -141,6 +143,11 @@
      */
     void deleteLayerDeferred(Layer* layer);
 
+    /*
+     * Can be used to delete a display list from a non EGL thread.
+     */
+    void deleteDisplayListDeferred(DisplayList* layer);
+
     /**
      * Binds the VBO used to render simple textured quads.
      */
@@ -269,6 +276,7 @@
 
     mutable Mutex mGarbageLock;
     Vector<Layer*> mLayerGarbage;
+    Vector<DisplayList*> mDisplayListGarbage;
 
     DebugLevel mDebugLevel;
     bool mInitialized;
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index babfd04..d9b0e5a 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -101,6 +101,13 @@
     clearResources();
 }
 
+void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) {
+    if (displayList) {
+        DISPLAY_LIST_LOGD("Deferring display list destruction");
+        Caches::getInstance().deleteDisplayListDeferred(displayList);
+    }
+}
+
 void DisplayList::clearResources() {
     sk_free((void*) mReader.base());
 
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 96b87cc..02f8438 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -119,16 +119,16 @@
 
     static const char* OP_NAMES[];
 
-    void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
-
     ANDROID_API size_t getSize();
+    ANDROID_API static void destroyDisplayListDeferred(DisplayList* displayList);
+    ANDROID_API static void outputLogBuffer(int fd);
+
+    void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
 
     bool replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, uint32_t level = 0);
 
     void output(OpenGLRenderer& renderer, uint32_t level = 0);
 
-    ANDROID_API static void outputLogBuffer(int fd);
-
     void setRenderable(bool renderable) {
         mIsRenderable = renderable;
     }
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index ee6ef1a..f243177 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -37,6 +37,10 @@
 // Layers
 ///////////////////////////////////////////////////////////////////////////////
 
+// Forward declarations
+class OpenGLRenderer;
+class DisplayList;
+
 /**
  * A layer has dimensions and is backed by an OpenGL texture or FBO.
  */
@@ -51,6 +55,9 @@
         texture.width = layerWidth;
         texture.height = layerHeight;
         colorFilter = NULL;
+        deferredUpdateScheduled = false;
+        renderer = NULL;
+        displayList = NULL;
     }
 
     ~Layer() {
@@ -77,6 +84,15 @@
         regionRect.translate(layer.left, layer.top);
     }
 
+    void updateDeferred(OpenGLRenderer* renderer, DisplayList* displayList,
+            int left, int top, int right, int bottom) {
+        this->renderer = renderer;
+        this->displayList = displayList;
+        const Rect r(left, top, right, bottom);
+        dirtyRect.unionWith(r);
+        deferredUpdateScheduled = true;
+    }
+
     inline uint32_t getWidth() {
         return texture.width;
     }
@@ -234,6 +250,14 @@
     uint16_t* meshIndices;
     GLsizei meshElementCount;
 
+    /**
+     * Used for deferred updates.
+     */
+    bool deferredUpdateScheduled;
+    OpenGLRenderer* renderer;
+    DisplayList* displayList;
+    Rect dirtyRect;
+
 private:
     /**
      * Name of the FBO used to render the layer. If the name is 0
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index e3148e8..339ae0a 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2364,6 +2364,24 @@
         return;
     }
 
+    if (layer->deferredUpdateScheduled && layer->renderer && layer->displayList) {
+        OpenGLRenderer* renderer = layer->renderer;
+        Rect& dirty = layer->dirtyRect;
+
+        interrupt();
+        renderer->setViewport(layer->layer.getWidth(), layer->layer.getHeight());
+        renderer->prepareDirty(dirty.left, dirty.top, dirty.right, dirty.bottom, !layer->isBlend());
+        renderer->drawDisplayList(layer->displayList, layer->getWidth(), layer->getHeight(),
+                dirty, DisplayList::kReplayFlag_ClipChildren);
+        renderer->finish();
+        resume();
+
+        dirty.setEmpty();
+        layer->deferredUpdateScheduled = false;
+        layer->renderer = NULL;
+        layer->displayList = NULL;
+    }
+
     mCaches.activeTexture(0);
 
     int alpha;
diff --git a/libs/rs/driver/rsdGL.cpp b/libs/rs/driver/rsdGL.cpp
index 1b12235..63bf7cc 100644
--- a/libs/rs/driver/rsdGL.cpp
+++ b/libs/rs/driver/rsdGL.cpp
@@ -41,6 +41,8 @@
 #include "rsdVertexArray.h"
 #include "rsdFrameBufferObj.h"
 
+#include <gui/SurfaceTextureClient.h>
+
 using namespace android;
 using namespace android::renderscript;
 
@@ -171,15 +173,12 @@
     }
 }
 
-bool rsdGLInit(const Context *rsc) {
-    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
+void getConfigData(const Context *rsc,
+                   EGLint *configAttribs, size_t configAttribsLen,
+                   uint32_t numSamples) {
+    memset(configAttribs, 0, configAttribsLen*sizeof(*configAttribs));
 
-    dc->gl.egl.numConfigs = -1;
-    EGLint configAttribs[128];
     EGLint *configAttribsPtr = configAttribs;
-    EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
-
-    memset(configAttribs, 0, sizeof(configAttribs));
 
     configAttribsPtr[0] = EGL_SURFACE_TYPE;
     configAttribsPtr[1] = EGL_WINDOW_BIT;
@@ -219,8 +218,25 @@
         configAttribsPtr += 2;
     }
 
+    if (numSamples > 1) {
+        configAttribsPtr[0] = EGL_SAMPLE_BUFFERS;
+        configAttribsPtr[1] = 1;
+        configAttribsPtr[2] = EGL_SAMPLES;
+        configAttribsPtr[3] = numSamples;
+        configAttribsPtr += 4;
+    }
+
     configAttribsPtr[0] = EGL_NONE;
-    rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
+    rsAssert(configAttribsPtr < (configAttribs + configAttribsLen));
+}
+
+bool rsdGLInit(const Context *rsc) {
+    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
+
+    dc->gl.egl.numConfigs = -1;
+
+    EGLint configAttribs[128];
+    EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
 
     ALOGV("%p initEGL start", rsc);
     rsc->setWatchdogGL("eglGetDisplay", __LINE__, __FILE__);
@@ -235,8 +251,18 @@
 
     EGLint numConfigs = -1, n = 0;
     rsc->setWatchdogGL("eglChooseConfig", __LINE__, __FILE__);
-    ret = eglChooseConfig(dc->gl.egl.display, configAttribs, 0, 0, &numConfigs);
-    checkEglError("eglGetConfigs", ret);
+
+    // Try minding a multisample config that matches the user request
+    uint32_t minSample = rsc->mUserSurfaceConfig.samplesMin;
+    uint32_t prefSample = rsc->mUserSurfaceConfig.samplesPref;
+    for (uint32_t sampleCount = prefSample; sampleCount >= minSample; sampleCount--) {
+        getConfigData(rsc, configAttribs, (sizeof(configAttribs) / sizeof(EGLint)), sampleCount);
+        ret = eglChooseConfig(dc->gl.egl.display, configAttribs, 0, 0, &numConfigs);
+        checkEglError("eglGetConfigs", ret);
+        if (numConfigs > 0) {
+            break;
+        }
+    }
 
     eglSwapInterval(dc->gl.egl.display, 0);
 
@@ -299,14 +325,15 @@
     }
     gGLContextCount++;
 
+    sp<SurfaceTexture> st(new SurfaceTexture(123));
+    sp<SurfaceTextureClient> stc(new SurfaceTextureClient(st));
+    dc->gl.egl.surfaceDefault = eglCreateWindowSurface(dc->gl.egl.display, dc->gl.egl.config,
+                                                       static_cast<ANativeWindow*>(stc.get()),
+                                                       NULL);
 
-    EGLint pbuffer_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
-    rsc->setWatchdogGL("eglCreatePbufferSurface", __LINE__, __FILE__);
-    dc->gl.egl.surfaceDefault = eglCreatePbufferSurface(dc->gl.egl.display, dc->gl.egl.config,
-                                                        pbuffer_attribs);
-    checkEglError("eglCreatePbufferSurface");
+    checkEglError("eglCreateWindowSurface");
     if (dc->gl.egl.surfaceDefault == EGL_NO_SURFACE) {
-        ALOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
+        ALOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
         rsdGLShutdown(rsc);
         rsc->setWatchdogGL(NULL, 0, NULL);
         return false;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 8f7b35c..b972548 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1919,10 +1919,10 @@
 
 AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output,
         audio_io_handle_t id, uint32_t device, type_t type)
-    :   PlaybackThread(audioFlinger, output, id, device, type),
-        mAudioMixer(new AudioMixer(mFrameCount, mSampleRate)),
-        mPrevMixerStatus(MIXER_IDLE)
+    :   PlaybackThread(audioFlinger, output, id, device, type)
 {
+    mAudioMixer = new AudioMixer(mFrameCount, mSampleRate);
+    mPrevMixerStatus = MIXER_IDLE;
     // FIXME - Current mixer implementation only supports stereo output
     if (mChannelCount == 1) {
         ALOGE("Invalid audio hardware channel count");
@@ -1991,44 +1991,67 @@
     }
 }
 
-bool AudioFlinger::MixerThread::threadLoop()
+bool AudioFlinger::PlaybackThread::threadLoop()
 {
-    // DirectOutputThread has single trackToRemove instead of Vector
+    // MIXER || DUPLICATING
     Vector< sp<Track> > tracksToRemove;
-    // DirectOutputThread has activeTrack here
-    nsecs_t standbyTime = systemTime();
-    size_t mixBufferSize = mFrameCount * mFrameSize;
 
+    // DIRECT
+    sp<Track> trackToRemove;
+
+    standbyTime = systemTime();
+    mixBufferSize = mFrameCount * mFrameSize;
+
+    // MIXER
     // FIXME: Relaxed timing because of a certain device that can't meet latency
     // Should be reduced to 2x after the vendor fixes the driver issue
     // increase threshold again due to low power audio mode. The way this warning threshold is
     // calculated and its usefulness should be reconsidered anyway.
     nsecs_t maxPeriod = seconds(mFrameCount) / mSampleRate * 15;
     nsecs_t lastWarning = 0;
-    bool longStandbyExit = false;
+if (mType == MIXER) {
+    longStandbyExit = false;
+}
 
-    uint32_t activeSleepTime = activeSleepTimeUs();
-    uint32_t idleSleepTime = idleSleepTimeUs();
-    uint32_t sleepTime = idleSleepTime;
+    // DUPLICATING
+    // FIXME could this be made local to while loop?
+    writeFrames = 0;
 
-    uint32_t sleepTimeShift = 0;
+    activeSleepTime = activeSleepTimeUs();
+    idleSleepTime = idleSleepTimeUs();
+    sleepTime = idleSleepTime;
+
+if (mType == MIXER) {
+    sleepTimeShift = 0;
+}
+
+    // MIXER
     CpuStats cpuStats;
 
-    // DirectOutputThread has shorter standbyDelay
+    // DIRECT
+if (mType == DIRECT) {
+    // use shorter standby delay as on normal output to release
+    // hardware resources as soon as possible
+    standbyDelay = microseconds(activeSleepTime*2);
+}
 
     acquireWakeLock();
 
     while (!exitPending())
     {
+if (mType == MIXER) {
         cpuStats.sample();
-
-        // DirectOutputThread has rampVolume, leftVol, rightVol
+}
 
         Vector< sp<EffectChain> > effectChains;
 
         processConfigEvents();
 
-        mixer_state mixerStatus = MIXER_IDLE;
+if (mType == DIRECT) {
+        activeTrack.clear();
+}
+
+        mixerStatus = MIXER_IDLE;
         { // scope for mLock
 
             Mutex::Autolock _l(mLock);
@@ -2036,23 +2059,46 @@
             if (checkForNewParameters_l()) {
                 mixBufferSize = mFrameCount * mFrameSize;
 
+if (mType == MIXER) {
                 // FIXME: Relaxed timing because of a certain device that can't meet latency
                 // Should be reduced to 2x after the vendor fixes the driver issue
                 // increase threshold again due to low power audio mode. The way this warning
                 // threshold is calculated and its usefulness should be reconsidered anyway.
                 maxPeriod = seconds(mFrameCount) / mSampleRate * 15;
+}
+
+if (mType == DUPLICATING) {
+                updateWaitTime();
+}
 
                 activeSleepTime = activeSleepTimeUs();
                 idleSleepTime = idleSleepTimeUs();
-                // DirectOutputThread updates standbyDelay also
+
+if (mType == DIRECT) {
+                standbyDelay = microseconds(activeSleepTime*2);
+}
+
             }
 
+if (mType == DUPLICATING) {
+#if 0   // see earlier FIXME
+            // Now that this is a field instead of local variable,
+            // clear it so it is empty the first time through the loop,
+            // and later an assignment could combine the clear with the loop below
+            outputTracks.clear();
+#endif
+            for (size_t i = 0; i < mOutputTracks.size(); i++) {
+                outputTracks.add(mOutputTracks[i]);
+            }
+}
+
             // put audio hardware into standby after short delay
             if (CC_UNLIKELY((!mActiveTracks.size() && systemTime() > standbyTime) ||
                         mSuspended > 0)) {
                 if (!mStandby) {
-                    ALOGV("Audio hardware entering standby, mixer %p, suspend count %u", this, mSuspended);
-                    mOutput->stream->common.standby(&mOutput->stream->common);
+
+                    threadLoop_standby();
+
                     mStandby = true;
                     mBytesWritten = 0;
                 }
@@ -2061,6 +2107,10 @@
                     // we're about to wait, flush the binder command buffer
                     IPCThreadState::self()->flushCommands();
 
+if (mType == DUPLICATING) {
+                    outputTracks.clear();
+}
+
                     if (exitPending()) break;
 
                     releaseWakeLock_l();
@@ -2070,17 +2120,41 @@
                     ALOGV("Thread %p type %d TID %d waking up", this, mType, gettid());
                     acquireWakeLock_l();
 
+if (mType == MIXER || mType == DUPLICATING) {
                     mPrevMixerStatus = MIXER_IDLE;
+}
+
                     checkSilentMode_l();
 
+if (mType == MIXER || mType == DUPLICATING) {
                     standbyTime = systemTime() + mStandbyTimeInNsecs;
+}
+
+if (mType == DIRECT) {
+                    standbyTime = systemTime() + standbyDelay;
+}
+
                     sleepTime = idleSleepTime;
+
+if (mType == MIXER) {
                     sleepTimeShift = 0;
+}
+
                     continue;
                 }
             }
 
+// FIXME merge these
+if (mType == MIXER || mType == DUPLICATING) {
             mixerStatus = prepareTracks_l(&tracksToRemove);
+}
+if (mType == DIRECT) {
+            mixerStatus = threadLoop_prepareTracks_l(trackToRemove);
+            // see FIXME in AudioFlinger.h
+            if (mixerStatus == MIXER_CONTINUE) {
+                continue;
+            }
+}
 
             // prevent any changes in effect chain list and in each effect chain
             // during mixing and effect process as the audio buffers could be deleted
@@ -2088,7 +2162,130 @@
             lockEffectChains_l(effectChains);
         }
 
+if (mType == DIRECT) {
+        // For DirectOutputThread, this test is equivalent to "activeTrack != 0"
+}
+
         if (CC_LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
+            threadLoop_mix();
+        } else {
+            threadLoop_sleepTime();
+        }
+
+        if (mSuspended > 0) {
+            sleepTime = suspendSleepTimeUs();
+        }
+
+        // only process effects if we're going to write
+        if (sleepTime == 0) {
+
+            if (mixerStatus == MIXER_TRACKS_READY) {
+
+                // Non-trivial for DIRECT only
+                applyVolume();
+
+            }
+
+            for (size_t i = 0; i < effectChains.size(); i ++) {
+                effectChains[i]->process_l();
+            }
+        }
+
+        // enable changes in effect chain
+        unlockEffectChains(effectChains);
+
+        // sleepTime == 0 means we must write to audio hardware
+        if (sleepTime == 0) {
+
+            threadLoop_write();
+
+if (mType == MIXER) {
+            // write blocked detection
+            nsecs_t now = systemTime();
+            nsecs_t delta = now - mLastWriteTime;
+            if (!mStandby && delta > maxPeriod) {
+                mNumDelayedWrites++;
+                if ((now - lastWarning) > kWarningThrottleNs) {
+                    ALOGW("write blocked for %llu msecs, %d delayed writes, thread %p",
+                            ns2ms(delta), mNumDelayedWrites, this);
+                    lastWarning = now;
+                }
+                // FIXME this is broken: longStandbyExit should be handled out of the if() and with
+                // a different threshold. Or completely removed for what it is worth anyway...
+                if (mStandby) {
+                    longStandbyExit = true;
+                }
+            }
+}
+
+            mStandby = false;
+        } else {
+            usleep(sleepTime);
+        }
+
+        // finally let go of removed track(s), without the lock held
+        // since we can't guarantee the destructors won't acquire that
+        // same lock.
+
+// FIXME merge these
+if (mType == MIXER) {
+        tracksToRemove.clear();
+}
+if (mType == DIRECT) {
+        trackToRemove.clear();
+        activeTrack.clear();
+}
+if (mType == DUPLICATING) {
+        tracksToRemove.clear();
+        outputTracks.clear();
+}
+
+        // Effect chains will be actually deleted here if they were removed from
+        // mEffectChains list during mixing or effects processing
+        effectChains.clear();
+
+        // FIXME Note that the above .clear() is no longer necessary since effectChains
+        // is now local to this block, but will keep it for now (at least until merge done).
+    }
+
+if (mType == MIXER || mType == DIRECT) {
+    // put output stream into standby mode
+    if (!mStandby) {
+        mOutput->stream->common.standby(&mOutput->stream->common);
+    }
+}
+if (mType == DUPLICATING) {
+    // for DuplicatingThread, standby mode is handled by the outputTracks
+}
+
+    releaseWakeLock();
+
+    ALOGV("Thread %p type %d exiting", this, mType);
+    return false;
+}
+
+// shared by MIXER and DIRECT, overridden by DUPLICATING
+void AudioFlinger::PlaybackThread::threadLoop_write()
+{
+            // FIXME rewrite to reduce number of system calls
+            mLastWriteTime = systemTime();
+            mInWrite = true;
+            mBytesWritten += mixBufferSize;
+            int bytesWritten = (int)mOutput->stream->write(mOutput->stream, mMixBuffer, mixBufferSize);
+            if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
+            mNumWrites++;
+            mInWrite = false;
+}
+
+// shared by MIXER and DIRECT, overridden by DUPLICATING
+void AudioFlinger::PlaybackThread::threadLoop_standby()
+{
+                    ALOGV("Audio hardware entering standby, mixer %p, suspend count %u", this, mSuspended);
+                    mOutput->stream->common.standby(&mOutput->stream->common);
+}
+
+void AudioFlinger::MixerThread::threadLoop_mix()
+{
             // obtain the presentation timestamp of the next output buffer
             int64_t pts;
             status_t status = INVALID_OPERATION;
@@ -2114,7 +2311,10 @@
             sleepTime = 0;
             standbyTime = systemTime() + mStandbyTimeInNsecs;
             //TODO: delay standby when effects have a tail
-        } else {
+}
+
+void AudioFlinger::MixerThread::threadLoop_sleepTime()
+{
             // If no tracks are ready, sleep once for the duration of an output
             // buffer size, then write 0s to the output
             if (sleepTime == 0) {
@@ -2140,79 +2340,6 @@
                 ALOGV_IF((mBytesWritten == 0 && (mixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)), "anticipated start");
             }
             // TODO add standby time extension fct of effect tail
-        }
-
-        if (mSuspended > 0) {
-            sleepTime = suspendSleepTimeUs();
-        }
-
-        // only process effects if we're going to write
-        if (sleepTime == 0) {
-
-            // DirectOutputThread adds applyVolume here
-
-            for (size_t i = 0; i < effectChains.size(); i ++) {
-                effectChains[i]->process_l();
-            }
-        }
-
-        // enable changes in effect chain
-        unlockEffectChains(effectChains);
-
-        // sleepTime == 0 means we must write to audio hardware
-        if (sleepTime == 0) {
-            // FIXME Only in MixerThread, and rewrite to reduce number of system calls
-            mLastWriteTime = systemTime();
-            mInWrite = true;
-            mBytesWritten += mixBufferSize;
-            int bytesWritten = (int)mOutput->stream->write(mOutput->stream, mMixBuffer, mixBufferSize);
-            if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
-            mNumWrites++;
-            mInWrite = false;
-
-            // Only in MixerThread: start of write blocked detection
-            nsecs_t now = systemTime();
-            nsecs_t delta = now - mLastWriteTime;
-            if (!mStandby && delta > maxPeriod) {
-                mNumDelayedWrites++;
-                if ((now - lastWarning) > kWarningThrottleNs) {
-                    ALOGW("write blocked for %llu msecs, %d delayed writes, thread %p",
-                            ns2ms(delta), mNumDelayedWrites, this);
-                    lastWarning = now;
-                }
-                if (mStandby) {
-                    longStandbyExit = true;
-                }
-            }
-            // end of write blocked detection
-
-            mStandby = false;
-        } else {
-            usleep(sleepTime);
-        }
-
-        // finally let go of removed track(s), without the lock held
-        // since we can't guarantee the destructors won't acquire that
-        // same lock.
-        tracksToRemove.clear();
-
-        // Effect chains will be actually deleted here if they were removed from
-        // mEffectChains list during mixing or effects processing
-        effectChains.clear();
-
-        // FIXME Note that the above .clear() is no longer necessary since effectChains
-        // is now local to this block, but will keep it for now (at least until merge done).
-    }
-
-    // put output stream into standby mode
-    if (!mStandby) {
-        mOutput->stream->common.standby(&mOutput->stream->common);
-    }
-
-    releaseWakeLock();
-
-    ALOGV("Thread %p type %d exiting", this, mType);
-    return false;
 }
 
 // prepareTracks_l() must be called with ThreadBase::mLock held
@@ -2653,7 +2780,7 @@
 {
 }
 
-void AudioFlinger::DirectOutputThread::applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp)
+void AudioFlinger::DirectOutputThread::applyVolume()
 {
     // Do not apply volume on compressed audio
     if (!audio_is_linear_pcm(mFormat)) {
@@ -2672,7 +2799,7 @@
 
     size_t frameCount = mFrameCount;
     int16_t *out = mMixBuffer;
-    if (ramp) {
+    if (rampVolume) {
         if (mChannelCount == 1) {
             int32_t d = ((int32_t)leftVol - (int32_t)mLeftVolShort) << 16;
             int32_t vlInc = d / (int32_t)frameCount;
@@ -2727,103 +2854,19 @@
     mRightVolShort = rightVol;
 }
 
-bool AudioFlinger::DirectOutputThread::threadLoop()
+AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::threadLoop_prepareTracks_l(
+    sp<Track>& trackToRemove
+)
 {
-    // MixerThread has Vector instead of single trackToRemove
-    sp<Track> trackToRemove;
-
-    nsecs_t standbyTime = systemTime();
-    size_t mixBufferSize = mFrameCount * mFrameSize;
-
-    // MixerThread has relaxed timing: maxPeriod, lastWarning, longStandbyExit
-
-    uint32_t activeSleepTime = activeSleepTimeUs();
-    uint32_t idleSleepTime = idleSleepTimeUs();
-    uint32_t sleepTime = idleSleepTime;
-
-    // MixerThread has sleepTimeShift and cpuStats
-
-    // use shorter standby delay as on normal output to release
-    // hardware resources as soon as possible
-    nsecs_t standbyDelay = microseconds(activeSleepTime*2);
-
-    acquireWakeLock();
-
-    while (!exitPending())
-    {
-        // MixerThread has cpuStats.sample()
-
-        bool rampVolume;
-        uint16_t leftVol;
-        uint16_t rightVol;
-
-        Vector< sp<EffectChain> > effectChains;
-
-        processConfigEvents();
-
-        // MixerThread does not have activeTrack here
-        sp<Track> activeTrack;
-
-        mixer_state mixerStatus = MIXER_IDLE;
-        { // scope for the mLock
-
-            Mutex::Autolock _l(mLock);
-
-            if (checkForNewParameters_l()) {
-                mixBufferSize = mFrameCount * mFrameSize;
-
-                // different calculations here
-                standbyDelay = microseconds(activeSleepTime*2);
-
-                activeSleepTime = activeSleepTimeUs();
-                idleSleepTime = idleSleepTimeUs();
-                standbyDelay = microseconds(activeSleepTime*2);
-            }
-
-            // put audio hardware into standby after short delay
-            if (CC_UNLIKELY((!mActiveTracks.size() && systemTime() > standbyTime) ||
-                        mSuspended > 0)) {
-                if (!mStandby) {
-                    ALOGV("Audio hardware entering standby, mixer %p, suspend count %u", this, mSuspended);
-                    mOutput->stream->common.standby(&mOutput->stream->common);
-                    mStandby = true;
-                    mBytesWritten = 0;
-                }
-
-                if (!mActiveTracks.size() && mConfigEvents.isEmpty()) {
-                    // we're about to wait, flush the binder command buffer
-                    IPCThreadState::self()->flushCommands();
-
-                    if (exitPending()) break;
-
-                    releaseWakeLock_l();
-                    // wait until we have something to do...
-                    ALOGV("Thread %p type %d TID %d going to sleep", this, mType, gettid());
-                    mWaitWorkCV.wait(mLock);
-                    ALOGV("Thread %p type %d TID %d waking up", this, mType, gettid());
-                    acquireWakeLock_l();
-
-                    // MixerThread has "mPrevMixerStatus = MIXER_IDLE"
-                    checkSilentMode_l();
-
-                    // MixerThread has different standbyDelay
-                    standbyTime = systemTime() + standbyDelay;
-                    sleepTime = idleSleepTime;
-                    // MixerThread has "sleepTimeShift = 0"
-                    continue;
-                }
-            }
-
-            // MixerThread has "mixerStatus = prepareTracks_l(...)"
-
-            // equivalent to MixerThread's lockEffectChains_l, but without the lock
-            // FIXME - is it OK to omit the lock here?
-            effectChains = mEffectChains;
+// FIXME Temporarily renamed to avoid confusion with the member "mixerStatus"
+mixer_state mixerStatus_ = MIXER_IDLE;
 
             // find out which tracks need to be processed
             if (mActiveTracks.size() != 0) {
                 sp<Track> t = mActiveTracks[0].promote();
-                if (t == 0) continue;
+                // see FIXME in AudioFlinger.h, return MIXER_IDLE might also work
+                if (t == 0) return MIXER_CONTINUE;
+                //if (t == 0) continue;
 
                 Track* const track = t.get();
                 audio_track_cblk_t* cblk = track->cblk();
@@ -2886,9 +2929,9 @@
                         // Delegate volume control to effect in track effect chain if needed
                         // only one effect chain can be present on DirectOutputThread, so if
                         // there is one, the track is connected to it
-                        if (!effectChains.isEmpty()) {
+                        if (!mEffectChains.isEmpty()) {
                             // Do not ramp volume if volume is controlled by effect
-                            if(effectChains[0]->setVolume_l(&vl, &vr)) {
+                            if (mEffectChains[0]->setVolume_l(&vl, &vr)) {
                                 rampVolume = false;
                             }
                         }
@@ -2909,7 +2952,7 @@
                     // reset retry count
                     track->mRetryCount = kMaxTrackRetriesDirect;
                     activeTrack = t;
-                    mixerStatus = MIXER_TRACKS_READY;
+                    mixerStatus_ = MIXER_TRACKS_READY;
                 } else {
                     //ALOGV("track %d u=%08x, s=%08x [NOT READY]", track->name(), cblk->user, cblk->server);
                     if (track->isStopped()) {
@@ -2926,7 +2969,7 @@
                             ALOGV("BUFFER TIMEOUT: remove(%d) from active list", track->name());
                             trackToRemove = track;
                         } else {
-                            mixerStatus = MIXER_TRACKS_ENABLED;
+                            mixerStatus_ = MIXER_TRACKS_ENABLED;
                         }
                     }
                 }
@@ -2935,21 +2978,21 @@
             // remove all the tracks that need to be...
             if (CC_UNLIKELY(trackToRemove != 0)) {
                 mActiveTracks.remove(trackToRemove);
-                if (!effectChains.isEmpty()) {
+                if (!mEffectChains.isEmpty()) {
                     ALOGV("stopping track on chain %p for session Id: %d", effectChains[0].get(),
                             trackToRemove->sessionId());
-                    effectChains[0]->decActiveTrackCnt();
+                    mEffectChains[0]->decActiveTrackCnt();
                 }
                 if (trackToRemove->isTerminated()) {
                     removeTrack_l(trackToRemove);
                 }
             }
 
-            lockEffectChains_l(effectChains);
-       }
+return mixerStatus_;
+}
 
-        // For DirectOutputThread, this test is equivalent to "activeTrack != 0"
-        if (CC_LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
+void AudioFlinger::DirectOutputThread::threadLoop_mix()
+{
             AudioBufferProvider::Buffer buffer;
             size_t frameCount = mFrameCount;
             int8_t *curBuf = (int8_t *)mMixBuffer;
@@ -2968,7 +3011,10 @@
             }
             sleepTime = 0;
             standbyTime = systemTime() + standbyDelay;
-        } else {
+}
+
+void AudioFlinger::DirectOutputThread::threadLoop_sleepTime()
+{
             if (sleepTime == 0) {
                 if (mixerStatus == MIXER_TRACKS_ENABLED) {
                     sleepTime = activeSleepTime;
@@ -2979,68 +3025,6 @@
                 memset (mMixBuffer, 0, mFrameCount * mFrameSize);
                 sleepTime = 0;
             }
-        }
-
-        if (mSuspended > 0) {
-            sleepTime = suspendSleepTimeUs();
-        }
-
-        // only process effects if we're going to write
-        if (sleepTime == 0) {
-
-            // MixerThread does not have applyVolume
-            if (mixerStatus == MIXER_TRACKS_READY) {
-                applyVolume(leftVol, rightVol, rampVolume);
-            }
-
-            for (size_t i = 0; i < effectChains.size(); i ++) {
-                effectChains[i]->process_l();
-            }
-        }
-
-        // enable changes in effect chain
-        unlockEffectChains(effectChains);
-
-        // sleepTime == 0 means we must write to audio hardware
-        if (sleepTime == 0) {
-            mLastWriteTime = systemTime();
-            mInWrite = true;
-            mBytesWritten += mixBufferSize;
-            int bytesWritten = (int)mOutput->stream->write(mOutput->stream, mMixBuffer, mixBufferSize);
-            if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
-            mNumWrites++;
-            mInWrite = false;
-
-            // MixerThread has write blocked detection here
-
-            mStandby = false;
-        } else {
-            usleep(sleepTime);
-        }
-
-        // finally let go of removed track(s), without the lock held
-        // since we can't guarantee the destructors won't acquire that
-        // same lock.
-        trackToRemove.clear();
-        activeTrack.clear();
-
-        // Effect chains will be actually deleted here if they were removed from
-        // mEffectChains list during mixing or effects processing
-        effectChains.clear();
-
-        // FIXME Note that the above .clear() is no longer necessary since effectChains
-        // is now local to this block, but will keep it for now (at least until merge done).
-    }
-
-    // put output stream into standby mode
-    if (!mStandby) {
-        mOutput->stream->common.standby(&mOutput->stream->common);
-    }
-
-    releaseWakeLock();
-
-    ALOGV("Thread %p type %d exiting", this, mType);
-    return false;
 }
 
 // getTrackName_l() must be called with ThreadBase::mLock held
@@ -3153,96 +3137,8 @@
     }
 }
 
-bool AudioFlinger::DuplicatingThread::threadLoop()
+void AudioFlinger::DuplicatingThread::threadLoop_mix()
 {
-    Vector< sp<Track> > tracksToRemove;
-    nsecs_t standbyTime = systemTime();
-    size_t mixBufferSize = mFrameCount * mFrameSize;
-
-    // Only in DuplicatingThread
-    SortedVector< sp<OutputTrack> > outputTracks;
-    uint32_t writeFrames = 0;
-
-    uint32_t activeSleepTime = activeSleepTimeUs();
-    uint32_t idleSleepTime = idleSleepTimeUs();
-    uint32_t sleepTime = idleSleepTime;
-
-    acquireWakeLock();
-
-    while (!exitPending())
-    {
-        // MixerThread has cpuStats.sample
-
-        Vector< sp<EffectChain> > effectChains;
-
-        processConfigEvents();
-
-        mixer_state mixerStatus = MIXER_IDLE;
-        { // scope for the mLock
-
-            Mutex::Autolock _l(mLock);
-
-            if (checkForNewParameters_l()) {
-                mixBufferSize = mFrameCount * mFrameSize;
-
-                // Only in DuplicatingThread
-                updateWaitTime();
-
-                activeSleepTime = activeSleepTimeUs();
-                idleSleepTime = idleSleepTimeUs();
-            }
-
-            // Only in DuplicatingThread
-            for (size_t i = 0; i < mOutputTracks.size(); i++) {
-                outputTracks.add(mOutputTracks[i]);
-            }
-
-            // put audio hardware into standby after short delay
-            if (CC_UNLIKELY((!mActiveTracks.size() && systemTime() > standbyTime) ||
-                         mSuspended > 0)) {
-                if (!mStandby) {
-                    // DuplicatingThread implements standby by stopping all tracks
-                    for (size_t i = 0; i < outputTracks.size(); i++) {
-                        outputTracks[i]->stop();
-                    }
-                    mStandby = true;
-                    mBytesWritten = 0;
-                }
-
-                if (!mActiveTracks.size() && mConfigEvents.isEmpty()) {
-                    // we're about to wait, flush the binder command buffer
-                    IPCThreadState::self()->flushCommands();
-                    outputTracks.clear();
-
-                    if (exitPending()) break;
-
-                    releaseWakeLock_l();
-                    // wait until we have something to do...
-                    ALOGV("Thread %p type %d TID %d going to sleep", this, mType, gettid());
-                    mWaitWorkCV.wait(mLock);
-                    ALOGV("Thread %p type %d TID %d waking up", this, mType, gettid());
-                    acquireWakeLock_l();
-
-                    // MixerThread has "mPrevMixerStatus = MIXER_IDLE"
-                    checkSilentMode_l();
-
-                    standbyTime = systemTime() + mStandbyTimeInNsecs;
-                    sleepTime = idleSleepTime;
-                    // MixerThread has sleepTimeShift
-                    continue;
-                }
-            }
-
-            mixerStatus = prepareTracks_l(&tracksToRemove);
-
-            // prevent any changes in effect chain list and in each effect chain
-            // during mixing and effect process as the audio buffers could be deleted
-            // or modified if an effect is created or deleted
-            lockEffectChains_l(effectChains);
-        }
-
-        // Duplicating Thread is completely different here
-        if (CC_LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
             // mix buffers...
             if (outputsReady(outputTracks)) {
                 mAudioMixer->process(AudioBufferProvider::kInvalidPTS);
@@ -3251,7 +3147,10 @@
             }
             sleepTime = 0;
             writeFrames = mFrameCount;
-        } else {
+}
+
+void AudioFlinger::DuplicatingThread::threadLoop_sleepTime()
+{
             if (sleepTime == 0) {
                 if (mixerStatus == MIXER_TRACKS_ENABLED) {
                     sleepTime = activeSleepTime;
@@ -3269,58 +3168,23 @@
                     }
                 }
             }
-        }
+}
 
-        if (mSuspended > 0) {
-            sleepTime = suspendSleepTimeUs();
-        }
-
-        // only process effects if we're going to write
-        if (sleepTime == 0) {
-            for (size_t i = 0; i < effectChains.size(); i ++) {
-                effectChains[i]->process_l();
-            }
-        }
-
-        // enable changes in effect chain
-        unlockEffectChains(effectChains);
-
-        // sleepTime == 0 means we must write to audio hardware
-        if (sleepTime == 0) {
+void AudioFlinger::DuplicatingThread::threadLoop_write()
+{
             standbyTime = systemTime() + mStandbyTimeInNsecs;
             for (size_t i = 0; i < outputTracks.size(); i++) {
                 outputTracks[i]->write(mMixBuffer, writeFrames);
             }
-            mStandby = false;
             mBytesWritten += mixBufferSize;
+}
 
-            // MixerThread has write blocked detection here
-
-        } else {
-            usleep(sleepTime);
-        }
-
-        // finally let go of removed track(s), without the lock held
-        // since we can't guarantee the destructors won't acquire that
-        // same lock.
-        tracksToRemove.clear();
-        outputTracks.clear();
-
-        // Effect chains will be actually deleted here if they were removed from
-        // mEffectChains list during mixing or effects processing
-        effectChains.clear();
-
-        // FIXME Note that the above .clear() is no longer necessary since effectChains
-        // is now local to this block, but will keep it for now (at least until merge done).
-    }
-
-    // MixerThread and DirectOutpuThread have standby here,
-    // but for DuplicatingThread this is handled by the outputTracks
-
-    releaseWakeLock();
-
-    ALOGV("Thread %p type %d exiting", this, mType);
-    return false;
+void AudioFlinger::DuplicatingThread::threadLoop_standby()
+{
+                    // DuplicatingThread implements standby by stopping all tracks
+                    for (size_t i = 0; i < outputTracks.size(); i++) {
+                        outputTracks[i]->stop();
+                    }
 }
 
 void AudioFlinger::DuplicatingThread::addOutputTrack(MixerThread *thread)
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index bdaf97c..c7ac0a8 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -207,7 +207,9 @@
     // call in any IAudioFlinger method that accesses mPrimaryHardwareDev
     status_t                initCheck() const { return mPrimaryHardwareDev == NULL ? NO_INIT : NO_ERROR; }
 
+    // RefBase
     virtual     void        onFirstRef();
+
     audio_hw_device_t*      findSuitableHwDev_l(uint32_t devices);
     void                    purgeStaleEffects_l();
 
@@ -581,6 +583,10 @@
             MIXER_TRACKS_READY      // at least one active track, and at least one track has data
             // standby mode does not have an enum value
             // suspend by audio policy manager is orthogonal to mixer state
+#if 1
+            // FIXME remove these hacks for threadLoop_prepareTracks_l
+            , MIXER_CONTINUE        // "continue;"
+#endif
         };
 
         // playback track
@@ -793,8 +799,33 @@
 
         // Thread virtuals
         virtual     status_t    readyToRun();
+        virtual     bool        threadLoop();
+
+        // RefBase
         virtual     void        onFirstRef();
 
+protected:
+        // Code snippets that were lifted up out of threadLoop()
+        virtual     void        threadLoop_mix() = 0;
+        virtual     void        threadLoop_sleepTime() = 0;
+        virtual     void        threadLoop_write();
+        virtual     void        threadLoop_standby();
+
+        // Non-trivial for DUPLICATING only
+        virtual     void        updateWaitTime() { }
+
+        // Non-trivial for DIRECT only
+        virtual     void        applyVolume() { }
+
+        // FIXME merge these
+        // Non-trivial for MIXER and DUPLICATING only
+        virtual     mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove) { return MIXER_IDLE; }
+        // Non-trivial for DIRECT only
+        virtual     mixer_state threadLoop_prepareTracks_l(sp<Track>& trackToRemove)
+                                                                { return MIXER_IDLE; }
+
+public:
+
         virtual     status_t    initCheck() const { return (mOutput == NULL) ? NO_INIT : NO_ERROR; }
 
         virtual     uint32_t    latency() const;
@@ -897,6 +928,30 @@
         int                             mNumWrites;
         int                             mNumDelayedWrites;
         bool                            mInWrite;
+
+        // FIXME rename these former local variables of threadLoop to standard "m" names
+        nsecs_t                         standbyTime;
+        size_t                          mixBufferSize;
+        uint32_t                        activeSleepTime;
+        uint32_t                        idleSleepTime;
+        uint32_t                        sleepTime;
+        // mixerStatus was local to the while !exitingPending loop
+        mixer_state                     mixerStatus;
+
+        // FIXME move these declarations into the specific sub-class that needs them
+        // MIXER only
+        bool                            longStandbyExit;
+        uint32_t                        sleepTimeShift;
+        // MIXER and DUPLICATING only
+        mixer_state mPrevMixerStatus; // previous status returned by prepareTracks_l()
+        // DIRECT only
+        nsecs_t                         standbyDelay;
+        // activeTrack was local to the while !exitingPending loop
+        sp<Track>                       activeTrack;
+        // DUPLICATING only
+        SortedVector < sp<OutputTrack> >  outputTracks;
+        uint32_t                        writeFrames;
+        SortedVector < sp<OutputTrack> >  mOutputTracks;
     };
 
     class MixerThread : public PlaybackThread {
@@ -909,7 +964,6 @@
         virtual             ~MixerThread();
 
         // Thread virtuals
-        virtual     bool        threadLoop();
 
                     void        invalidateTracks(audio_stream_type_t streamType);
         virtual     bool        checkForNewParameters_l();
@@ -920,14 +974,17 @@
                     // pending set of tracks to remove via Vector 'tracksToRemove'.  The caller is
                     // responsible for clearing or destroying this Vector later on, when it
                     // is safe to do so. That will drop the final ref count and destroy the tracks.
-                    mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove);
+        virtual     mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove);
         virtual     int         getTrackName_l();
         virtual     void        deleteTrackName_l(int name);
         virtual     uint32_t    idleSleepTimeUs();
         virtual     uint32_t    suspendSleepTimeUs();
 
+        // threadLoop snippets
+        virtual     void        threadLoop_mix();
+        virtual     void        threadLoop_sleepTime();
+
                     AudioMixer* mAudioMixer;
-                    mixer_state mPrevMixerStatus; // previous status returned by prepareTracks_l()
     };
 
     class DirectOutputThread : public PlaybackThread {
@@ -938,7 +995,6 @@
         virtual                 ~DirectOutputThread();
 
         // Thread virtuals
-        virtual     bool        threadLoop();
 
         virtual     bool        checkForNewParameters_l();
 
@@ -949,8 +1005,11 @@
         virtual     uint32_t    idleSleepTimeUs();
         virtual     uint32_t    suspendSleepTimeUs();
 
-    private:
-        void applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp);
+        // threadLoop snippets
+        virtual     mixer_state threadLoop_prepareTracks_l(sp<Track>& trackToRemove);
+        virtual     void        threadLoop_mix();
+        virtual     void        threadLoop_sleepTime();
+        virtual     void        applyVolume();
 
         // volumes last sent to audio HAL with stream->set_volume()
         // FIXME use standard representation and names
@@ -958,6 +1017,12 @@
         float mRightVolFloat;
         uint16_t mLeftVolShort;
         uint16_t mRightVolShort;
+
+        // FIXME rename these former local variables of threadLoop to standard names
+        // next 3 were local to the while !exitingPending loop
+        bool rampVolume;
+        uint16_t leftVol;
+        uint16_t rightVol;
     };
 
     class DuplicatingThread : public MixerThread {
@@ -967,7 +1032,6 @@
         virtual                 ~DuplicatingThread();
 
         // Thread virtuals
-        virtual     bool        threadLoop();
                     void        addOutputTrack(MixerThread* thread);
                     void        removeOutputTrack(MixerThread* thread);
                     uint32_t    waitTimeMs() { return mWaitTimeMs; }
@@ -976,9 +1040,15 @@
 
     private:
                     bool        outputsReady(const SortedVector<sp<OutputTrack> > &outputTracks);
-                    void        updateWaitTime();
+    protected:
+        // threadLoop snippets
+        virtual     void        threadLoop_mix();
+        virtual     void        threadLoop_sleepTime();
+        virtual     void        threadLoop_write();
+        virtual     void        threadLoop_standby();
+        virtual     void        updateWaitTime();
+    private:
 
-        SortedVector < sp<OutputTrack> >  mOutputTracks;
                     uint32_t    mWaitTimeMs;
     };
 
@@ -1086,8 +1156,11 @@
                         uint32_t device);
                 virtual     ~RecordThread();
 
+        // Thread
         virtual bool        threadLoop();
         virtual status_t    readyToRun();
+
+        // RefBase
         virtual void        onFirstRef();
 
         virtual status_t    initCheck() const { return (mInput == NULL) ? NO_INIT : NO_ERROR; }
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index eab60a7..352decf 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -2179,8 +2179,9 @@
             String dnsString = dns.getHostAddress();
             if (changed || !dnsString.equals(SystemProperties.get("net.dns" + j + "." + pid))) {
                 changed = true;
-                SystemProperties.set("net.dns" + j++ + "." + pid, dns.getHostAddress());
+                SystemProperties.set("net.dns" + j + "." + pid, dns.getHostAddress());
             }
+            j++;
         }
         return changed;
     }
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index c8f49ee..d9d3f4e 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -2235,7 +2235,7 @@
 
                 if (target != currentValue) {
                     final boolean turningOff = endValue == Power.BRIGHTNESS_OFF;
-                    if (turningOff) {
+                    if (turningOff && ((mask & (SCREEN_ON_BIT | SCREEN_BRIGHT_BIT)) != 0)) {
                         // Cancel all pending animations since we're turning off
                         mScreenBrightnessHandler.removeCallbacksAndMessages(null);
                         screenOffFinishedAnimatingLocked(mScreenOffReason);
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 6b4c895..8363e6e 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -297,6 +297,10 @@
                     mWifiStateMachine.sendMessage(Message.obtain(msg));
                     break;
                 }
+                case WifiManager.CANCEL_WPS: {
+                    mWifiStateMachine.sendMessage(Message.obtain(msg));
+                    break;
+                }
                 case WifiManager.DISABLE_NETWORK: {
                     mWifiStateMachine.sendMessage(Message.obtain(msg));
                     break;
diff --git a/services/java/com/android/server/wm/BlackFrame.java b/services/java/com/android/server/wm/BlackFrame.java
index 10e294b..26289c9 100644
--- a/services/java/com/android/server/wm/BlackFrame.java
+++ b/services/java/com/android/server/wm/BlackFrame.java
@@ -16,6 +16,8 @@
 
 package com.android.server.wm;
 
+import java.io.PrintWriter;
+
 import android.graphics.Matrix;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
@@ -72,14 +74,31 @@
         }
     }
 
+    final Rect mOuterRect;
+    final Rect mInnerRect;
     final Matrix mTmpMatrix = new Matrix();
     final float[] mTmpFloats = new float[9];
     final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
 
+    public void printTo(String prefix, PrintWriter pw) {
+        pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw);
+                pw.print(" / Inner: "); mInnerRect.printShortString(pw);
+                pw.println();
+        for (int i=0; i<mBlackSurfaces.length; i++) {
+            BlackSurface bs = mBlackSurfaces[i];
+            pw.print(prefix); pw.print("#"); pw.print(i);
+                    pw.print(": "); pw.print(bs.surface);
+                    pw.print(" left="); pw.print(bs.left);
+                    pw.print(" top="); pw.println(bs.top);
+        }
+    }
+
     public BlackFrame(SurfaceSession session, Rect outer, Rect inner,
             int layer) throws Surface.OutOfResourcesException {
         boolean success = false;
 
+        mOuterRect = new Rect(outer);
+        mInnerRect = new Rect(inner);
         try {
             if (outer.top < inner.top) {
                 mBlackSurfaces[0] = new BlackSurface(session, layer,
diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/java/com/android/server/wm/ScreenRotationAnimation.java
index 1335a44..7ac67b6 100644
--- a/services/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -59,6 +59,8 @@
     final Transformation mStartExitTransformation = new Transformation();
     Animation mStartEnterAnimation;
     final Transformation mStartEnterTransformation = new Transformation();
+    Animation mStartFrameAnimation;
+    final Transformation mStartFrameTransformation = new Transformation();
 
     // The finishing animation for the exiting and entering elements.  This
     // animation needs to undo the transformation of the starting animation.
@@ -68,6 +70,8 @@
     final Transformation mFinishExitTransformation = new Transformation();
     Animation mFinishEnterAnimation;
     final Transformation mFinishEnterTransformation = new Transformation();
+    Animation mFinishFrameAnimation;
+    final Transformation mFinishFrameTransformation = 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
@@ -76,6 +80,8 @@
     final Transformation mRotateExitTransformation = new Transformation();
     Animation mRotateEnterAnimation;
     final Transformation mRotateEnterTransformation = new Transformation();
+    Animation mRotateFrameAnimation;
+    final Transformation mRotateFrameTransformation = 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.
@@ -83,32 +89,42 @@
     final Transformation mLastRotateExitTransformation = new Transformation();
     Animation mLastRotateEnterAnimation;
     final Transformation mLastRotateEnterTransformation = new Transformation();
+    Animation mLastRotateFrameAnimation;
+    final Transformation mLastRotateFrameTransformation = new Transformation();
 
     // Complete transformations being applied.
     final Transformation mExitTransformation = new Transformation();
     final Transformation mEnterTransformation = new Transformation();
+    final Transformation mFrameTransformation = new Transformation();
 
     boolean mStarted;
     boolean mAnimRunning;
     boolean mFinishAnimReady;
     long mFinishAnimStartTime;
 
+    final Matrix mFrameInitialMatrix = new Matrix();
     final Matrix mSnapshotInitialMatrix = new Matrix();
     final Matrix mSnapshotFinalMatrix = new Matrix();
     final Matrix mTmpMatrix = new Matrix();
     final float[] mTmpFloats = new float[9];
     private boolean mMoreRotateEnter;
     private boolean mMoreRotateExit;
+    private boolean mMoreRotateFrame;
     private boolean mMoreFinishEnter;
     private boolean mMoreFinishExit;
+    private boolean mMoreFinishFrame;
     private boolean mMoreStartEnter;
     private boolean mMoreStartExit;
+    private boolean mMoreStartFrame;
 
     public void printTo(String prefix, PrintWriter pw) {
         pw.print(prefix); pw.print("mSurface="); pw.print(mSurface);
                 pw.print(" mWidth="); pw.print(mWidth);
                 pw.print(" mHeight="); pw.println(mHeight);
         pw.print(prefix); pw.print("mBlackFrame="); pw.println(mBlackFrame);
+        if (mBlackFrame != null) {
+            mBlackFrame.printTo(prefix + "  ", pw);
+        }
         pw.print(prefix); pw.print("mSnapshotRotation="); pw.print(mSnapshotRotation);
                 pw.print(" mSnapshotDeltaRotation="); pw.print(mSnapshotDeltaRotation);
                 pw.print(" mCurRotation="); pw.println(mCurRotation);
@@ -123,21 +139,29 @@
                 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
                 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
+        pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
+                pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
                 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
                 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
+        pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
+                pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
                 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
                 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
-        pw.print(prefix); pw.print("mLastRotateExitAnimation=");
-                pw.print(mLastRotateExitAnimation);
-                pw.print(" "); mLastRotateExitTransformation.printShortString(pw); pw.println();
+        pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
+                pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mExitTransformation=");
                 mExitTransformation.printShortString(pw); pw.println();
         pw.print(prefix); pw.print("mEnterTransformation=");
                 mEnterTransformation.printShortString(pw); pw.println();
+        pw.print(prefix); pw.print("mFrameTransformation=");
+                mEnterTransformation.printShortString(pw); pw.println();
+        pw.print(prefix); pw.print("mFrameInitialMatrix=");
+                mFrameInitialMatrix.printShortString(pw);
+                pw.println();
         pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
                 mSnapshotInitialMatrix.printShortString(pw);
                 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
@@ -178,7 +202,7 @@
                     mSurface = null;
                     return;
                 }
-                mSurface.setLayer(FREEZE_LAYER + 1);
+                mSurface.setLayer(FREEZE_LAYER);
                 mSurface.show();
             } catch (Surface.OutOfResourcesException e) {
                 Slog.w(TAG, "Unable to allocate freeze surface", e);
@@ -299,10 +323,14 @@
                     com.android.internal.R.anim.screen_rotate_start_exit);
             mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
                     com.android.internal.R.anim.screen_rotate_start_enter);
+            mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
+                    com.android.internal.R.anim.screen_rotate_start_frame);
             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);
+            mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
+                    com.android.internal.R.anim.screen_rotate_finish_frame);
         }
 
         if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
@@ -315,24 +343,32 @@
                         com.android.internal.R.anim.screen_rotate_0_exit);
                 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_0_enter);
+                mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
+                        com.android.internal.R.anim.screen_rotate_0_frame);
                 break;
             case Surface.ROTATION_90:
                 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_plus_90_exit);
                 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_plus_90_enter);
+                mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
+                        com.android.internal.R.anim.screen_rotate_plus_90_frame);
                 break;
             case Surface.ROTATION_180:
                 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_180_exit);
                 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_180_enter);
+                mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
+                        com.android.internal.R.anim.screen_rotate_180_frame);
                 break;
             case Surface.ROTATION_270:
                 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_minus_90_exit);
                 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
                         com.android.internal.R.anim.screen_rotate_minus_90_enter);
+                mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
+                        com.android.internal.R.anim.screen_rotate_minus_90_frame);
                 break;
         }
 
@@ -346,13 +382,18 @@
                     mOriginalWidth, mOriginalHeight);
             mStartExitAnimation.initialize(finalWidth, finalHeight,
                     mOriginalWidth, mOriginalHeight);
+            mStartFrameAnimation.initialize(finalWidth, finalHeight,
+                    mOriginalWidth, mOriginalHeight);
             mFinishEnterAnimation.initialize(finalWidth, finalHeight,
                     mOriginalWidth, mOriginalHeight);
             mFinishExitAnimation.initialize(finalWidth, finalHeight,
                     mOriginalWidth, mOriginalHeight);
+            mFinishFrameAnimation.initialize(finalWidth, finalHeight,
+                    mOriginalWidth, mOriginalHeight);
         }
         mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
         mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
+        mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
         mAnimRunning = false;
         mFinishAnimReady = false;
         mFinishAnimStartTime = -1;
@@ -362,15 +403,21 @@
             mStartExitAnimation.scaleCurrentDuration(animationScale);
             mStartEnterAnimation.restrictDuration(maxAnimationDuration);
             mStartEnterAnimation.scaleCurrentDuration(animationScale);
+            mStartFrameAnimation.restrictDuration(maxAnimationDuration);
+            mStartFrameAnimation.scaleCurrentDuration(animationScale);
             mFinishExitAnimation.restrictDuration(maxAnimationDuration);
             mFinishExitAnimation.scaleCurrentDuration(animationScale);
             mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
             mFinishEnterAnimation.scaleCurrentDuration(animationScale);
+            mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
+            mFinishFrameAnimation.scaleCurrentDuration(animationScale);
         }
         mRotateExitAnimation.restrictDuration(maxAnimationDuration);
         mRotateExitAnimation.scaleCurrentDuration(animationScale);
         mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
         mRotateEnterAnimation.scaleCurrentDuration(animationScale);
+        mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
+        mRotateFrameAnimation.scaleCurrentDuration(animationScale);
 
         if (mBlackFrame == null) {
             if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
@@ -378,10 +425,20 @@
                     ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
             Surface.openTransaction();
 
+            // Compute the transformation matrix that must be applied
+            // the the black frame to make it stay in the initial position
+            // before the new screen rotation.  This is different than the
+            // snapshot transformation because the snapshot is always based
+            // of the native orientation of the screen, not the orientation
+            // we were last in.
+            createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
+
             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);
+                Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
+                        mOriginalWidth*2, mOriginalHeight*2);
+                Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
+                mBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 1);
+                mBlackFrame.setMatrix(mFrameInitialMatrix);
             } catch (Surface.OutOfResourcesException e) {
                 Slog.w(TAG, "Unable to allocate black surface", e);
             } finally {
@@ -438,13 +495,21 @@
             mStartEnterAnimation.cancel();
             mStartEnterAnimation = null;
         }
+        if (mStartFrameAnimation != null) {
+            mStartFrameAnimation.cancel();
+            mStartFrameAnimation = null;
+        }
         if (mFinishExitAnimation != null) {
             mFinishExitAnimation.cancel();
             mFinishExitAnimation = null;
         }
-        if (mStartEnterAnimation != null) {
-            mStartEnterAnimation.cancel();
-            mStartEnterAnimation = null;
+        if (mFinishEnterAnimation != null) {
+            mFinishEnterAnimation.cancel();
+            mFinishEnterAnimation = null;
+        }
+        if (mFinishFrameAnimation != null) {
+            mFinishFrameAnimation.cancel();
+            mFinishFrameAnimation = null;
         }
         if (mRotateExitAnimation != null) {
             mRotateExitAnimation.cancel();
@@ -454,12 +519,19 @@
             mRotateEnterAnimation.cancel();
             mRotateEnterAnimation = null;
         }
+        if (mRotateFrameAnimation != null) {
+            mRotateFrameAnimation.cancel();
+            mRotateFrameAnimation = null;
+        }
     }
 
     public boolean isAnimating() {
         return mStartEnterAnimation != null || mStartExitAnimation != null
-                && mFinishEnterAnimation != null || mFinishExitAnimation != null
-                && mRotateEnterAnimation != null || mRotateExitAnimation != null;
+                || mStartFrameAnimation != null
+                || mFinishEnterAnimation != null || mFinishExitAnimation != null
+                || mFinishFrameAnimation != null
+                || mRotateEnterAnimation != null || mRotateExitAnimation != null
+                || mRotateFrameAnimation != null;
     }
 
     @Override
@@ -497,6 +569,18 @@
             }
         }
 
+        mMoreStartFrame = false;
+        if (mStartFrameAnimation != null) {
+            mStartFrameTransformation.clear();
+            mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
+            if (!mMoreStartFrame) {
+                if (DEBUG_STATE) Slog.v(TAG, "Start frame animation done!");
+                mStartFrameAnimation.cancel();
+                mStartFrameAnimation = null;
+            }
+        }
+
         long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
         if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
 
@@ -528,18 +612,31 @@
             }
         }
 
+        mFinishFrameTransformation.clear();
+        mMoreFinishFrame = false;
+        if (mFinishFrameAnimation != null) {
+            mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
+            if (!mMoreStartFrame && !mMoreFinishFrame) {
+                if (DEBUG_STATE) Slog.v(TAG, "Finish frame animation done, clearing start/finish anims!");
+                mStartFrameTransformation.clear();
+                mFinishFrameAnimation.cancel();
+                mFinishFrameAnimation = null;
+                mFinishFrameTransformation.clear();
+            }
+        }
+
         mRotateExitTransformation.clear();
         mMoreRotateExit = false;
         if (mRotateExitAnimation != null) {
             mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
             if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
-        }
-
-        if (!mMoreFinishExit && !mMoreRotateExit) {
-            if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
-            mRotateExitAnimation.cancel();
-            mRotateExitAnimation = null;
-            mRotateExitTransformation.clear();
+            if (!mMoreFinishExit && !mMoreRotateExit) {
+                if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
+                mRotateExitAnimation.cancel();
+                mRotateExitAnimation = null;
+                mRotateExitTransformation.clear();
+            }
         }
 
         mRotateEnterTransformation.clear();
@@ -547,13 +644,25 @@
         if (mRotateEnterAnimation != null) {
             mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
             if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
+            if (!mMoreFinishEnter && !mMoreRotateEnter) {
+                if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
+                mRotateEnterAnimation.cancel();
+                mRotateEnterAnimation = null;
+                mRotateEnterTransformation.clear();
+            }
         }
 
-        if (!mMoreFinishEnter && !mMoreRotateEnter) {
-            if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
-            mRotateEnterAnimation.cancel();
-            mRotateEnterAnimation = null;
-            mRotateEnterTransformation.clear();
+        mRotateFrameTransformation.clear();
+        mMoreRotateFrame = false;
+        if (mRotateFrameAnimation != null) {
+            mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
+            if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
+            if (!mMoreFinishFrame && !mMoreRotateFrame) {
+                if (DEBUG_STATE) Slog.v(TAG, "Rotate frame animation done!");
+                mRotateFrameAnimation.cancel();
+                mRotateFrameAnimation = null;
+                mRotateFrameTransformation.clear();
+            }
         }
 
         mExitTransformation.set(mRotateExitTransformation);
@@ -564,11 +673,22 @@
         mEnterTransformation.compose(mStartEnterTransformation);
         mEnterTransformation.compose(mFinishEnterTransformation);
 
+        //mFrameTransformation.set(mRotateExitTransformation);
+        //mFrameTransformation.compose(mStartExitTransformation);
+        //mFrameTransformation.compose(mFinishExitTransformation);
+        mFrameTransformation.set(mRotateFrameTransformation);
+        mFrameTransformation.compose(mStartFrameTransformation);
+        mFrameTransformation.compose(mFinishFrameTransformation);
+        mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
+
         if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
         if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
+        if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
 
-        final boolean more = mMoreStartEnter || mMoreStartExit || mMoreFinishEnter
-                || mMoreFinishExit || mMoreRotateEnter || mMoreRotateExit || !mFinishAnimReady;
+        final boolean more = mMoreStartEnter || mMoreStartExit || mMoreStartFrame
+                || mMoreFinishEnter || mMoreFinishExit || mMoreFinishFrame
+                || mMoreRotateEnter || mMoreRotateExit || mMoreRotateFrame
+                || !mFinishAnimReady;
 
         mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
 
@@ -585,14 +705,14 @@
             }
         }
 
-        if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
+        if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
             if (mBlackFrame != null) {
-                if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, hiding black frame");
+                if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
                 mBlackFrame.hide();
             }
         } else {
             if (mBlackFrame != null) {
-                mBlackFrame.setMatrix(mEnterTransformation.getMatrix());
+                mBlackFrame.setMatrix(mFrameTransformation.getMatrix());
             }
         }
 
@@ -602,6 +722,7 @@
     public boolean startAndFinishAnimationLocked(long now) {
         if (!isAnimating()) {
             if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
+            mFinishAnimReady = false;
             return false;
         }
 
@@ -613,18 +734,27 @@
             if (mStartExitAnimation != null) {
                 mStartExitAnimation.setStartTime(now);
             }
+            if (mStartFrameAnimation != null) {
+                mStartFrameAnimation.setStartTime(now);
+            }
             if (mFinishEnterAnimation != null) {
                 mFinishEnterAnimation.setStartTime(0);
             }
             if (mFinishExitAnimation != null) {
                 mFinishExitAnimation.setStartTime(0);
             }
+            if (mFinishFrameAnimation != null) {
+                mFinishFrameAnimation.setStartTime(0);
+            }
             if (mRotateEnterAnimation != null) {
                 mRotateEnterAnimation.setStartTime(now);
             }
             if (mRotateExitAnimation != null) {
                 mRotateExitAnimation.setStartTime(now);
             }
+            if (mRotateFrameAnimation != null) {
+                mRotateFrameAnimation.setStartTime(now);
+            }
             mAnimRunning = true;
         }
         
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 6221b90..1c5a70f 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -7661,7 +7661,7 @@
         }
         final int NEAT = mExitingAppTokens.size();
         for (i=0; i<NEAT; i++) {
-            final AppWindowToken appToken = mAppTokens.get(i);
+            final AppWindowToken appToken = mExitingAppTokens.get(i);
             if (appToken.startAndFinishAnimationLocked(currentTime, innerDw, innerDh)) {
                 mStepAnimators.add(appToken);
                 mInnerFields.mAnimating = true;
@@ -7669,7 +7669,8 @@
         }
 
         if (mScreenRotationAnimation != null) {
-            if (mScreenRotationAnimation.isAnimating()) {
+            if (mScreenRotationAnimation.isAnimating() ||
+                    mScreenRotationAnimation.mFinishAnimReady) {
                 if (mScreenRotationAnimation.startAndFinishAnimationLocked(currentTime)) {
                     mInnerFields.mUpdateRotation = false;
                     mInnerFields.mAnimating = true;
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index 8305714..46ad036 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -286,7 +286,10 @@
                     config.status = Status.CURRENT;
                     break;
                 case DISCONNECTED:
-                    config.status = Status.ENABLED;
+                    //If network is already disabled, keep the status
+                    if (config.status == Status.CURRENT) {
+                        config.status = Status.ENABLED;
+                    }
                     break;
                 default:
                     //do nothing, retain the existing state
@@ -906,7 +909,7 @@
                         }
                     }
                 } else {
-                    loge("Missing id while parsing configuration");
+                    if (DBG) log("Missing id while parsing configuration");
                 }
             }
         } catch (EOFException ignore) {
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index bdee12a..d746810 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1069,15 +1069,22 @@
     public static final int START_WPS_SUCCEEDED             = BASE + 11;
     /** @hide */
     public static final int WPS_FAILED                      = BASE + 12;
-   /** @hide */
+    /** @hide */
     public static final int WPS_COMPLETED                   = BASE + 13;
 
     /** @hide */
-    public static final int DISABLE_NETWORK                 = BASE + 14;
+    public static final int CANCEL_WPS                      = BASE + 14;
     /** @hide */
-    public static final int DISABLE_NETWORK_FAILED          = BASE + 15;
+    public static final int CANCEL_WPS_FAILED               = BASE + 15;
     /** @hide */
-    public static final int DISABLE_NETWORK_SUCCEEDED       = BASE + 16;
+    public static final int CANCEL_WPS_SUCCEDED             = BASE + 16;
+
+    /** @hide */
+    public static final int DISABLE_NETWORK                 = BASE + 17;
+    /** @hide */
+    public static final int DISABLE_NETWORK_FAILED          = BASE + 18;
+    /** @hide */
+    public static final int DISABLE_NETWORK_SUCCEEDED       = BASE + 19;
 
     /* For system use only */
     /** @hide */
@@ -1091,14 +1098,14 @@
      * Indicates that the operation failed due to an internal error.
      * @hide
      */
-    public static final int ERROR               = 0;
+    public static final int ERROR                       = 0;
 
     /**
      * Passed with {@link ActionListener#onFailure}.
      * Indicates that the operation is already in progress
      * @hide
      */
-    public static final int IN_PROGRESS         = 1;
+    public static final int IN_PROGRESS                 = 1;
 
     /**
      * Passed with {@link ActionListener#onFailure}.
@@ -1106,11 +1113,19 @@
      * unable to service the request
      * @hide
      */
-    public static final int BUSY                = 2;
+    public static final int BUSY                        = 2;
 
     /* WPS specific errors */
     /** WPS overlap detected {@hide} */
-    public static final int WPS_OVERLAP_ERROR   = 3;
+    public static final int WPS_OVERLAP_ERROR           = 3;
+    /** WEP on WPS is prohibited {@hide} */
+    public static final int WPS_WEP_PROHIBITED          = 4;
+    /** TKIP only prohibited {@hide} */
+    public static final int WPS_TKIP_ONLY_PROHIBITED    = 5;
+    /** Authentication failure on WPS {@hide} */
+    public static final int WPS_AUTH_FAILURE            = 6;
+    /** WPS timed out {@hide} */
+    public static final int WPS_TIMED_OUT               = 7;
 
     /** Interface for callback invocation when framework channel is lost {@hide} */
     public interface ChannelListener {
@@ -1165,6 +1180,7 @@
         private SparseArray<Object> mListenerMap = new SparseArray<Object>();
         private Object mListenerMapLock = new Object();
         private int mListenerKey = 0;
+        private static final int INVALID_KEY = -1;
 
         AsyncChannel mAsyncChannel;
         WifiHandler mHandler;
@@ -1187,6 +1203,7 @@
                     case WifiManager.CONNECT_NETWORK_FAILED:
                     case WifiManager.FORGET_NETWORK_FAILED:
                     case WifiManager.SAVE_NETWORK_FAILED:
+                    case WifiManager.CANCEL_WPS_FAILED:
                     case WifiManager.DISABLE_NETWORK_FAILED:
                         if (listener != null) {
                             ((ActionListener) listener).onFailure(message.arg1);
@@ -1196,6 +1213,7 @@
                     case WifiManager.CONNECT_NETWORK_SUCCEEDED:
                     case WifiManager.FORGET_NETWORK_SUCCEEDED:
                     case WifiManager.SAVE_NETWORK_SUCCEEDED:
+                    case WifiManager.CANCEL_WPS_SUCCEDED:
                     case WifiManager.DISABLE_NETWORK_SUCCEEDED:
                         if (listener != null) {
                             ((ActionListener) listener).onSuccess();
@@ -1229,16 +1247,19 @@
         }
 
         int putListener(Object listener) {
-            if (listener == null) return 0;
+            if (listener == null) return INVALID_KEY;
             int key;
             synchronized (mListenerMapLock) {
-                key = mListenerKey++;
+                do {
+                    key = mListenerKey++;
+                } while (key == INVALID_KEY);
                 mListenerMap.put(key, listener);
             }
             return key;
         }
 
         Object removeListener(int key) {
+            if (key == INVALID_KEY) return null;
             synchronized (mListenerMapLock) {
                 Object listener = mListenerMap.get(key);
                 mListenerMap.remove(key);
@@ -1289,7 +1310,10 @@
         if (c == null) throw new IllegalArgumentException("Channel needs to be initialized");
         if (config == null) throw new IllegalArgumentException("config cannot be null");
 
-        c.mAsyncChannel.sendMessage(CONNECT_NETWORK, 0, c.putListener(listener), config);
+        // Use INVALID_NETWORK_ID for arg1 when passing a config object
+        // arg1 is used to pass network id when the network already exists
+        c.mAsyncChannel.sendMessage(CONNECT_NETWORK, WifiConfiguration.INVALID_NETWORK_ID,
+                c.putListener(listener), config);
     }
 
     /**
@@ -1385,6 +1409,21 @@
     }
 
     /**
+     * Cancel any ongoing Wi-fi Protected Setup
+     *
+     * @param c is the channel created at {@link #initialize}
+     * @param listener for callbacks on success or failure. Can be null.
+     * @hide
+     */
+    public void cancelWps(Channel c, ActionListener listener) {
+        if (c == null) throw new IllegalArgumentException("Channel needs to be initialized");
+
+        c.mAsyncChannel.sendMessage(CANCEL_WPS, 0, c.putListener(listener));
+    }
+
+
+
+    /**
      * Get a reference to WifiService handler. This is used by a client to establish
      * an AsyncChannel communication with WifiService
      *
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java
index e1cfba3..c406fa0 100644
--- a/wifi/java/android/net/wifi/WifiMonitor.java
+++ b/wifi/java/android/net/wifi/WifiMonitor.java
@@ -65,7 +65,20 @@
 
     /* WPS events */
     private static final String WPS_SUCCESS_STR = "WPS-SUCCESS";
+
+    /* Format: WPS-FAIL msg=%d [config_error=%d] [reason=%d (%s)] */
     private static final String WPS_FAIL_STR    = "WPS-FAIL";
+    private static final String WPS_FAIL_PATTERN =
+            "WPS-FAIL msg=\\d+(?: config_error=(\\d+))?(?: reason=(\\d+))?";
+
+    /* config error code values for config_error=%d */
+    private static final int CONFIG_MULTIPLE_PBC_DETECTED = 12;
+    private static final int CONFIG_AUTH_FAILURE = 18;
+
+    /* reason code values for reason=%d */
+    private static final int REASON_TKIP_ONLY_PROHIBITED = 1;
+    private static final int REASON_WEP_PROHIBITED = 2;
+
     private static final String WPS_OVERLAP_STR = "WPS-OVERLAP-DETECTED";
     private static final String WPS_TIMEOUT_STR = "WPS-TIMEOUT";
 
@@ -316,7 +329,7 @@
                     } else if (eventStr.startsWith(WPS_SUCCESS_STR)) {
                         mStateMachine.sendMessage(WPS_SUCCESS_EVENT);
                     } else if (eventStr.startsWith(WPS_FAIL_STR)) {
-                        mStateMachine.sendMessage(WPS_FAIL_EVENT);
+                        handleWpsFailEvent(eventStr);
                     } else if (eventStr.startsWith(WPS_OVERLAP_STR)) {
                         mStateMachine.sendMessage(WPS_OVERLAP_EVENT);
                     } else if (eventStr.startsWith(WPS_TIMEOUT_STR)) {
@@ -458,6 +471,43 @@
             }
         }
 
+        private void handleWpsFailEvent(String dataString) {
+            final Pattern p = Pattern.compile(WPS_FAIL_PATTERN);
+            Matcher match = p.matcher(dataString);
+            if (match.find()) {
+                String cfgErr = match.group(1);
+                String reason = match.group(2);
+
+                if (reason != null) {
+                    switch(Integer.parseInt(reason)) {
+                        case REASON_TKIP_ONLY_PROHIBITED:
+                            mStateMachine.sendMessage(mStateMachine.obtainMessage(WPS_FAIL_EVENT,
+                                    WifiManager.WPS_TKIP_ONLY_PROHIBITED, 0));
+                            return;
+                        case REASON_WEP_PROHIBITED:
+                            mStateMachine.sendMessage(mStateMachine.obtainMessage(WPS_FAIL_EVENT,
+                                    WifiManager.WPS_WEP_PROHIBITED, 0));
+                            return;
+                    }
+                }
+                if (cfgErr != null) {
+                    switch(Integer.parseInt(cfgErr)) {
+                        case CONFIG_AUTH_FAILURE:
+                            mStateMachine.sendMessage(mStateMachine.obtainMessage(WPS_FAIL_EVENT,
+                                    WifiManager.WPS_AUTH_FAILURE, 0));
+                            return;
+                        case CONFIG_MULTIPLE_PBC_DETECTED:
+                            mStateMachine.sendMessage(mStateMachine.obtainMessage(WPS_FAIL_EVENT,
+                                    WifiManager.WPS_OVERLAP_ERROR, 0));
+                            return;
+                    }
+                }
+            }
+            //For all other errors, return a generic internal error
+            mStateMachine.sendMessage(mStateMachine.obtainMessage(WPS_FAIL_EVENT,
+                    WifiManager.ERROR, 0));
+        }
+
         /**
          * Handle p2p events
          */
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index e3dd3a6..ecd4073 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -388,27 +388,37 @@
         return doStringCommand("SIGNAL_POLL");
     }
 
-    public boolean startWpsPbc() {
-        return doBooleanCommand("WPS_PBC");
-    }
-
     public boolean startWpsPbc(String bssid) {
-        return doBooleanCommand("WPS_PBC " + bssid);
+        if (TextUtils.isEmpty(bssid)) {
+            return doBooleanCommand("WPS_PBC");
+        } else {
+            return doBooleanCommand("WPS_PBC " + bssid);
+        }
     }
 
     public boolean startWpsPinKeypad(String pin) {
+        if (TextUtils.isEmpty(pin)) return false;
         return doBooleanCommand("WPS_PIN any " + pin);
     }
 
     public String startWpsPinDisplay(String bssid) {
-        return doStringCommand("WPS_PIN " + bssid);
+        if (TextUtils.isEmpty(bssid)) {
+            return doStringCommand("WPS_PIN any");
+        } else {
+            return doStringCommand("WPS_PIN " + bssid);
+        }
     }
 
     /* Configures an access point connection */
     public boolean startWpsRegistrar(String bssid, String pin) {
+        if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false;
         return doBooleanCommand("WPS_REG " + bssid + " " + pin);
     }
 
+    public boolean cancelWps() {
+        return doBooleanCommand("WPS_CANCEL");
+    }
+
     public boolean setPersistentReconnect(boolean enabled) {
         int value = (enabled == true) ? 1 : 0;
         return doBooleanCommand("SET persistent_reconnect " + value);
@@ -539,7 +549,7 @@
     }
 
     public boolean p2pGroupRemove(String iface) {
-        if (iface == null) return false;
+        if (TextUtils.isEmpty(iface)) return false;
         return doBooleanCommand("P2P_GROUP_REMOVE " + iface);
     }
 
@@ -549,7 +559,7 @@
 
     /* Invite a peer to a group */
     public boolean p2pInvite(WifiP2pGroup group, String deviceAddress) {
-        if (deviceAddress == null) return false;
+        if (TextUtils.isEmpty(deviceAddress)) return false;
 
         if (group == null) {
             return doBooleanCommand("P2P_INVITE peer=" + deviceAddress);
@@ -561,19 +571,19 @@
 
     /* Reinvoke a persistent connection */
     public boolean p2pReinvoke(int netId, String deviceAddress) {
-        if (deviceAddress == null || netId < 0) return false;
+        if (TextUtils.isEmpty(deviceAddress) || netId < 0) return false;
 
         return doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + deviceAddress);
     }
 
 
     public String p2pGetInterfaceAddress(String deviceAddress) {
-        if (deviceAddress == null) return null;
+        if (TextUtils.isEmpty(deviceAddress)) return null;
 
         //  "p2p_peer deviceAddress" returns a multi-line result containing
         //      intended_addr=fa:7b:7a:42:82:13
         String peerInfo = p2pPeer(deviceAddress);
-        if (peerInfo == null) return null;
+        if (TextUtils.isEmpty(peerInfo)) return null;
         String[] tokens= peerInfo.split("\n");
 
         for (String token : tokens) {
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index d6988cd..843620c 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -1844,6 +1844,10 @@
                     replyToMessage(message, WifiManager.WPS_FAILED,
                             WifiManager.BUSY);
                     break;
+                case WifiManager.CANCEL_WPS:
+                    replyToMessage(message, WifiManager.CANCEL_WPS_FAILED,
+                            WifiManager.BUSY);
+                    break;
                 case WifiManager.DISABLE_NETWORK:
                     replyToMessage(message, WifiManager.DISABLE_NETWORK_FAILED,
                             WifiManager.BUSY);
@@ -3321,8 +3325,15 @@
                     transitionTo(mDisconnectedState);
                     break;
                 case WifiMonitor.WPS_FAIL_EVENT:
+                    //arg1 has the reason for the failure
+                    replyToMessage(mSourceMessage, WifiManager.WPS_FAILED, message.arg1);
+                    mSourceMessage.recycle();
+                    mSourceMessage = null;
+                    transitionTo(mDisconnectedState);
+                    break;
                 case WifiMonitor.WPS_TIMEOUT_EVENT:
-                    replyToMessage(mSourceMessage, WifiManager.WPS_FAILED, WifiManager.ERROR);
+                    replyToMessage(mSourceMessage, WifiManager.WPS_FAILED,
+                            WifiManager.WPS_TIMED_OUT);
                     mSourceMessage.recycle();
                     mSourceMessage = null;
                     transitionTo(mDisconnectedState);
@@ -3330,6 +3341,14 @@
                 case WifiManager.START_WPS:
                     replyToMessage(message, WifiManager.WPS_FAILED, WifiManager.IN_PROGRESS);
                     break;
+                case WifiManager.CANCEL_WPS:
+                    if (mWifiNative.cancelWps()) {
+                        replyToMessage(message, WifiManager.CANCEL_WPS_SUCCEDED);
+                    } else {
+                        replyToMessage(message, WifiManager.CANCEL_WPS_FAILED, WifiManager.ERROR);
+                    }
+                    transitionTo(mDisconnectedState);
+                    break;
                 /* Defer all commands that can cause connections to a different network
                  * or put the state machine out of connect mode
                  */
@@ -3346,6 +3365,11 @@
                     if (DBG) log("Network connection lost");
                     handleNetworkDisconnect();
                     break;
+                case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
+                    //Throw away supplicant state changes when WPS is running.
+                    //We will start getting supplicant state changes once we get
+                    //a WPS success or failure
+                    break;
                 default:
                     return NOT_HANDLED;
             }
@@ -3353,6 +3377,7 @@
             return HANDLED;
         }
 
+        @Override
         public void exit() {
             mWifiConfigStore.enableAllNetworks();
             mWifiConfigStore.loadConfiguredNetworks();
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index 5b0e424..399dc9d 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -996,7 +996,7 @@
                     break;
                 case PEER_CONNECTION_USER_ACCEPT:
                     if (mSavedPeerConfig.wps.setup == WpsInfo.PBC) {
-                        mWifiNative.startWpsPbc();
+                        mWifiNative.startWpsPbc(null);
                     } else {
                         mWifiNative.startWpsPinKeypad(mSavedPeerConfig.wps.pin);
                     }