Merge "Check if BT is disabled or not when sending audio state."
diff --git a/api/current.xml b/api/current.xml
index 1f3b5fd..22d82ce 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -57955,6 +57955,17 @@
  visibility="public"
 >
 </field>
+<field name="CONFIG_SCREEN_SIZE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1024"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="CONFIG_TOUCHSCREEN"
  type="int"
  transient="false"
@@ -64017,6 +64028,28 @@
  visibility="public"
 >
 </field>
+<field name="SCREEN_HEIGHT_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREEN_WIDTH_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TOUCHSCREEN_FINGER"
  type="int"
  transient="false"
@@ -64260,6 +64293,16 @@
  visibility="public"
 >
 </field>
+<field name="screenHeightDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="screenLayout"
  type="int"
  transient="false"
@@ -64270,6 +64313,16 @@
  visibility="public"
 >
 </field>
+<field name="screenWidthDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="touchscreen"
  type="int"
  transient="false"
@@ -144074,6 +144127,17 @@
  visibility="public"
 >
 </field>
+<field name="ICE_CREAM_SANDWICH"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="10000"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 </class>
 <class name="Bundle"
  extends="java.lang.Object"
@@ -267777,7 +267841,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="t" type="T">
+<parameter name="arg0" type="T">
 </parameter>
 </method>
 </interface>
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 46f611f..64c437d 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -334,6 +334,12 @@
     public static final int CONFIG_UI_MODE = 0x0200;
     /**
      * Bit in {@link #configChanges} that indicates that the activity
+     * can itself handle the screen size. Set from the
+     * {@link android.R.attr#configChanges} attribute.
+     */
+    public static final int CONFIG_SCREEN_SIZE = 0x0400;
+    /**
+     * Bit in {@link #configChanges} that indicates that the activity
      * can itself handle changes to the font scaling factor.  Set from the
      * {@link android.R.attr#configChanges} attribute.  This is
      * not a core resource configutation, but a higher-level value, so its
@@ -341,6 +347,37 @@
      */
     public static final int CONFIG_FONT_SCALE = 0x40000000;
     
+    /** @hide
+     * Unfortunately the constants for config changes in native code are
+     * different from ActivityInfo. :(  Here are the values we should use for the
+     * native side given the bit we have assigned in ActivityInfo.
+     */
+    public static int[] CONFIG_NATIVE_BITS = new int[] {
+        0x0001, // MNC
+        0x0002, // MCC
+        0x0004, // LOCALE
+        0x0008, // TOUCH SCREEN
+        0x0010, // KEYBOARD
+        0x0020, // KEYBOARD HIDDEN
+        0x0040, // NAVIGATION
+        0x0080, // ORIENTATION
+        0x0800, // SCREEN LAYOUT
+        0x1000, // UI MODE
+        0x0200, // SCREEN SIZE
+    };
+    /** @hide
+     * Convert Java change bits to native.
+     */
+    public static int activityInfoConfigToNative(int input) {
+        int output = 0;
+        for (int i=0; i<CONFIG_NATIVE_BITS.length; i++) {
+            if ((input&(1<<i)) != 0) {
+                output |= CONFIG_NATIVE_BITS[i];
+            }
+        }
+        return output;
+    }
+
     /**
      * Bit mask of kinds of configuration changes that this activity
      * can handle itself (without being restarted by the system).
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 7ebfda4..8dfdaa8 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -396,7 +396,7 @@
             int cookie = assmgr.addAssetPath(mArchiveSourcePath);
             if (cookie != 0) {
                 res = new Resources(assmgr, metrics, null);
-                assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                         Build.VERSION.RESOURCES_SDK_INT);
                 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
                 assetError = false;
@@ -596,7 +596,7 @@
         AssetManager assmgr = null;
         try {
             assmgr = new AssetManager();
-            assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+            assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     Build.VERSION.RESOURCES_SDK_INT);
             int cookie = assmgr.addAssetPath(packageFilePath);
             parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
@@ -1931,6 +1931,10 @@
             a.info.configChanges = sa.getInt(
                     com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
                     0);
+            if (owner.applicationInfo.targetSdkVersion
+                        < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+                a.info.configChanges |= ActivityInfo.CONFIG_SCREEN_SIZE;
+            }
             a.info.softInputMode = sa.getInt(
                     com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
                     0);
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index e279f64..afa68c3 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -652,7 +652,8 @@
     public native final void setConfiguration(int mcc, int mnc, String locale,
             int orientation, int touchscreen, int density, int keyboard,
             int keyboardHidden, int navigation, int screenWidth, int screenHeight,
-            int screenLayout, int uiMode, int majorVersion);
+            int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode,
+            int majorVersion);
 
     /**
      * Retrieve the resource identifier for the given resource name.
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 72fa07c..28ba4e7 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -241,6 +241,20 @@
      */
     public int uiMode;
 
+    public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;
+
+    /**
+     * The current width of the available screen space, in dp units.
+     */
+    public int screenWidthDp;
+
+    public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;
+
+    /**
+     * The current height of the available screen space, in dp units.
+     */
+    public int screenHeightDp;
+
     /**
      * @hide Internal book-keeping.
      */
@@ -278,6 +292,8 @@
         orientation = o.orientation;
         screenLayout = o.screenLayout;
         uiMode = o.uiMode;
+        screenWidthDp = o.screenWidthDp;
+        screenHeightDp = o.screenHeightDp;
         seq = o.seq;
     }
     
@@ -316,6 +332,10 @@
         sb.append(java.lang.Integer.toHexString(screenLayout));
         sb.append(" uiMode=0x");
         sb.append(java.lang.Integer.toHexString(uiMode));
+        sb.append(" wdp=");
+        sb.append(screenWidthDp);
+        sb.append(" hdp=");
+        sb.append(screenHeightDp);
         if (seq != 0) {
             sb.append(" seq=");
             sb.append(seq);
@@ -341,6 +361,8 @@
         orientation = ORIENTATION_UNDEFINED;
         screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
         uiMode = UI_MODE_TYPE_UNDEFINED;
+        screenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
+        screenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
         seq = 0;
     }
 
@@ -434,6 +456,16 @@
                         | (delta.uiMode&UI_MODE_NIGHT_MASK);
             }
         }
+        if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
+                && screenWidthDp != delta.screenWidthDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+            screenWidthDp = delta.screenWidthDp;
+        }
+        if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
+                && screenHeightDp != delta.screenHeightDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+            screenHeightDp = delta.screenHeightDp;
+        }
         
         if (delta.seq != 0) {
             seq = delta.seq;
@@ -463,9 +495,11 @@
      * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
      * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
      * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
-     * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or
+     * PackageManager.ActivityInfo.CONFIG_ORIENTATION},
      * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
-     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}.
+     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or
+     * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
+     * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}.
      */
     public int diff(Configuration delta) {
         int changed = 0;
@@ -518,6 +552,14 @@
                 && uiMode != delta.uiMode) {
             changed |= ActivityInfo.CONFIG_UI_MODE;
         }
+        if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
+                && screenWidthDp != delta.screenWidthDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+        }
+        if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
+                && screenHeightDp != delta.screenHeightDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+        }
         
         return changed;
     }
@@ -599,6 +641,8 @@
         dest.writeInt(orientation);
         dest.writeInt(screenLayout);
         dest.writeInt(uiMode);
+        dest.writeInt(screenWidthDp);
+        dest.writeInt(screenHeightDp);
         dest.writeInt(seq);
     }
 
@@ -620,6 +664,8 @@
         orientation = source.readInt();
         screenLayout = source.readInt();
         uiMode = source.readInt();
+        screenWidthDp = source.readInt();
+        screenHeightDp = source.readInt();
         seq = source.readInt();
     }
     
@@ -680,6 +726,10 @@
         n = this.screenLayout - that.screenLayout;
         if (n != 0) return n;
         n = this.uiMode - that.uiMode;
+        if (n != 0) return n;
+        n = this.screenWidthDp - that.screenWidthDp;
+        if (n != 0) return n;
+        n = this.screenHeightDp - that.screenHeightDp;
         //if (n != 0) return n;
         return n;
     }
@@ -704,6 +754,7 @@
                 + this.touchscreen
                 + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
                 + this.navigation + this.navigationHidden
-                + this.orientation + this.screenLayout + this.uiMode;
+                + this.orientation + this.screenLayout + this.uiMode
+                + this.screenWidthDp + this.screenHeightDp;
     }
 }
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 81eb09c..2e6ae70 100755
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -21,6 +21,7 @@
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.content.pm.ActivityInfo;
 import android.graphics.Movie;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.ColorDrawable;
@@ -1404,6 +1405,7 @@
             int configChanges = 0xfffffff;
             if (config != null) {
                 configChanges = mConfiguration.updateFrom(config);
+                configChanges = ActivityInfo.activityInfoConfigToNative(configChanges);
             }
             if (mConfiguration.locale == null) {
                 mConfiguration.locale = Locale.getDefault();
@@ -1443,6 +1445,7 @@
                     mConfiguration.touchscreen,
                     (int)(mMetrics.density*160), mConfiguration.keyboard,
                     keyboardHidden, mConfiguration.navigation, width, height,
+                    mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
                     mConfiguration.screenLayout, mConfiguration.uiMode,
                     Build.VERSION.RESOURCES_SDK_INT);
 
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 3bb0821..24d5369 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -230,6 +230,11 @@
          * Newest version of Android, version 3.1.
          */
         public static final int HONEYCOMB_MR1 = 12;
+
+        /**
+         * Current version under development.
+         */
+        public static final int ICE_CREAM_SANDWICH = CUR_DEVELOPMENT;
     }
     
     /** The type of build, like "user" or "eng". */
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 6deb5a0..c75b0fe 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3303,12 +3303,20 @@
         public static final String WIFI_IDLE_MS = "wifi_idle_ms";
 
         /**
-         * The interval in milliseconds to issue scans when the driver is
-         * started. This is necessary to allow wifi to connect to an
-         * access point when the driver is suspended.
+         * The interval in milliseconds to issue wake up scans when wifi needs
+         * to connect. This is necessary to connect to an access point when
+         * device is on the move and the screen is off.
          * @hide
          */
-        public static final String WIFI_SCAN_INTERVAL_MS = "wifi_scan_interval_ms";
+        public static final String WIFI_FRAMEWORK_SCAN_INTERVAL_MS =
+                "wifi_framework_scan_interval_ms";
+
+        /**
+         * The interval in milliseconds to scan as used by the wifi supplicant
+         * @hide
+         */
+        public static final String WIFI_SUPPLICANT_SCAN_INTERVAL_MS =
+                "wifi_supplicant_scan_interval_ms";
 
         /**
          * The interval in milliseconds at which to check packet counts on the
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index 132c346..ca2212c 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -83,19 +83,6 @@
                     onBluetoothDisable();
                     break;
                 }
-            } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
-                int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
-                                                   BluetoothDevice.ERROR);
-                switch(bondState) {
-                case BluetoothDevice.BOND_BONDED:
-                    if (getPriority(device) == BluetoothA2dp.PRIORITY_UNDEFINED) {
-                        setPriority(device, BluetoothA2dp.PRIORITY_ON);
-                    }
-                    break;
-                case BluetoothDevice.BOND_NONE:
-                    setPriority(device, BluetoothA2dp.PRIORITY_UNDEFINED);
-                    break;
-                }
             } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
                 synchronized (this) {
                     if (mAudioDevices.containsKey(device)) {
@@ -158,7 +145,6 @@
         mAdapter = BluetoothAdapter.getDefaultAdapter();
 
         mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
-        mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
         mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
         mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
         mIntentFilter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
diff --git a/core/java/android/server/BluetoothBondState.java b/core/java/android/server/BluetoothBondState.java
index 2304a70..a36cd24 100644
--- a/core/java/android/server/BluetoothBondState.java
+++ b/core/java/android/server/BluetoothBondState.java
@@ -18,6 +18,9 @@
 
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
+import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothHeadset;
 import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
@@ -68,6 +71,8 @@
     private final Context mContext;
     private final BluetoothService mService;
     private final BluetoothInputProfileHandler mBluetoothInputProfileHandler;
+    private BluetoothA2dp mA2dpProxy;
+    private BluetoothHeadset mHeadsetProxy;
 
     BluetoothBondState(Context context, BluetoothService service) {
         mContext = context;
@@ -126,14 +131,15 @@
 
         if (state == BluetoothDevice.BOND_BONDED) {
             mService.addProfileState(address);
+        } else if (state == BluetoothDevice.BOND_BONDING) {
+            if (mA2dpProxy == null || mHeadsetProxy == null) {
+                getProfileProxy();
+            }
         } else if (state == BluetoothDevice.BOND_NONE) {
             mService.removeProfileState(address);
         }
 
-        // HID is handled by BluetoothService, other profiles
-        // will be handled by their respective services.
-        mBluetoothInputProfileHandler.setInitialInputDevicePriority(
-            mService.getRemoteDevice(address), state);
+        setProfilePriorities(address, state);
 
         if (DBG) {
             Log.d(TAG, address + " bond state " + oldState + " -> " + state
@@ -261,6 +267,52 @@
         mPinAttempt.put(address, new Integer(newAttempt));
     }
 
+    private void getProfileProxy() {
+        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+        if (mA2dpProxy == null) {
+            bluetoothAdapter.getProfileProxy(mContext, mProfileServiceListener,
+                                             BluetoothProfile.A2DP);
+        }
+
+        if (mHeadsetProxy == null) {
+            bluetoothAdapter.getProfileProxy(mContext, mProfileServiceListener,
+                                             BluetoothProfile.HEADSET);
+        }
+    }
+
+    private void closeProfileProxy() {
+        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+        if (mA2dpProxy != null) {
+            bluetoothAdapter.closeProfileProxy(BluetoothProfile.A2DP, mA2dpProxy);
+        }
+
+        if (mHeadsetProxy != null) {
+            bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mHeadsetProxy);
+        }
+    }
+
+    private BluetoothProfile.ServiceListener mProfileServiceListener =
+        new BluetoothProfile.ServiceListener() {
+
+        public void onServiceConnected(int profile, BluetoothProfile proxy) {
+            if (profile == BluetoothProfile.A2DP) {
+                mA2dpProxy = (BluetoothA2dp) proxy;
+            } else if (profile == BluetoothProfile.HEADSET) {
+                mHeadsetProxy = (BluetoothHeadset) proxy;
+            }
+        }
+
+        public void onServiceDisconnected(int profile) {
+            if (profile == BluetoothProfile.A2DP) {
+                mA2dpProxy = null;
+            } else if (profile == BluetoothProfile.HEADSET) {
+                mHeadsetProxy = null;
+            }
+        }
+    };
+
     private void copyAutoPairingData() {
         FileInputStream in = null;
         FileOutputStream out = null;
@@ -365,4 +417,30 @@
             }
         }
     }
+
+    // Set service priority of Hid, A2DP and Headset profiles depending on
+    // the bond state change
+    private void setProfilePriorities(String address, int state) {
+        BluetoothDevice remoteDevice = mService.getRemoteDevice(address);
+        // HID is handled by BluetoothService
+        mBluetoothInputProfileHandler.setInitialInputDevicePriority(remoteDevice, state);
+
+        // Set service priority of A2DP and Headset
+        // We used to do the priority change in the 2 services after the broadcast
+        //   intent reach them. But that left a small time gap that could reject
+        //   incoming connection due to undefined priorities.
+        if (state == BluetoothDevice.BOND_BONDED) {
+            if (mA2dpProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
+                mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
+            }
+
+            if (mHeadsetProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
+                mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
+            }
+        } else if (state == BluetoothDevice.BOND_NONE) {
+            mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
+            mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
+        }
+    }
+
 }
diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java
index ca1effb..c773527 100644
--- a/core/java/android/widget/AdapterViewAnimator.java
+++ b/core/java/android/widget/AdapterViewAnimator.java
@@ -79,7 +79,7 @@
     /**
      * Map of the children of the {@link AdapterViewAnimator}.
      */
-    HashMap<Integer, ViewAndIndex> mViewsMap = new HashMap<Integer, ViewAndIndex>();
+    HashMap<Integer, ViewAndMetaData> mViewsMap = new HashMap<Integer, ViewAndMetaData>();
 
     /**
      * List of views pending removal from the {@link AdapterViewAnimator}
@@ -204,13 +204,18 @@
         mPreviousViews = new ArrayList<Integer>();
     }
 
-    class ViewAndIndex {
-        ViewAndIndex(View v, int i) {
-            view = v;
-            index = i;
-        }
+    class ViewAndMetaData {
         View view;
-        int index;
+        int relativeIndex;
+        int adapterPosition;
+        long itemId;
+
+        ViewAndMetaData(View view, int relativeIndex, int adapterPosition, long itemId) {
+            this.view = view;
+            this.relativeIndex = relativeIndex;
+            this.adapterPosition = adapterPosition;
+            this.itemId = itemId;
+        }
     }
 
     /**
@@ -376,6 +381,15 @@
         }
     }
 
+    private ViewAndMetaData getMetaDataForChild(View child) {
+        for (ViewAndMetaData vm: mViewsMap.values()) {
+            if (vm.view == child) {
+                return vm;
+            }
+        }
+        return null;
+     }
+
     LayoutParams createOrReuseLayoutParams(View v) {
         final ViewGroup.LayoutParams currentLp = v.getLayoutParams();
         if (currentLp instanceof ViewGroup.LayoutParams) {
@@ -478,7 +492,7 @@
 
             if (remove) {
                 View previousView = mViewsMap.get(index).view;
-                int oldRelativeIndex = mViewsMap.get(index).index;
+                int oldRelativeIndex = mViewsMap.get(index).relativeIndex;
 
                 mPreviousViews.add(index);
                 transformViewForTransition(oldRelativeIndex, -1, previousView, animate);
@@ -494,7 +508,7 @@
                 int index = modulo(i, getWindowSize());
                 int oldRelativeIndex;
                 if (mViewsMap.containsKey(index)) {
-                    oldRelativeIndex = mViewsMap.get(index).index;
+                    oldRelativeIndex = mViewsMap.get(index).relativeIndex;
                 } else {
                     oldRelativeIndex = -1;
                 }
@@ -507,14 +521,16 @@
 
                 if (inOldRange) {
                     View view = mViewsMap.get(index).view;
-                    mViewsMap.get(index).index = newRelativeIndex;
+                    mViewsMap.get(index).relativeIndex = newRelativeIndex;
                     applyTransformForChildAtIndex(view, newRelativeIndex);
                     transformViewForTransition(oldRelativeIndex, newRelativeIndex, view, animate);
 
                 // Otherwise this view is new to the window
                 } else {
                     // Get the new view from the adapter, add it and apply any transform / animation
-                    View newView = mAdapter.getView(modulo(i, adapterCount), null, this);
+                    final int adapterPosition = modulo(i, adapterCount);
+                    View newView = mAdapter.getView(adapterPosition, null, this);
+                    long itemId = mAdapter.getItemId(adapterPosition);
 
                     // We wrap the new view in a FrameLayout so as to respect the contract
                     // with the adapter, that is, that we don't modify this view directly
@@ -524,7 +540,8 @@
                     if (newView != null) {
                        fl.addView(newView);
                     }
-                    mViewsMap.put(index, new ViewAndIndex(fl, newRelativeIndex));
+                    mViewsMap.put(index, new ViewAndMetaData(fl, newRelativeIndex,
+                            adapterPosition, itemId));
                     addChild(fl);
                     applyTransformForChildAtIndex(fl, newRelativeIndex);
                     transformViewForTransition(-1, newRelativeIndex, fl, animate);
@@ -601,6 +618,7 @@
             case MotionEvent.ACTION_UP: {
                 if (mTouchMode == TOUCH_MODE_DOWN_IN_CURRENT_VIEW) {
                     final View v = getCurrentView();
+                    final ViewAndMetaData viewData = getMetaDataForChild(v);
                     if (v != null) {
                         if (isTransformedTouchPointInView(ev.getX(), ev.getY(), v, null)) {
                             final Handler handler = getHandler();
@@ -613,7 +631,12 @@
                                     hideTapFeedback(v);
                                     post(new Runnable() {
                                         public void run() {
-                                            performItemClick(v, 0, 0);
+                                            if (viewData != null) {
+                                                performItemClick(v, viewData.adapterPosition,
+                                                        viewData.itemId);
+                                            } else {
+                                                performItemClick(v, 0, 0);
+                                            }
                                         }
                                     });
                                 }
diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java
index ec4ef4b..71c91e1 100644
--- a/core/java/android/widget/StackView.java
+++ b/core/java/android/widget/StackView.java
@@ -427,8 +427,8 @@
         // Here we need to make sure that the z-order of the children is correct
         for (int i = mCurrentWindowEnd; i >= mCurrentWindowStart; i--) {
             int index = modulo(i, getWindowSize());
-            ViewAndIndex vi = mViewsMap.get(index);
-            if (vi != null) {
+            ViewAndMetaData vm = mViewsMap.get(index);
+            if (vm != null) {
                 View v = mViewsMap.get(index).view;
                 if (v != null) v.bringToFront();
             }
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index de18f9f..b319a74 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -137,7 +137,6 @@
 
 #define RETURN_ERR_IF_NULL(value)   do { if (!(value)) { assert(0); return -1; } } while (false)
 
-int register_android_graphics_Movie(JNIEnv* env);
 int register_android_graphics_Movie(JNIEnv* env)
 {
     gMovie_class = env->FindClass(kClassPathName);
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index b6619ab..1b6b24f 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -41,7 +41,6 @@
 
 struct fields_t {
     // these fields provide access from C++ to the...
-    jclass    audioRecordClass;      //... AudioRecord class
     jmethodID postNativeEventInJava; //... event post callback method
     int       PCM16;                 //...  format constants
     int       PCM8;                  //...  format constants
@@ -520,22 +519,20 @@
 // ----------------------------------------------------------------------------
 int register_android_media_AudioRecord(JNIEnv *env)
 {
-    javaAudioRecordFields.audioRecordClass = NULL;
     javaAudioRecordFields.postNativeEventInJava = NULL;
     javaAudioRecordFields.nativeRecorderInJavaObj = NULL;
     javaAudioRecordFields.nativeCallbackCookie = NULL;
     
 
     // Get the AudioRecord class
-    javaAudioRecordFields.audioRecordClass = env->FindClass(kClassPathName);
-    if (javaAudioRecordFields.audioRecordClass == NULL) {
+    jclass audioRecordClass = env->FindClass(kClassPathName);
+    if (audioRecordClass == NULL) {
         LOGE("Can't find %s", kClassPathName);
         return -1;
     }
-    
     // Get the postEvent method
     javaAudioRecordFields.postNativeEventInJava = env->GetStaticMethodID(
-            javaAudioRecordFields.audioRecordClass,
+            audioRecordClass,
             JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V");
     if (javaAudioRecordFields.postNativeEventInJava == NULL) {
         LOGE("Can't find AudioRecord.%s", JAVA_POSTEVENT_CALLBACK_NAME);
@@ -545,7 +542,7 @@
     // Get the variables
     //    mNativeRecorderInJavaObj
     javaAudioRecordFields.nativeRecorderInJavaObj = 
-        env->GetFieldID(javaAudioRecordFields.audioRecordClass,
+        env->GetFieldID(audioRecordClass,
                         JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "I");
     if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
         LOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
@@ -553,7 +550,7 @@
     }
     //     mNativeCallbackCookie
     javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID(
-            javaAudioRecordFields.audioRecordClass,
+            audioRecordClass,
             JAVA_NATIVECALLBACKINFO_FIELD_NAME, "I");
     if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
         LOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 5f3fed2..5016bf9 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -34,6 +34,8 @@
 
 using namespace android;
 
+static const char* const kClassPathName = "android/media/AudioSystem";
+
 enum AudioError {
     kAudioStatusOk = 0,
     kAudioStatusError = 1,
@@ -96,14 +98,15 @@
     return env->NewStringUTF(AudioSystem::getParameters(0, c_keys8).string());
 }
 
-void android_media_AudioSystem_error_callback(status_t err)
+static void
+android_media_AudioSystem_error_callback(status_t err)
 {
     JNIEnv *env = AndroidRuntime::getJNIEnv();
     if (env == NULL) {
         return;
     }
 
-    jclass clazz = env->FindClass("android/media/AudioSystem");
+    jclass clazz = env->FindClass(kClassPathName);
 
     int error;
 
@@ -218,12 +221,10 @@
     {"getDevicesForStream", "(I)I",     (void *)android_media_AudioSystem_getDevicesForStream},
 };
 
-const char* const kClassPathName = "android/media/AudioSystem";
-
 int register_android_media_AudioSystem(JNIEnv *env)
 {
     AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback);
     
     return AndroidRuntime::registerNativeMethods(env,
-                "android/media/AudioSystem", gMethods, NELEM(gMethods));
+                kClassPathName, gMethods, NELEM(gMethods));
 }
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 44d2a52..587a16c 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -43,7 +43,6 @@
 
 struct fields_t {
     // these fields provide access from C++ to the...
-    jclass    audioTrackClass;       //... AudioTrack class
     jmethodID postNativeEventInJava; //... event post callback method
     int       PCM16;                 //...  format constants
     int       PCM8;                  //...  format constants
@@ -915,20 +914,19 @@
 // ----------------------------------------------------------------------------
 int register_android_media_AudioTrack(JNIEnv *env)
 {
-    javaAudioTrackFields.audioTrackClass = NULL;
     javaAudioTrackFields.nativeTrackInJavaObj = NULL;
     javaAudioTrackFields.postNativeEventInJava = NULL;
 
     // Get the AudioTrack class
-    javaAudioTrackFields.audioTrackClass = env->FindClass(kClassPathName);
-    if (javaAudioTrackFields.audioTrackClass == NULL) {
+    jclass audioTrackClass = env->FindClass(kClassPathName);
+    if (audioTrackClass == NULL) {
         LOGE("Can't find %s", kClassPathName);
         return -1;
     }
 
     // Get the postEvent method
     javaAudioTrackFields.postNativeEventInJava = env->GetStaticMethodID(
-            javaAudioTrackFields.audioTrackClass,
+            audioTrackClass,
             JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V");
     if (javaAudioTrackFields.postNativeEventInJava == NULL) {
         LOGE("Can't find AudioTrack.%s", JAVA_POSTEVENT_CALLBACK_NAME);
@@ -938,7 +936,7 @@
     // Get the variables fields
     //      nativeTrackInJavaObj
     javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID(
-            javaAudioTrackFields.audioTrackClass,
+            audioTrackClass,
             JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "I");
     if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
         LOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
@@ -946,7 +944,7 @@
     }
     //      jniData;
     javaAudioTrackFields.jniData = env->GetFieldID(
-            javaAudioTrackFields.audioTrackClass,
+            audioTrackClass,
             JAVA_JNIDATA_FIELD_NAME, "I");
     if (javaAudioTrackFields.jniData == NULL) {
         LOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
@@ -954,10 +952,10 @@
     }
 
     // Get the memory mode constants
-    if ( !android_media_getIntConstantFromClass(env, javaAudioTrackFields.audioTrackClass,
+    if ( !android_media_getIntConstantFromClass(env, audioTrackClass,
                kClassPathName, 
                JAVA_CONST_MODE_STATIC_NAME, &(javaAudioTrackFields.MODE_STATIC))
-         || !android_media_getIntConstantFromClass(env, javaAudioTrackFields.audioTrackClass,
+         || !android_media_getIntConstantFromClass(env, audioTrackClass,
                kClassPathName, 
                JAVA_CONST_MODE_STREAM_NAME, &(javaAudioTrackFields.MODE_STREAM)) ) {
         // error log performed in android_media_getIntConstantFromClass() 
diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp
index 3adf770..db132ec 100644
--- a/core/jni/android_net_NetUtils.cpp
+++ b/core/jni/android_net_NetUtils.cpp
@@ -55,7 +55,6 @@
  * to look them up every time.
  */
 static struct fieldIds {
-    jclass dhcpInfoInternalClass;
     jmethodID constructorId;
     jfieldID ipaddress;
     jfieldID gateway;
@@ -163,7 +162,7 @@
     result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
                                         dns1, dns2, server, &lease);
     env->ReleaseStringUTFChars(ifname, nameStr);
-    if (result == 0 && dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
+    if (result == 0) {
         env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr));
         env->SetObjectField(info, dhcpInfoInternalFieldIds.gateway, env->NewStringUTF(gateway));
         env->SetIntField(info, dhcpInfoInternalFieldIds.prefixLength, prefixLength);
@@ -229,17 +228,16 @@
     jclass netutils = env->FindClass(NETUTILS_PKG_NAME);
     LOG_FATAL_IF(netutils == NULL, "Unable to find class " NETUTILS_PKG_NAME);
 
-    dhcpInfoInternalFieldIds.dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal");
-    if (dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
-        dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "<init>", "()V");
-        dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "gateway", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "prefixLength", "I");
-        dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns1", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns2", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "leaseDuration", "I");
-    }
+    jclass dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal");
+    LOG_FATAL_IF(dhcpInfoInternalClass == NULL, "Unable to find class android/net/DhcpInfoInternal");
+    dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalClass, "<init>", "()V");
+    dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalClass, "gateway", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalClass, "prefixLength", "I");
+    dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalClass, "dns1", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalClass, "dns2", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalClass, "leaseDuration", "I");
 
     return AndroidRuntime::registerNativeMethods(env,
             NETUTILS_PKG_NAME, gNetworkUtilMethods, NELEM(gNetworkUtilMethods));
diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp
index 667ba75..494dc27 100644
--- a/core/jni/android_net_wifi_Wifi.cpp
+++ b/core/jni/android_net_wifi_Wifi.cpp
@@ -556,7 +556,7 @@
     return doBooleanCommand(cmdstr, "OK");
 }
 
-static void android_net_wifi_enableBackgroundScan(JNIEnv* env, jobject clazz, jboolean enable)
+static void android_net_wifi_enableBackgroundScanCommand(JNIEnv* env, jobject clazz, jboolean enable)
 {
     //Note: BGSCAN-START and BGSCAN-STOP are documented in core/res/res/values/config.xml
     //and will need an update if the names are changed
@@ -568,6 +568,16 @@
     }
 }
 
+static void android_net_wifi_setScanIntervalCommand(JNIEnv* env, jobject clazz, jint scanInterval)
+{
+    char cmdstr[BUF_SIZE];
+
+    int numWritten = snprintf(cmdstr, sizeof(cmdstr), "SCAN_INTERVAL %d", scanInterval);
+
+    if(numWritten < (int)sizeof(cmdstr)) doBooleanCommand(cmdstr, "OK");
+}
+
+
 // ----------------------------------------------------------------------------
 
 /*
@@ -635,7 +645,8 @@
         (void*) android_net_wifi_setSuspendOptimizationsCommand},
     { "setCountryCodeCommand", "(Ljava/lang/String;)Z",
         (void*) android_net_wifi_setCountryCodeCommand},
-    { "enableBackgroundScan", "(Z)V", (void*) android_net_wifi_enableBackgroundScan},
+    { "enableBackgroundScanCommand", "(Z)V", (void*) android_net_wifi_enableBackgroundScanCommand},
+    { "setScanIntervalCommand", "(I)V", (void*) android_net_wifi_setScanIntervalCommand},
 };
 
 int register_android_net_wifi_WifiManager(JNIEnv* env)
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index fdb7fda..65b5990 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -532,6 +532,7 @@
                                                           jint keyboard, jint keyboardHidden,
                                                           jint navigation,
                                                           jint screenWidth, jint screenHeight,
+                                                          jint screenWidthDp, jint screenHeightDp,
                                                           jint screenLayout, jint uiMode,
                                                           jint sdkVersion)
 {
@@ -555,6 +556,8 @@
     config.navigation = (uint8_t)navigation;
     config.screenWidth = (uint16_t)screenWidth;
     config.screenHeight = (uint16_t)screenHeight;
+    config.screenWidthDp = (uint16_t)screenWidthDp;
+    config.screenHeightDp = (uint16_t)screenHeightDp;
     config.screenLayout = (uint8_t)screenLayout;
     config.uiMode = (uint8_t)uiMode;
     config.sdkVersion = (uint16_t)sdkVersion;
@@ -1693,7 +1696,7 @@
         (void*) android_content_AssetManager_setLocale },
     { "getLocales",      "()[Ljava/lang/String;",
         (void*) android_content_AssetManager_getLocales },
-    { "setConfiguration", "(IILjava/lang/String;IIIIIIIIIII)V",
+    { "setConfiguration", "(IILjava/lang/String;IIIIIIIIIIIII)V",
         (void*) android_content_AssetManager_setConfiguration },
     { "getResourceIdentifier","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
         (void*) android_content_AssetManager_getResourceIdentifier },
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index 9a727a7..f31bba9 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -736,9 +736,9 @@
 
 int register_android_app_ActivityThread(JNIEnv* env)
 {
-    jclass gFileDescriptorClass = env->FindClass("java/io/FileDescriptor");
+    jclass fileDescriptorClass = env->FindClass("java/io/FileDescriptor");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor");
-    gFileDescriptorField = env->GetFieldID(gFileDescriptorClass, "descriptor", "I");
+    gFileDescriptorField = env->GetFieldID(fileDescriptorClass, "descriptor", "I");
     LOG_FATAL_IF(gFileDescriptorField == NULL,
                  "Unable to find descriptor field in java.io.FileDescriptor");
 
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index e8f30ad..80beaa5 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -590,6 +590,11 @@
         <!-- The global user interface mode has changed.  For example,
              going in or out of car mode, night mode changing, etc. -->
         <flag name="uiMode" value="0x0200" />
+        <!-- The physical screen size has changed.  If applications don't
+             target at least {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}
+             then the activity will always handle this itself (the change
+             will not result in a restart). -->
+        <flag name="screenSize" value="0x0400" />
         <!-- The font scaling factor has changed, that is the user has
              selected a new global font size. -->
         <flag name="fontScale" value="0x40000000" />
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 5d65b72..51a32b0 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -226,6 +226,15 @@
          The driver commands needed to support the feature are BGSCAN-START and BGSCAN-STOP -->
     <bool translatable="false" name="config_wifi_background_scan_support">false</bool>
 
+    <!-- Integer indicating wpa_supplicant scan interval in milliseconds -->
+    <integer translatable="false" name="config_wifi_supplicant_scan_interval">15000</integer>
+
+    <!-- Integer indicating the framework scan interval in milliseconds. This is used in the scenario
+         where the chipset does not support background scanning (config_wifi_background_scan_suport
+         is false) to set up a periodic wake up scan so that the device can connect to a new access
+         point on the move. A value of 0 means no periodic scans will be used in the framework. -->
+    <integer translatable="false" name="config_wifi_framework_scan_interval">300000</integer>
+
     <!-- Flag indicating whether the keyguard should be bypassed when
          the slider is open.  This can be set or unset depending how easily
          the slider can be opened (for example, in a pocket or purse). -->
diff --git a/docs/html/guide/market/billing/billing_admin.jd b/docs/html/guide/market/billing/billing_admin.jd
index 38099ee..723113d 100755
--- a/docs/html/guide/market/billing/billing_admin.jd
+++ b/docs/html/guide/market/billing/billing_admin.jd
@@ -15,118 +15,214 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>In-app billing frees you from processing financial transactions, but you still need to perform a few administrative tasks, including setting up and maintaining your product list on the publisher site, registering test accounts, and handling refunds when necessary.</p>
+<p>In-app billing frees you from processing financial transactions, but you still need to perform a
+few administrative tasks, including setting up and maintaining your product list on the publisher
+site, registering test accounts, and handling refunds when necessary.</p>
 
-<p>You must have an Android Market publisher account to register test accounts. And you must have a Google Checkout Merchant account to create a product list and issue refunds to your users. If you already have a publisher account on Android Market, you can use your existing account. You do not need to register for a new account to support in-app billing. If you do not have a publisher account, you can register as an Android Market developer and set up a publisher account at the Android Market <a href="http://market.android.com/publish">publisher site</a>. If you do not have a Google Checkout Merchant account, you can register for one at the <a href="http://checkout.google.com">Google Checkout site</a>.</p>
+<p>You must have an Android Market publisher account to register test accounts. And you must have a
+Google Checkout Merchant account to create a product list and issue refunds to your users. If you
+already have a publisher account on Android Market, you can use your existing account. You do not
+need to register for a new account to support in-app billing. If you do not have a publisher
+account, you can register as an Android Market developer and set up a publisher account at the
+Android Market <a href="http://market.android.com/publish">publisher site</a>. If you do not have a
+Google Checkout Merchant account, you can register for one at the <a
+href="http://checkout.google.com">Google Checkout site</a>.</p>
 
 <h2 id="billing-list-setup">Creating a Product List</h2>
 
-<p>The Android Market publisher site provides a product list for each of your published applications. You can sell an item using Android Market's in-app billing feature only if the item is listed on an application's product list. Each application has its own product list; you cannot sell items that are listed in another application's product list.</p>
+<p>The Android Market publisher site provides a product list for each of your published
+applications. You can sell an item using Android Market's in-app billing feature only if the item is
+listed on an application's product list. Each application has its own product list; you cannot sell
+items that are listed in another application's product list.</p>
 
-<p>You can access an application's product list by clicking the <strong>In-App Products</strong> link that appears under each of the applications that are listed for your publisher account (see figure 1). The <strong>In-App Products</strong> link appears only if you have a Google Checkout Merchant account and an application's manifest includes the <code>com.android.vending.BILLING</code> permission.</p>
+<p>You can access an application's product list by clicking the <strong>In-App Products</strong>
+link that appears under each of the applications that are listed for your publisher account (see
+figure 1). The <strong>In-App Products</strong> link appears only if you have a Google Checkout
+Merchant account and an application's manifest includes the <code>com.android.vending.BILLING</code>
+permission.</p>
 
 <img src="{@docRoot}images/billing_product_list_entry.png" height="548" id="figure1" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> You can access an application's product list by clicking the <strong>In-App Products</strong> link.
+  <strong>Figure 1.</strong> You can access an application's product list by clicking the
+  <strong>In-App Products</strong> link.
 </p>
 
-<p>A product list contains information about the items you are selling, such as a product id, product description, and price (see figure 2). The product list stores only metadata about the items you are selling in your application. It does not store any digital content. You are responsible for storing and delivering the digital content that you sell in your applications.</p>
+<p>A product list contains information about the items you are selling, such as a product id,
+product description, and price (see figure 2). The product list stores only metadata about the items
+you are selling in your application. It does not store any digital content. You are responsible for
+storing and delivering the digital content that you sell in your applications.</p>
 
 <img src="{@docRoot}images/billing_product_list.png" height="560" id="figure2" />
 <p class="img-caption">
   <strong>Figure 2.</strong> An application's product list.
 </p>
 
-<p>You can create a product list for a published application or a draft application that's been uploaded and saved to the Android Market site. However, you must have a Google Checkout Merchant account and the application's manifest must include the <code>com.android.vending.BILLING</code> permission. If an application's manifest does not include this permission, you will be able to edit existing items in the product list but you will not be able to add new items to the list. For more information, see <a href="#billing-permission">Modifying your application's AndroidManifest.xml file</a>.</p>
+<p>You can create a product list for a published application or a draft application that's been
+uploaded and saved to the Android Market site. However, you must have a Google Checkout Merchant
+account and the application's manifest must include the <code>com.android.vending.BILLING</code>
+permission. If an application's manifest does not include this permission, you will be able to edit
+existing items in the product list but you will not be able to add new items to the list. For more
+information, see <a href="#billing-permission">Modifying your application's AndroidManifest.xml
+file</a>.</p>
 
 <p>To create a product list for an application, follow these steps:</p>
 
 <ol>
   <li><a href="http://market.android.com/publish">Log in</a> to your publisher account.</li>
-  <li>In the <strong>All Android Market listings</strong> panel, under the application name, click <strong>In-app Products</strong>.</li>
+  <li>In the <strong>All Android Market listings</strong> panel, under the application name, click
+  <strong>In-app Products</strong>.</li>
   <li>On the In-app Products List page, click <strong>Add in-app product</strong>.</li>
-  <li>On the Create New In-app Product page (see figure 3), provide details about the item you are selling and then click <strong>Save</strong>.</li>
+  <li>On the Create New In-app Product page (see figure 3), provide details about the item you are
+  selling and then click <strong>Save</strong>.</li>
 </ol>
 
 <img src="{@docRoot}images/billing_list_form.png" height="840" id="figure3" />
 <p class="img-caption">
-  f<strong>Figure 3.</strong> The Create New In-app Product page lets you add items to an application's product list.
+  f<strong>Figure 3.</strong> The Create New In-app Product page lets you add items to an
+  application's product list.
 </p>
 
 <p>You must enter the following information for each item in a product list:</p>
 <ul>
   <li><strong>In-app Product ID</strong>
-    <p>Product IDs are unique across an application's namespace. A product ID must start with a lowercase letter or a number, and must be composed using only lowercase letters (a-z), numbers (0-9), underlines (_), and dots (.). The product ID "android.test" is reserved, as are all product IDs that start with "android.test."</p>
-    <p>In addition, you cannot modify an item's product ID after it is created, and you cannot reuse a product ID, even if you delete the item previously using the product ID.</p>
+    <p>Product IDs are unique across an application's namespace. A product ID must start with a
+    lowercase letter or a number, and must be composed using only lowercase letters (a-z), numbers
+    (0-9), underlines (_), and dots (.). The product ID "android.test" is reserved, as are all
+    product IDs that start with "android.test."</p>
+    <p>In addition, you cannot modify an item's product ID after it is created, and you cannot reuse
+    a product ID, even if you delete the item previously using the product ID.</p>
   </li>
   <li><strong>Purchase type</strong>
-    <p>The purchase type can be "managed per user account" or "unmanaged." You can specify an item's purchase type only through the publisher site and you can never change an item's purchase type once you specify it. For more information, see <a href="#billing_purchase_type">Choosing a purchase type</a> later in this document.</p>
+    <p>The purchase type can be "managed per user account" or "unmanaged." You can specify an item's
+    purchase type only through the publisher site and you can never change an item's purchase type
+    once you specify it. For more information, see <a href="#billing_purchase_type">Choosing a
+    purchase type</a> later in this document.</p>
   </li>
   <li><strong>Publishing State</strong>
-    <p>An item's publishing state can be "published" or "unpublished." However, to be visible to a user during checkout, an item's publishing state must be set to "published" and the item's application must be published on Android Market.</p>
-    <p class="note"><strong>Note:</strong> This is not true for test accounts. An item is visible to a test account if the application is not published and the item is published. See <a href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-real">Testing In-app Billing</a> for more information.</p>
+    <p>An item's publishing state can be "published" or "unpublished." However, to be visible to a
+    user during checkout, an item's publishing state must be set to "published" and the item's
+    application must be published on Android Market.</p>
+    <p class="note"><strong>Note:</strong> This is not true for test accounts. An item is visible to
+    a test account if the application is not published and the item is published. See <a
+    href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-real">Testing In-app
+    Billing</a> for more information.</p>
   </li>
   <li><strong>Language</strong>
     <p>A product list inherits its language from the parent application.</p>
   </li>
   <li><strong>Title</strong>
-    <p>The title is a short descriptor for the item. For example, "Sleeping potion." Titles must be unique across an application's namespace. Every item must have a title. The title is visible to users during checkout. For optimum appearance, titles should be no longer than 25 characters; however, titles can be up to 55 characters in length.</p>
+    <p>The title is a short descriptor for the item. For example, "Sleeping potion." Titles must be
+    unique across an application's namespace. Every item must have a title. The title is visible to
+    users during checkout. For optimum appearance, titles should be no longer than 25 characters;
+    however, titles can be up to 55 characters in length.</p>
   </li>
   <li><strong>Description</strong>
-    <p>The description is a long descriptor for the item. For example, "Instantly puts creatures to sleep. Does not work on angry elves." Every item must have a description. The description is visible to users during checkout. Descriptions can be up to 80 characters in length.</p>
+    <p>The description is a long descriptor for the item. For example, "Instantly puts creatures to
+    sleep. Does not work on angry elves." Every item must have a description. The description is
+    visible to users during checkout. Descriptions can be up to 80 characters in length.</p>
   </li>
   <li><strong>Price</strong>
     <p>Every item must have a price greater than zero; you cannot set a price of "0" (free).</p>
   </li>
 </ul>
 
-<p>For more information about product IDs and product lists, see <a href="http://market.android.com/support/bin/answer.py?answer=1072599">Creating In-App Product IDs</a>. For more information about pricing, see <a href="http://market.android.com/support/bin/answer.py?answer=1153485">In-App Billing Pricing</a>.</p>
+<p>For more information about product IDs and product lists, see <a
+href="http://market.android.com/support/bin/answer.py?answer=1072599">Creating In-App Product
+IDs</a>. For more information about pricing, see <a
+href="http://market.android.com/support/bin/answer.py?answer=1153485">In-App Billing
+Pricing</a>.</p>
 
-<p class="note"><strong>Note</strong>: Be sure to plan your product ID namespace. You cannot reuse or modify product IDs after you save them.</p>
+<p class="note"><strong>Note</strong>: Be sure to plan your product ID namespace. You cannot reuse
+or modify product IDs after you save them.</p>
 
 <h3 id="billing-purchase-type">Choosing a Purchase Type</h3>
 
-<p>An item's purchase type controls how Android Market manages the purchase of the item. There are two purchase types: "managed per user account" and "unmanaged."</p>
+<p>An item's purchase type controls how Android Market manages the purchase of the item. There are
+two purchase types: "managed per user account" and "unmanaged."</p>
 
-<p>Items that are managed per user account can be purchased only once per user account. When an item is managed per user account, Android Market permanently stores the transaction information for each item on a per-user basis. This enables you to query Android Market with the <code>RESTORE_TRANSACTIONS</code> request and restore the state of the items a specific user has purchased.</p>
+<p>Items that are managed per user account can be purchased only once per user account. When an item
+is managed per user account, Android Market permanently stores the transaction information for each
+item on a per-user basis. This enables you to query Android Market with the
+<code>RESTORE_TRANSACTIONS</code> request and restore the state of the items a specific user has
+purchased.</p>
 
-<p>If a user attempts to purchase a managed item that has already been purchased, Android Market displays an "Item already purchased" error. This occurs during checkout, when Android Market displays the price and description information on the checkout page. When the user dismisses the error message, the checkout page disappears and the user returns to your user interface. As a best practice, your application should prevent the user from seeing this error. The sample application demonstrates how you can do this by keeping track of items that are managed and already purchased and not allowing users to select those items from the list. Your application should do something similar&mdash;either graying out the item or hiding it so that it cannot be selected.</p>
+<p>If a user attempts to purchase a managed item that has already been purchased, Android Market
+displays an "Item already purchased" error. This occurs during checkout, when Android Market
+displays the price and description information on the checkout page. When the user dismisses the
+error message, the checkout page disappears and the user returns to your user interface. As a best
+practice, your application should prevent the user from seeing this error. The sample application
+demonstrates how you can do this by keeping track of items that are managed and already purchased
+and not allowing users to select those items from the list. Your application should do something
+similar&mdash;either graying out the item or hiding it so that it cannot be selected.</p>
 
-<p>The "manage by user account" purchase type is useful if you are selling items such as game levels or application features. These items are not transient and usually need to be restored whenever a user reinstalls your application, wipes the data on their device, or installs your application on a new device.</p>
+<p>The "manage by user account" purchase type is useful if you are selling items such as game levels
+or application features. These items are not transient and usually need to be restored whenever a
+user reinstalls your application, wipes the data on their device, or installs your application on a
+new device.</p>
 
-<p>Items that are unmanaged do not have their transaction information stored on Android Market, which means you cannot query Android Market to retrieve transaction information for items whose purchase type is listed as unmanaged. You are responsible for managing the transaction information of unmanaged items. Also, unmanaged items can be purchased multiple times as far as Android Market is concerned, so it's also up to you to control how many times an unmanaged item can be purchased.</p>
+<p>Items that are unmanaged do not have their transaction information stored on Android Market,
+which means you cannot query Android Market to retrieve transaction information for items whose
+purchase type is listed as unmanaged. You are responsible for managing the transaction information
+of unmanaged items. Also, unmanaged items can be purchased multiple times as far as Android Market
+is concerned, so it's also up to you to control how many times an unmanaged item can be
+purchased.</p>
 
-<p>The "unmanaged" purchase type is useful if you are selling consumable items, such as fuel or magic spells. These items are consumed within your application and are usually purchased multiple times.</p>
+<p>The "unmanaged" purchase type is useful if you are selling consumable items, such as fuel or
+magic spells. These items are consumed within your application and are usually purchased multiple
+times.</p>
 
 <h2 id="billing-refunds">Handling Refunds</h2>
 
-<p>In-app billing does not allow users to send a refund request to Android Market. Refunds for in-app purchases must be directed to you (the application developer). You can then process the refund through your Google Checkout Merchant account. When you do this, Android Market receives a refund notification from Google Checkout, and Android Market sends a refund message to your application. For more information, see <a href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling IN_APP_NOTIFY messages</a> and <a href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing Pricing</a>.</p>
+<p>In-app billing does not allow users to send a refund request to Android Market. Refunds for
+in-app purchases must be directed to you (the application developer). You can then process the
+refund through your Google Checkout Merchant account. When you do this, Android Market receives a
+refund notification from Google Checkout, and Android Market sends a refund message to your
+application. For more information, see <a
+href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling
+IN_APP_NOTIFY messages</a> and <a
+href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing
+Pricing</a>.</p>
 
 <h2 id="billing-testing-setup">Setting Up Test Accounts</h2>
 
-<p>The Android Market publisher site lets you set up one or more test accounts. A test account is a regular Google account that you register on the publisher site as a test account. Test accounts are authorized to make in-app purchases from applications that you have uploaded to the Android Market site but have not yet published.</p>
+<p>The Android Market publisher site lets you set up one or more test accounts. A test account is a
+regular Google account that you register on the publisher site as a test account. Test accounts are
+authorized to make in-app purchases from applications that you have uploaded to the Android Market
+site but have not yet published.</p>
 
-<p>You can use any Google account as a test account. Test accounts are useful if you want to let multiple people test in-app billing on applications without giving them access to your publisher account's sign-in credentials. 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>
+<p>You can use any Google account as a test account. Test accounts are useful if you want to let
+multiple people test in-app billing on applications without giving them access to your publisher
+account's sign-in credentials. 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>
 
 <p>Test accounts have three limitations:</p>
 
 <ul>
-  <li>Test account users can make purchase requests only within applications that are already uploaded to your publisher account (although the application doesn't need to be published).</li>
-  <li>Test accounts can only be used to purchase items that are listed (and published) in an application's product list.</li>
-  <li>Test account users do not have access to your publisher account and cannot upload applications to your publisher account.</li>
+  <li>Test account users can make purchase requests only within applications that are already
+  uploaded to your publisher account (although the application doesn't need to be published).</li>
+  <li>Test accounts can only be used to purchase items that are listed (and published) in an
+  application's product list.</li>
+  <li>Test account users do not have access to your publisher account and cannot upload applications
+  to your publisher account.</li>
 </ul>
 
 <p>To add test accounts to your publisher account, follow these steps:</p>
@@ -134,21 +230,27 @@
 <ol>
   <li><a href="http://market.android.com/publish">Log in</a> to your publisher account.</li>
   <li>On the upper left part of the page, under your name, click <strong>Edit profile</strong>.</li>
-  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure 4).</li>
-  <li>In Test Accounts, add the email addresses for the test accounts you want to register, separating each account with a comma.</li>
+  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure
+  4).</li>
+  <li>In Test Accounts, add the email addresses for the test accounts you want to register,
+  separating each account with a comma.</li>
   <li>Click <strong>Save</strong> to save your profile changes.</li>
 </ol>
 
 <img src="{@docRoot}images/billing_public_key.png" height="510" id="figure4" />
 <p class="img-caption">
-  <strong>Figure 4.</strong> The Licensing and In-app Billing panel of your account's Edit Profile page lets you register test accounts.
+  <strong>Figure 4.</strong> The Licensing and In-app Billing panel of your account's Edit Profile
+  page lets you register test accounts.
 </p>
 
 <h2 id="billing-support">Where to Get Support</h2>
 
-<p>If you have questions or encounter problems while implementing in-app billing, contact the support resources listed in the following table (see table 2). By directing your queries to the correct forum, you can get the support you need more quickly.</p>
+<p>If you have questions or encounter problems while implementing in-app billing, contact the
+support resources listed in the following table (see table 2). By directing your queries to the
+correct forum, you can get the support you need more quickly.</p>
 
-<p class="table-caption" id="support-table"><strong>Table 2.</strong> Developer support resources for Android Market in-app billing.</p>
+<p class="table-caption" id="support-table"><strong>Table 2.</strong> Developer support resources
+for Android Market in-app billing.</p>
 
 <table>
 
@@ -159,12 +261,15 @@
 </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">In-app billing integration questions, user experience ideas, handling of responses, obfuscating code, IPC, test environment setup.</td>
+<td>Google Groups: <a
+href="http://groups.google.com/group/android-developers">android-developers</a> </td>
+<td rowspan="2">In-app billing integration questions, user experience ideas, handling of responses,
+obfuscating code, 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>
+href="http://stackoverflow.com/questions/tagged/android">http://stackoverflow.com/questions/tagged/
+android</a></td>
 </tr>
 <tr>
 <td>Market billing issue tracker</td>
@@ -174,7 +279,9 @@
 </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>
+<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/billing/billing_best_practices.jd b/docs/html/guide/market/billing/billing_best_practices.jd
index 6f9f64c..d9776af 100755
--- a/docs/html/guide/market/billing/billing_best_practices.jd
+++ b/docs/html/guide/market/billing/billing_best_practices.jd
@@ -11,62 +11,101 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>As you design your in-app billing implementation, be sure to follow the security and design guidelines that are discussed in this document. These guidelines are recommended best practices for anyone who is using Android Market's in-app billing service.</p>
+<p>As you design your in-app billing implementation, be sure to follow the security and design
+guidelines that are discussed in this document. These guidelines are recommended best practices for
+anyone who is using Android Market's in-app billing service.</p>
 
 <h2>Security Best Practices</h2>
 
 <h4>Perform signature verification tasks on a server</h4>
-<p>If practical, you should perform signature verification on a remote server and not on a device. Implementing the verification process on a server makes it difficult for attackers to break the verification process by reverse engineering your .apk file. If you do offload security processing to a remote server, be sure that the device-server handshake is secure.</p>
+<p>If practical, you should perform signature verification on a remote server and not on a device.
+Implementing the verification process on a server makes it difficult for attackers to break the
+verification process by reverse engineering your .apk file. If you do offload security processing to
+a remote server, be sure that the device-server handshake is secure.</p>
 
 <h4>Protect your unlocked content</h4>
-<p>To prevent malicious users from redistributing your unlocked content, do not bundle it in your .apk file. Instead, do one of the following:</p>
+<p>To prevent malicious users from redistributing your unlocked content, do not bundle it in your
+.apk file. Instead, do one of the following:</p>
   <ul>
-    <li>Use a real-time service to deliver your content, such as a content feed. Delivering content through a real-time service allows you to keep your content fresh.</li>
+    <li>Use a real-time service to deliver your content, such as a content feed. Delivering content
+    through a real-time service allows you to keep your content fresh.</li>
     <li>Use a remote server to deliver your content.</li>
   </ul>
-<p>When you deliver content from a remote server or a real-time service, you can store the unlocked content in device memory or store it on the device's SD card. If you store content on an SD card, be sure to encrypt the content and use a device-specific encryption key.</p>
+<p>When you deliver content from a remote server or a real-time service, you can store the unlocked
+content in device memory or store it on the device's SD card. If you store content on an SD card, be
+sure to encrypt the content and use a device-specific encryption key.</p>
 
 <h4>Obfuscate your code</h4>
-<p>You should obfuscate your in-app billing code so it is difficult for an attacker to reverse engineer security protocols and other application components. At a minimum, we recommend that you run an  obfuscation tool like <a href="http://developer.android.com/guide/developing/tools/proguard.html">Proguard</a> on your code.</p>
-<p>In addition to running an obfuscation program, we recommend that you use the following techniques to obfuscate your in-app billing code.</p>
+<p>You should obfuscate your in-app billing code so it is difficult for an attacker to reverse
+engineer security protocols and other application components. At a minimum, we recommend that you
+run an  obfuscation tool like <a
+href="http://developer.android.com/guide/developing/tools/proguard.html">Proguard</a> on your
+code.</p>
+<p>In addition to running an obfuscation program, we recommend that you use the following techniques
+to obfuscate your in-app billing code.</p>
 <ul>
   <li>Inline methods into other methods.</li>
   <li>Construct strings on the fly instead of defining them as constants.</li>
   <li>Use Java reflection to call methods.</li>
 </ul>
-<p>Using these techniques can help reduce the attack surface of your application and help minimize attacks that can compromise your in-app billing implementation.</p>
+<p>Using these techniques can help reduce the attack surface of your application and help minimize
+attacks that can compromise your in-app billing implementation.</p>
 <div class="note">
-  <p><strong>Note:</strong> If you use Proguard to obfuscate your code, you must add the following line to your Proguard configuration file:</p>
+  <p><strong>Note:</strong> If you use Proguard to obfuscate your code, you must add the following
+  line to your Proguard configuration file:</p>
   <p><code>-keep class com.android.vending.billing.**</code></p>
 </div>
   
 <h4>Modify all sample application code</h4>
-<p>The in-app billing sample application is publicly distributed and can be downloaded by anyone, which means it is relatively easy for an attacker to reverse engineer your application if you use the sample code exactly as it is published. The sample application is intended to be used only as an example. If you use any part of the sample application, you must modify it before you publish it or release it as part of a production application.</p>
-<p>In particular, attackers look for known entry points and exit points in an application, so it is important that you modify these parts of your code that are identical to the sample application.</p>
+<p>The in-app billing sample application is publicly distributed and can be downloaded by anyone,
+which means it is relatively easy for an attacker to reverse engineer your application if you use
+the sample code exactly as it is published. The sample application is intended to be used only as an
+example. If you use any part of the sample application, you must modify it before you publish it or
+release it as part of a production application.</p>
+<p>In particular, attackers look for known entry points and exit points in an application, so it is
+important that you modify these parts of your code that are identical to the sample application.</p>
 
 <h4>Use secure random nonces</h4>
-<p>Nonces must not be predictable or reused. Always use a cryptographically secure random number generator (like {@link java.security.SecureRandom}) when you generate nonces. This can help reduce replay attacks.</p>
-<p>Also, if you are performing nonce verification on a server, make sure that you generate the nonces on the server.</p>
+<p>Nonces must not be predictable or reused. Always use a cryptographically secure random number
+generator (like {@link java.security.SecureRandom}) when you generate nonces. This can help reduce
+replay attacks.</p>
+<p>Also, if you are performing nonce verification on a server, make sure that you generate the
+nonces on the server.</p>
 
 <h4>Take action against trademark and copyright infringement</h4>
-<p>If you see your content being redistributed on Android Market, act quickly and decisively. File a <a href="http://market.android.com/support/bin/answer.py?hl=en&amp;answer=141511">trademark notice of infringement</a> or a <a href="http://www.google.com/android_dmca.html">copyright notice of infringement</a>.</p>
+<p>If you see your content being redistributed on Android Market, act quickly and decisively. File a
+<a href="http://market.android.com/support/bin/answer.py?hl=en&amp;answer=141511">trademark notice
+of infringement</a> or a <a href="http://www.google.com/android_dmca.html">copyright notice of
+infringement</a>.</p>
 
 <h4>Implement a revocability scheme for unlocked content</h4>
-<p>If you are using a remote server to deliver or manage content, have your application verify the purchase state of the unlocked content whenever a user accesses the content. This allows you to revoke use when necessary and minimize piracy.</p>
+<p>If you are using a remote server to deliver or manage content, have your application verify the
+purchase state of the unlocked content whenever a user accesses the content. This allows you to
+revoke use when necessary and minimize piracy.</p>
 
 <h4>Protect your Android Market public key</h4>
-<p>To keep your public key safe from malicious users and hackers, do not embed it in any code as a literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the actual key. The key itself is not secret information, but you do not want to make it easy for a hacker or malicious user to replace the public key with another key.</p>
+<p>To keep your public key safe from malicious users and hackers, do not embed it in any code as a
+literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for
+example, XOR with some other string) to hide the actual key. The key itself is not secret
+information, but you do not want to make it easy for a hacker or malicious user to replace the
+public key with another key.</p>
 
diff --git a/docs/html/guide/market/billing/billing_integrate.jd b/docs/html/guide/market/billing/billing_integrate.jd
index 7532337..f57ebe3 100755
--- a/docs/html/guide/market/billing/billing_integrate.jd
+++ b/docs/html/guide/market/billing/billing_integrate.jd
@@ -21,33 +21,50 @@
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>Android Market In-app Billing provides a straightforward, simple interface for sending in-app billing requests and managing in-app billing transactions using Android Market. This document helps you implement in-app billing by stepping through the primary implementation tasks, using the in-app billing sample application as an example.</p>
+<p>Android Market In-app Billing provides a straightforward, simple interface for sending in-app
+billing requests and managing in-app billing transactions using Android Market. This document helps
+you implement in-app billing by stepping through the primary implementation tasks, using the in-app
+billing sample application as an example.</p>
 
-<p>Before you implement in-app billing in your own application, be sure that you read <a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a> and <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>. These documents provide background information that will make it easier for you to implement in-app billing.</p>
+<p>Before you implement in-app billing in your own application, be sure that you read <a
+href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a> and <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>. These
+documents provide background information that will make it easier for you to implement in-app
+billing.</p>
 
 <p>To implement in-app billing in your application, you need to do the following:</p>
 <ol>
   <li><a href="#billing-download">Download the in-app billing sample application</a>.</li>
   <li><a href="#billing-add-aidl">Add the IMarketBillingService.aidl file</a> to your project.</li>
   <li><a href="#billing-permission">Update your AndroidManifest.xml file</a>.</li>
-  <li><a href="#billing-service">Create a Service</a> and bind it to the <code>MarketBillingService</code> so your application can send billing requests and receive billing responses from the Android Market application.</li>
-  <li><a href="#billing-broadcast-receiver">Create a BroadcastReceiver</a> to handle broadcast intents from the Android Market application.</li>
-  <li><a href="#billing-signatures">Create a security processing component</a> to verify the integrity of the transaction messages that are sent by Android Market .</li>
+  <li><a href="#billing-service">Create a Service</a> and bind it to the
+  <code>MarketBillingService</code> so your application can send billing requests and receive
+  billing responses from the Android Market application.</li>
+  <li><a href="#billing-broadcast-receiver">Create a BroadcastReceiver</a> to handle broadcast
+  intents from the Android Market application.</li>
+  <li><a href="#billing-signatures">Create a security processing component</a> to verify the
+  integrity of the transaction messages that are sent by Android Market .</li>
   <li><a href="#billing-implement">Modify your application code</a> to support in-app billing.</li>
 </ol>
 
 <h2 id="billing-download">Downloading the Sample Application</h2>
 
-<p>The in-app billing sample application shows you how to perform several tasks that are common to all Android Market in-app billing implementations, including:</p>
+<p>The in-app billing sample application shows you how to perform several tasks that are common to
+all Android Market in-app billing implementations, including:</p>
 
 <ul>
   <li>Sending in-app billing requests to the Android Market application.</li>
@@ -57,10 +74,14 @@
   <li>Creating a user interface that lets users select items for purchase.</li>
 </ul>
 
-<p>The sample application includes an application file (<code>Dungeons.java</code>), the AIDL file for the <code>MarketBillingService</code> (<code>IMarketBillingService.aidl</code>), and several classes that demonstrate in-app billing messaging. It also includes a class that demonstrates basic security tasks, such as signature verification.</p>
+<p>The sample application includes an application file (<code>Dungeons.java</code>), the AIDL file
+for the <code>MarketBillingService</code> (<code>IMarketBillingService.aidl</code>), and several
+classes that demonstrate in-app billing messaging. It also includes a class that demonstrates basic
+security tasks, such as signature verification.</p>
 
 <p>Table 1 lists the source files that are included with the sample application.</p>
-<p class="table-caption" id="source-files-table"><strong>Table 1.</strong> In-app billing sample application source files.</p>
+<p class="table-caption" id="source-files-table"><strong>Table 1.</strong> In-app billing sample
+application source files.</p>
 
 <table>
 <tr>
@@ -70,12 +91,14 @@
 
 <tr>
 <td>IMarketBillingService.aidl</td>
-<td>Android Interface Definition Library (AIDL) file that defines the IPC interface to Android Market's in-app billing service (<code>MarketBillingService</code>).</td>
+<td>Android Interface Definition Library (AIDL) file that defines the IPC interface to Android
+Market's in-app billing service (<code>MarketBillingService</code>).</td>
 </tr>
 
 <tr>
 <td>Dungeons.java</td>
-<td>Sample application file that provides a UI for making purchases and displaying purchase history.</td>
+<td>Sample application file that provides a UI for making purchases and displaying purchase
+history.</td>
 </tr>
 
 <tr>
@@ -85,16 +108,20 @@
 
 <tr>
   <td>BillingReceiver.java</td>
-  <td>A {@link android.content.BroadcastReceiver} that receives asynchronous response messages (broadcast intents) from Android Market. Forwards all messages to the <code>BillingService</code>.</td>
+  <td>A {@link android.content.BroadcastReceiver} that receives asynchronous response messages
+  (broadcast intents) from Android Market. Forwards all messages to the
+  <code>BillingService</code>.</td>
 </tr>
 <tr>
   <td>BillingService.java</td>
-  <td>A {@link android.app.Service} that sends messages to Android Market on behalf of the application by connecting (binding) to the <code>MarketBillingService</code>.</td>
+  <td>A {@link android.app.Service} that sends messages to Android Market on behalf of the
+  application by connecting (binding) to the <code>MarketBillingService</code>.</td>
 </tr>
 
 <tr>
   <td>ResponseHandler.java</td>
-  <td>A {@link android.os.Handler} that contains methods for updating the purchases database and the UI.</td>
+  <td>A {@link android.os.Handler} that contains methods for updating the purchases database and the
+  UI.</td>
 </tr>
 
 <tr>
@@ -109,29 +136,38 @@
 
 <tr>
 <td>Consts.java</td>
-<td>Defines various Android Market constants and sample application constants. All constants that are defined by Android Market must be defined the same way in your application.</td>
+<td>Defines various Android Market constants and sample application constants. All constants that
+are defined by Android Market must be defined the same way in your application.</td>
 </tr>
 
 <tr>
 <td>Base64.java and Base64DecoderException.java</td>
-<td>Provides conversion services from binary to Base64 encoding. The <code>Security</code> class relies on these utility classes.</td>
+<td>Provides conversion services from binary to Base64 encoding. The <code>Security</code> class
+relies on these utility classes.</td>
 </tr>
 
 </table>
 
-<p>The in-app billing sample application is available as a downloadable component of the Android SDK. To download the sample application component, launch the Android SDK and AVD Manager and then select the "Google Market Billing package" component (see figure 1), and click <strong>Install Selected</strong> to begin the download.</p>
+<p>The in-app billing sample application is available as a downloadable component of the Android
+SDK. To download the sample application component, launch the Android SDK and AVD Manager and then
+select the "Google Market Billing package" component (see figure 1), and click <strong>Install
+Selected</strong> to begin the download.</p>
 
 
 <img src="{@docRoot}images/billing_package.png" height="325" id="figure1" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> The Google Market Billing package contains the sample application and the AIDL file.
+  <strong>Figure 1.</strong> The Google Market Billing package contains the sample application and
+  the AIDL file.
 </p>
 
-<p>When the download is complete, the Android SDK and AVD Manager saves the component into the following directory:</p>
+<p>When the download is complete, the Android SDK and AVD Manager saves the component into the
+following directory:</p>
 
 <p><code>&lt;sdk&gt;/google-market_billing/</code></p>
 
-<p>If you want to see an end-to-end demonstration of in-app billing before you integrate in-app billing into your own application, you can build and run the sample application. Building and running the sample application involves three tasks:<p>
+<p>If you want to see an end-to-end demonstration of in-app billing before you integrate in-app
+billing into your own application, you can build and run the sample application. Building and
+running the sample application involves three tasks:<p>
 
 <ul>
   <li>Configuring and building the sample application.</li>
@@ -139,19 +175,28 @@
   <li>Setting up test accounts and running the sample application.</li>
 </ul>
 
-<p class="note"><strong>Note:</strong> Building and running the sample application is necessary only if you want to see a demonstration of in-app billing. If you do not want to run the sample application, you can skip to the next section, <a href="#billing-add-aidl">Adding the AIDL file to your project</a>.</p>
+<p class="note"><strong>Note:</strong> Building and running the sample application is necessary only
+if you want to see a demonstration of in-app billing. If you do not want to run the sample
+application, you can skip to the next section, <a href="#billing-add-aidl">Adding the AIDL file to
+your project</a>.</p>
 
 <h3>Configuring and building the sample application</h3>
 
-<p>Before you can run the sample application, you need to configure it and build it by doing the following:</p>
+<p>Before you can run the sample application, you need to configure it and build it by doing the
+following:</p>
 
 <ol>
   <li><strong>Add your Android Market public key to the sample application code.</strong>
-    <p>This enables the application to verify the signature of the transaction information that is returned from Android Market. To add your public key to the sample application code, do the following:</p>
+    <p>This enables the application to verify the signature of the transaction information that is
+    returned from Android Market. To add your public key to the sample application code, do the
+    following:</p>
     <ol>
-      <li>Log in to your Android Market <a href="http://market.android.com/publish">publisher account</a>.</li>
-      <li>On the upper left part of the page, under your name, click <strong>Edit Profile</strong>.</li>
-      <li>On the Edit Profile page, scroll down to the <strong>Licensing &amp; In-app Billing</strong> panel.</li>
+      <li>Log in to your Android Market <a href="http://market.android.com/publish">publisher
+      account</a>.</li>
+      <li>On the upper left part of the page, under your name, click <strong>Edit
+      Profile</strong>.</li>
+      <li>On the Edit Profile page, scroll down to the <strong>Licensing &amp; In-app
+      Billing</strong> panel.</li>
       <li>Copy your public key.</li>
       <li>Open <code>src/com/example/dungeons/Security.java</code> in the editor of your choice.
         <p>You can find this file in the sample application's project folder.</p>
@@ -163,61 +208,112 @@
     </ol>
   </li>
   <li><strong>Change the package name of the sample application.</strong>
-    <p>The current package name is <code>com.example.dungeons</code>. Android Market does not let you upload applications with package names that contain <code>com.example</code>, so you must change the package name to something else.</p>
+    <p>The current package name is <code>com.example.dungeons</code>. Android Market does not let
+    you upload applications with package names that contain <code>com.example</code>, so you must
+    change the package name to something else.</p>
   </li>
   <li><strong>Build the sample application in release mode and sign it.</strong>
-    <p>To learn how to build and sign applications, see <a href="{@docRoot}guide/developing/building/index.html">Building and Running</a>.</p>
+    <p>To learn how to build and sign applications, see <a
+    href="{@docRoot}guide/developing/building/index.html">Building and Running</a>.</p>
   </li>
 </ol>
 
 <h3>Uploading the sample application</h3>
 
-<p>After you build a release version of the sample application and sign it, you need to upload it as a draft to the Android Market publisher site. You also need to create a product list for the in-app items that are available for purchase in the sample application. The following instructions show you how to do this.</p>
+<p>After you build a release version of the sample application and sign it, you need to upload it as
+a draft to the Android Market publisher site. You also need to create a product list for the in-app
+items that are available for purchase in the sample application. The following instructions show you
+how to do this.</p>
 <ol>
   <li><strong>Upload the release version of the sample application to Android Market.</strong>
-    <p>Do not publish the sample application; leave it as an unpublished draft application. The sample application is for demonstration purposes only and should not be made publicly available on Android Market. To learn how to upload an application to Android Market, see <a href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading applications</a>.</p>
+    <p>Do not publish the sample application; leave it as an unpublished draft application. The
+    sample application is for demonstration purposes only and should not be made publicly available
+    on Android Market. To learn how to upload an application to Android Market, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading
+    applications</a>.</p>
   </li>
   <li><strong>Create a product list for the sample application.</strong>
-    <p>The sample application lets you purchase two items: a two-handed sword (<code>sword_001</code>) and a potion (<code>potion_001</code>). We recommend that you set up your product list so that <code>sword_001</code> has a purchase type of "Managed per user account" and <code>potion_001</code> has a purchase type of "Unmanaged" so you can see how these two purchase types behave. To learn how to set up a product list, see <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">Creating a Product List</a>.</p>
-    <p class="note"><strong>Note:</strong> You must publish the items in your product list (<code>sword_001</code> and <code>potion_001</code>) even though you are not publishing the sample application. Also, you must have a Google Checkout Merchant account to add items to the sample application's product list.</p>
+    <p>The sample application lets you purchase two items: a two-handed sword
+    (<code>sword_001</code>) and a potion (<code>potion_001</code>). We recommend that you set up
+    your product list so that <code>sword_001</code> has a purchase type of "Managed per user
+    account" and <code>potion_001</code> has a purchase type of "Unmanaged" so you can see how these
+    two purchase types behave. To learn how to set up a product list, see <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">Creating a Product
+    List</a>.</p>
+    <p class="note"><strong>Note:</strong> You must publish the items in your product
+    list (<code>sword_001</code> and <code>potion_001</code>) even though you are not publishing the
+    sample application. Also, you must have a Google Checkout Merchant account to add items to the
+    sample application's product list.</p>
   </li>
 </ol>
 
 <h3>Running the sample application</h3>
 
-<p>You cannot run the sample application in the emulator. You must install the sample application onto a device to run it. To run the sample application, do the following:</p>
+<p>You cannot run the sample application in the emulator. You must install the sample application
+onto a device to run it. To run the sample application, do the following:</p>
 
 <ol>
-  <li><strong>Make sure you have at least one test account registered under your Android Market publisher account.</strong>
-    <p>You cannot purchase items from yourself (Google Checkout prohibits this), so you need to create at least one test account that you can use to purchase items in the sample application. To learn how to set up a test account, see <a href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-setup">Setting up Test Accounts</a>.</p>
+  <li><strong>Make sure you have at least one test account registered under your Android Market
+  publisher account.</strong>
+    <p>You cannot purchase items from yourself (Google Checkout prohibits this), so you need to
+    create at least one test account that you can use to purchase items in the sample application.
+    To learn how to set up a test account, see <a
+    href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-setup">Setting up Test
+    Accounts</a>.</p>
   </li>
-  <li><strong>Verify that your device is running a supported version of the Android Market application or the MyApps application.</strong>
-    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>.</p>
+  <li><strong>Verify that your device is running a supported version of the Android Market
+  application or the MyApps application.</strong>
+    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+    the MyApps application. If your device is running any other version of Android, in-app billing
+    requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the
+    version of the Android Market application, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android
+    Market</a>.</p>
   </li>
   <li><strong>Install the application onto your device.</strong>
-    <p>Even though you uploaded the application to Android Market, the application is not published, so you cannot download it from Android Market to a device. Instead, you must install the application onto your device. To learn how to install an application onto a device, see <a href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a device</a>.</p>
+    <p>Even though you uploaded the application to Android Market, the application is not published,
+    so you cannot download it from Android Market to a device. Instead, you must install the
+    application onto your device. To learn how to install an application onto a device, see <a
+    href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a
+    device</a>.</p>
  </li>
  <li><strong>Make one of your test accounts the primary account on your device.</strong>
-    <p>The primary account on your device must be one of the <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:</p>
+    <p>The primary account on your device must be one of the <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a>
+    that you registered on the Android Market site. If the primary account on your device is not a
+    test account, you must do a factory reset of the device and then sign in with one of your test
+    accounts. To perform a factory reset, do the following:</p>
     <ol>
       <li>Open Settings on your device.</li>
       <li>Touch <strong>Privacy</strong>.</li>
       <li>Touch <strong>Factory data reset</strong>.</li>
       <li>Touch <strong>Reset phone</strong>.</li>
-      <li>After the phone resets, be sure to sign in with one of your test accounts during the device setup process.</li>
+      <li>After the phone resets, be sure to sign in with one of your test accounts during the
+      device setup process.</li>
     </ol>
   </li>
   <li><strong>Run the application and purchase the sword or the potion.</strong>
-    <p>When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.</p>
+    <p>When you use a test account to purchase items, the test account is billed through Google
+    Checkout and your Google Checkout Merchant account receives a payout for the purchase.
+    Therefore, you may want to refund purchases that are made with test accounts, otherwise the
+    purchases will show up as actual payouts to your merchant account.</p>
 </ol>
 
 <p class="note"><strong>Note</strong>: Debug log messages are turned off by default in the sample application. You can turn them on by setting the variable <code>DEBUG</code> to <code>true</code> in the <code>Consts.java</code> file.</p>
 
 <h2 id="billing-add-aidl">Adding the AIDL file to your project</h2>
 
-<p>The sample application contains an Android Interface Definition Language (AIDL) file,  which defines the interface to Android Market's in-app billing service (<code>MarketBillingService</code>). When you add this file to your project, the Android build environment creates an interface file (<code>IMarketBillingService.java</code>). You can then use this interface to make billing requests by invoking IPC method calls.</p>
+<p>The sample application contains an Android Interface Definition Language (AIDL) file,  which
+defines the interface to Android Market's in-app billing service
+(<code>MarketBillingService</code>). When you add this file to your project, the Android build
+environment creates an interface file (<code>IMarketBillingService.java</code>). You can then use
+this interface to make billing requests by invoking IPC method calls.</p>
 
-<p>If you are using the ADT plug-in with Eclipse, you can just add this file to your <code>/src</code> directory. Eclipse will automatically generate the interface file when you build your project (which should happen immediately). If you are not using the ADT plug-in, you can put the AIDL file into your project and use the Ant tool to build your project so that the <code>IMarketBillingService.java</code> file gets generated.</p>
+<p>If you are using the ADT plug-in with Eclipse, you can just add this file to your
+<code>/src</code> directory. Eclipse will automatically generate the interface file when you build
+your project (which should happen immediately). If you are not using the ADT plug-in, you can put
+the AIDL file into your project and use the Ant tool to build your project so that the
+<code>IMarketBillingService.java</code> file gets generated.</p>
 
 <p>To add the <code>IMarketBillingService.aidl</code> file to your project, do the following:</p>
 
@@ -225,19 +321,39 @@
   <li>Create the following directory in your application's <code>/src</code> directory:
     <p><code>com/android/vending/billing/</code></p>
   </li>
-  <li>Copy the <code>IMarketBillingService.aidl</code> file into the <code>sample/src/com/android/vending/billing/</code> directory.</li>
+  <li>Copy the <code>IMarketBillingService.aidl</code> file into the
+  <code>sample/src/com/android/vending/billing/</code> directory.</li>
   <li>Build your application.</li>
 </ol>
 
-<p>You should now find a generated interface file named <code>IMarketBillingService.java</code> in the <code>gen</code> folder of your project.</p>
+<p>You should now find a generated interface file named <code>IMarketBillingService.java</code> in
+the <code>gen</code> folder of your project.</p>
 
 <h2 id="billing-permission">Updating Your Application's Manifest</h2>
 
-<p>In-app billing relies on the Android Market application, which handles all communication between your application and the Android Market server. To use the Android Market application, your application must request the proper permission. You can do this by adding the <code>com.android.vending.BILLING</code> permission to your AndroidManifest.xml file. If your application does not declare the in-app billing permission, but attempts to send billing requests, Android Market will refuse the requests and respond with a <code>RESULT_DEVELOPER_ERROR</code> response code.</p>
+<p>In-app billing relies on the Android Market application, which handles all communication between
+your application and the Android Market server. To use the Android Market application, your
+application must request the proper permission. You can do this by adding the
+<code>com.android.vending.BILLING</code> permission to your AndroidManifest.xml file. If your
+application does not declare the in-app billing permission, but attempts to send billing requests,
+Android Market will refuse the requests and respond with a <code>RESULT_DEVELOPER_ERROR</code>
+response code.</p>
 
-<p>In addition to the billing permission, you need to declare the {@link android.content.BroadcastReceiver} that you will use to receive asynchronous response messages (broadcast intents) from Android Market, and you need to declare the {@link android.app.Service} that you will use to bind with the <code>IMarketBillingService</code> and send messages to Android Market. You must also declare <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">intent filters</a> for the {@link android.content.BroadcastReceiver} so that the Android system knows how to handle the broadcast intents that are sent from the Android Market application.</p>
+<p>In addition to the billing permission, you need to declare the {@link
+android.content.BroadcastReceiver} that you will use to receive asynchronous response messages
+(broadcast intents) from Android Market, and you need to declare the {@link android.app.Service}
+that you will use to bind with the <code>IMarketBillingService</code> and send messages to Android
+Market. You must also declare <a
+href="{@docRoot}guide/topics/manifest/intent-filter-element.html">intent filters</a> for the {@link
+android.content.BroadcastReceiver} so that the Android system knows how to handle the broadcast
+intents that are sent from the Android Market application.</p>
 
-<p>For example, here is how the in-app billing sample application declares the billing permission, the {@link android.content.BroadcastReceiver}, the {@link android.app.Service}, and the intent filters. In the sample application, <code>BillingReceiver</code> is the {@link android.content.BroadcastReceiver} that handles broadcast intents from the Android Market application and <code>BillingService</code> is the {@link android.app.Service} that sends requests to the Android Market application.</p>
+<p>For example, here is how the in-app billing sample application declares the billing permission,
+the {@link android.content.BroadcastReceiver}, the {@link android.app.Service}, and the intent
+filters. In the sample application, <code>BillingReceiver</code> is the {@link
+android.content.BroadcastReceiver} that handles broadcast intents from the Android Market
+application and <code>BillingService</code> is the {@link android.app.Service} that sends requests
+to the Android Market application.</p>
 
 <pre>
 &lt;?xml version="1.0" encoding="utf-8"?&gt;
@@ -272,11 +388,13 @@
 
 <h2 id="billing-service">Creating a Local Service</h2>
 
-<p>Your application must have a local {@link android.app.Service} to facilitate messaging between your application and Android Market. At a minimum, this service must do the following:</p>
+<p>Your application must have a local {@link android.app.Service} to facilitate messaging between
+your application and Android Market. At a minimum, this service must do the following:</p>
 
 <ul>
   <li>Bind to the <code>MarketBillingService</code>.
-  <li>Send billing requests (as IPC method calls) to the Android Market application. The five types of billing requests include:
+  <li>Send billing requests (as IPC method calls) to the Android Market application. The five types
+  of billing requests include:
     <ul>
       <li><code>CHECK_BILLING_SUPPORTED</code> requests</li>
       <li><code>REQUEST_PURCHASE</code> requests</li>
@@ -290,12 +408,17 @@
 
 <h3>Binding to the MarketBillingService</h3>
 
-<p>Binding to the <code>MarketBillingService</code> is relatively easy if you've already added the <code>IMarketBillingService.aidl</code> file to your project. The following code sample shows how to use the {@link android.content.Context#bindService bindService()} method to bind a service to the <code>MarketBillingService</code>. You could put this code in your service's {@link android.app.Activity#onCreate onCreate()} method.</p>
+<p>Binding to the <code>MarketBillingService</code> is relatively easy if you've already added the
+<code>IMarketBillingService.aidl</code> file to your project. The following code sample shows how to
+use the {@link android.content.Context#bindService bindService()} method to bind a service to the
+<code>MarketBillingService</code>. You could put this code in your service's {@link
+android.app.Activity#onCreate onCreate()} method.</p>
 
 <pre>
 try {
   boolean bindResult = mContext.bindService(
-    new Intent("com.android.vending.billing.MarketBillingService.BIND"), this, Context.BIND_AUTO_CREATE);
+    new Intent("com.android.vending.billing.MarketBillingService.BIND"), this,
+    Context.BIND_AUTO_CREATE);
   if (bindResult) {
     Log.i(TAG, "Service bind successful.");
   } else {
@@ -306,7 +429,10 @@
 }
 </pre>
 
-<p>After you bind to the service, you need to create a reference to the <code>IMarketBillingService</code> interface so you can make billing requests via IPC method calls. The following code shows you how to do this using the {@link android.content.ServiceConnection#onServiceConnected onServiceConnected()} callback method.</p>
+<p>After you bind to the service, you need to create a reference to the
+<code>IMarketBillingService</code> interface so you can make billing requests via IPC method calls.
+The following code shows you how to do this using the {@link
+android.content.ServiceConnection#onServiceConnected onServiceConnected()} callback method.</p>
 
 <pre>
 /**
@@ -318,24 +444,51 @@
   }
 </pre>
 
-<p>You can now use the <code>mService</code> reference to invoke the <code>sendBillingRequest()</code> method.</p>
+<p>You can now use the <code>mService</code> reference to invoke the
+<code>sendBillingRequest()</code> method.</p>
 
-<p>For a complete implementation of a service that binds to the <code>MarketBillingService</code>, see the <code>BillingService</code> class in the sample application.</p>
+<p>For a complete implementation of a service that binds to the <code>MarketBillingService</code>,
+see the <code>BillingService</code> class in the sample application.</p>
 
 <h3>Sending billing requests to the MarketBillingService</h3>
 
-<p>Now that your {@link android.app.Service} has a reference to the <code>IMarketBillingService</code> interface, you can use that reference to send billing requests (via IPC method calls) to the <code>MarketBillingService</code>. The <code>MarketBillingService</code> IPC interface exposes a single public method (<code>sendBillingRequest()</code>), which takes a single {@link android.os.Bundle} parameter. The Bundle that you deliver with this method specifies the type of request you want to perform, using various key-value pairs. For instance, one key indicates the type of request you are making, another indicates the item being purchased, and another identifies your application. The <code>sendBillingRequest()</code> method immediately returns a Bundle containing an initial response code. However, this is not the complete purchase response; the complete response is delivered with an asynchronous broadcast intent. For more information about the various Bundle keys that are supported by the <code>MarketBillingService</code>, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing Service Interface</a>.</p>
+<p>Now that your {@link android.app.Service} has a reference to the
+<code>IMarketBillingService</code> interface, you can use that reference to send billing requests
+(via IPC method calls) to the <code>MarketBillingService</code>. The
+<code>MarketBillingService</code> IPC interface exposes a single public method
+(<code>sendBillingRequest()</code>), which takes a single {@link android.os.Bundle} parameter. The
+Bundle that you deliver with this method specifies the type of request you want to perform, using
+various key-value pairs. For instance, one key indicates the type of request you are making, another
+indicates the item being purchased, and another identifies your application. The
+<code>sendBillingRequest()</code> method immediately returns a Bundle containing an initial response
+code. However, this is not the complete purchase response; the complete response is delivered with
+an asynchronous broadcast intent. For more information about the various Bundle keys that are
+supported by the <code>MarketBillingService</code>, see <a
+href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing
+Service Interface</a>.</p>
 
-<p>You can use the <code>sendBillingRequest()</code> method to send five types of billing requests. The five request types are specified using the <code>BILLING_REQUEST</code> Bundle key. This Bundle key can have the following five values:</p>
+<p>You can use the <code>sendBillingRequest()</code> method to send five types of billing requests.
+The five request types are specified using the <code>BILLING_REQUEST</code> Bundle key. This Bundle
+key can have the following five values:</p>
 
 <ul>
-  <li><code>CHECK_BILLING_SUPPORTED</code>&mdash;verifies that the Android Market application supports in-app billing.</li>
-  <li><code>REQUEST_PURCHASE</code>&mdash;sends a purchase request for an in-app item.</li>  <li><code>GET_PURCHASE_INFORMATION</code>&mdash;retrieves transaction information for a purchase or refund.</li>
-  <li><code>CONFIRM_NOTIFICATIONS</code>&mdash;acknowledges that you received the transaction information for a purchase or refund.</li>
-  <li><code>RESTORE_TRANSACTIONS</code>&mdash;retrieves a user's transaction history for <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed purchases</a>.</li>
+  <li><code>CHECK_BILLING_SUPPORTED</code>&mdash;verifies that the Android Market application
+  supports in-app billing.</li>
+  <li><code>REQUEST_PURCHASE</code>&mdash;sends a purchase request for an in-app item.</li> 
+  <li><code>GET_PURCHASE_INFORMATION</code>&mdash;retrieves transaction information for a purchase
+  or refund.</li>
+  <li><code>CONFIRM_NOTIFICATIONS</code>&mdash;acknowledges that you received the transaction
+  information for a purchase or refund.</li>
+  <li><code>RESTORE_TRANSACTIONS</code>&mdash;retrieves a user's transaction history for <a
+  href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed
+  purchases</a>.</li>
 </ul>
 
-<p>To make any of these billing requests, you first need to build an initial {@link android.os.Bundle} that contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The following code sample shows you how to create a helper method named <code>makeRequestBundle()</code> that does this.</p>
+<p>To make any of these billing requests, you first need to build an initial {@link
+android.os.Bundle} that contains the three keys that are required for all requests:
+<code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The following
+code sample shows you how to create a helper method named <code>makeRequestBundle()</code> that does
+this.</p>
 
 <pre>
 protected Bundle makeRequestBundle(String method) {
@@ -346,13 +499,18 @@
   return request;
 </pre>
 
-<p>To use this helper method, you pass in a <code>String</code> that corresponds to one of the five types of billing requests. The method returns a Bundle that has the three required keys defined. The following sections show you how to use this helper method when you send a billing request.<p>
+<p>To use this helper method, you pass in a <code>String</code> that corresponds to one of the five
+types of billing requests. The method returns a Bundle that has the three required keys defined. The
+following sections show you how to use this helper method when you send a billing request.<p>
 
-<p class="caution"><strong>Important</strong>: You must make all in-app billing requests from your application's main thread.</p>
+<p class="caution"><strong>Important</strong>: You must make all in-app billing requests from your
+application's main thread.</p>
 
 <h4>Verifying that in-app billing is supported (CHECK_BILLING_SUPPPORTED)</h4>
 
-<p>The following code sample shows how to verify whether the Android Market application supports in-app billing. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>The following code sample shows how to verify whether the Android Market application supports
+in-app billing. In the sample, <code>mService</code> is an instance of the
+<code>MarketBillingService</code> interface.</p>
 
 <pre>
 /**
@@ -363,19 +521,37 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The request returns a synchronous {@link android.os.Bundle} response, which contains only a single key: <code>RESPONSE_CODE</code>. The <code>RESPONSE_CODE</code> key can have the following values:</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The request returns a synchronous {@link
+android.os.Bundle} response, which contains only a single key: <code>RESPONSE_CODE</code>. The
+<code>RESPONSE_CODE</code> key can have the following values:</p>
 <ul>
   <li><code>RESULT_OK</code>&mdash;in-app billing is supported.</li>
-  <li><code>RESULT_BILLING_UNAVAILABLE</code>&mdash;in-app billing is not available because the API version you specified is not recognized or the user is not eligible to make in-app purchases (for example, the user resides in a country that prohibits in-app purchases).</li>
-  <li><code>RESULT_ERROR</code>&mdash;there was an error connecting with the Android Market application.</li>
-  <li><code>RESULT_DEVELOPER_ERROR</code>&mdash;the application is trying to make an in-app billing request but the application has not declared the <code>com.android.vending.BILLING</code> permission in its manifest. Can also indicate that an application is not properly signed, or that you sent a malformed request.</li>
+  <li><code>RESULT_BILLING_UNAVAILABLE</code>&mdash;in-app billing is not available because the API
+  version you specified is not recognized or the user is not eligible to make in-app purchases (for
+  example, the user resides in a country that prohibits in-app purchases).</li>
+  <li><code>RESULT_ERROR</code>&mdash;there was an error connecting with the Android Market
+  application.</li>
+  <li><code>RESULT_DEVELOPER_ERROR</code>&mdash;the application is trying to make an in-app billing
+  request but the application has not declared the <code>com.android.vending.BILLING</code>
+  permission in its manifest. Can also indicate that an application is not properly signed, or that
+  you sent a malformed request.</li>
 </ul>
 
-<p>The <code>CHECK_BILLING_SUPPORTED</code> request does not trigger any asynchronous responses (broadcast intents).</p>
+<p>The <code>CHECK_BILLING_SUPPORTED</code> request does not trigger any asynchronous responses
+(broadcast intents).</p>
 
-<p>We recommend that you invoke the <code>CHECK_BILLING_SUPPORTED</code> request within a <code>RemoteException</code> block. When your code throws a <code>RemoteException</code> it indicates that the remote method call failed, which means that the Android Market application is out of date and needs to be updated. In this case, you can provide users with an error message that contains a link to the <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a> Help topic.</p>
+<p>We recommend that you invoke the <code>CHECK_BILLING_SUPPORTED</code> request within a
+<code>RemoteException</code> block. When your code throws a <code>RemoteException</code> it
+indicates that the remote method call failed, which means that the Android Market application is out
+of date and needs to be updated. In this case, you can provide users with an error message that
+contains a link to the <a
+href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>
+Help topic.</p>
 
-<p>The sample application demonstrates how you can handle this error condition (see <code>DIALOG_CANNOT_CONNECT_ID</code> in <code>Dungeons.java</code>).</p>
+<p>The sample application demonstrates how you can handle this error condition (see
+<code>DIALOG_CANNOT_CONNECT_ID</code> in <code>Dungeons.java</code>).</p>
 
 <h4>Making a purchase request (REQUEST_PURCHASE)</h4>
 
@@ -383,13 +559,19 @@
 
 <ul>
   <li>Send the <code>REQUEST_PURCHASE</code> request.</li>
-  <li>Launch the {@link android.app.PendingIntent} that is returned from the Android Market application.</li>
+  <li>Launch the {@link android.app.PendingIntent} that is returned from the Android Market
+  application.</li>
   <li>Handle the broadcast intents that are sent by the Android Market application.</li>
 </ul>
 
 <h5>Making the request</h5>
 
-<p>You must specify four keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make a purchase request for a single in-app item. In the sample, <code>mProductId</code> is the Android Market product ID of an in-app item (which is listed in the application's <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">product list</a>), and <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>You must specify four keys in the request {@link android.os.Bundle}. The following code sample
+shows how to set these keys and make a purchase request for a single in-app item. In the sample,
+<code>mProductId</code> is the Android Market product ID of an in-app item (which is listed in the
+application's <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">product
+list</a>), and <code>mService</code> is an instance of the <code>MarketBillingService</code>
+interface.</p>
 
 <pre>
 /**
@@ -404,13 +586,26 @@
   // Do something with this response.
   }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The <code>ITEM_ID</code> key is then added to the Bundle prior to invoking the <code>sendBillingRequest()</code> method.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The <code>ITEM_ID</code> key is then added
+to the Bundle prior to invoking the <code>sendBillingRequest()</code> method.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains three keys: <code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request. The <code>PURCHASE_INTENT</code> key provides you with a {@link android.app.PendingIntent}, which you can use to launch the checkout UI.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains three keys:
+<code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The
+<code>RESPONSE_CODE</code> key provides you with the status of the request and the
+<code>REQUEST_ID</code> key provides you with a unique request identifier for the request. The
+<code>PURCHASE_INTENT</code> key provides you with a {@link android.app.PendingIntent}, which you
+can use to launch the checkout UI.</p>
 
 <h5>Launching the pending intent</h5>
 
-<p>How you use the pending intent depends on which version of Android a device is running. On Android 1.6, you must use the pending intent to launch the checkout UI in its own separate task instead of your application's activity stack. On Android 2.0 and higher, you can use the pending intent to launch the checkout UI on your application's activity stack. The following code shows you how to do this. You can find this code in the <code>PurchaseObserver.java</code> file in the sample application.</p>
+<p>How you use the pending intent depends on which version of Android a device is running. On
+Android 1.6, you must use the pending intent to launch the checkout UI in its own separate task
+instead of your application's activity stack. On Android 2.0 and higher, you can use the pending
+intent to launch the checkout UI on your application's activity stack. The following code shows you
+how to do this. You can find this code in the <code>PurchaseObserver.java</code> file in the sample
+application.</p>
 
 <pre>
 void startBuyPageActivity(PendingIntent pendingIntent, Intent intent) {
@@ -443,19 +638,37 @@
 }
 </pre>
 
-<p class="caution"><strong>Important:</strong> You must launch the pending intent from an activity context and not an application context. Also, you cannot use the <code>singleTop</code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">launch mode</a> to launch the pending intent. If you do either of these, the Android system will not attach the pending intent to your application process. Instead, it will bring Android Market to the foreground, disrupting your application.</p>
+<p class="caution"><strong>Important:</strong> You must launch the pending intent from an activity
+context and not an application context. Also, you cannot use the <code>singleTop</code> <a
+href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">launch mode</a> to launch the
+pending intent. If you do either of these, the Android system will not attach the pending intent to
+your application process. Instead, it will bring Android Market to the foreground, disrupting your
+application.</p>
 
 <h5>Handling broadcast intents</h5>
 
-<p>A <code>REQUEST_PURCHASE</code> request also triggers two asynchronous responses (broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides error information about the request. Next, if the request was successful, the Android Market application sends an <code>IN_APP_NOTIFY</code> broadcast intent. This message contains a notification ID, which you can use to retrieve the transaction details for the <code>REQUEST_PURCHASE</code> request.</p>
+<p>A <code>REQUEST_PURCHASE</code> request also triggers two asynchronous responses (broadcast
+intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent,
+which provides error information about the request. Next, if the request was successful, the Android
+Market application sends an <code>IN_APP_NOTIFY</code> broadcast intent. This message contains a
+notification ID, which you can use to retrieve the transaction details for the
+<code>REQUEST_PURCHASE</code> request.</p>
 
-<p>Keep in mind, the Android Market application also sends an <code>IN_APP_NOTIFY</code> for refunds. For more information, see <a href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling IN_APP_NOTIFY messages</a>.</p>
+<p>Keep in mind, the Android Market application also sends an <code>IN_APP_NOTIFY</code> for
+refunds. For more information, see <a
+href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling
+IN_APP_NOTIFY messages</a>.</p>
 
 <h4>Retrieving transaction information for a purchase or refund (GET_PURCHASE_INFORMATION)</h4>
 
-<p>You retrieve transaction information in response to an <code>IN_APP_NOTIFY</code> broadcast intent. The <code>IN_APP_NOTIFY</code> message contains a notification ID, which you can use to retrieve transaction information.</p>
+<p>You retrieve transaction information in response to an <code>IN_APP_NOTIFY</code> broadcast
+intent. The <code>IN_APP_NOTIFY</code> message contains a notification ID, which you can use to
+retrieve transaction information.</p>
 
-<p>To retrieve transaction information for a purchase or refund you must specify five keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>To retrieve transaction information for a purchase or refund you must specify five keys in the
+request {@link android.os.Bundle}. The following code sample shows how to set these keys and make
+the request. In the sample, <code>mService</code> is an instance of the
+<code>MarketBillingService</code> interface.</p>
 
 <pre>
 /**
@@ -468,15 +681,36 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional keys are then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The <code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you must generate. The Android Market application returns this nonce with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the integrity of the transaction information. The <code>NOTIFY_IDS</code> key contains an array of notification IDs, which you received in the <code>IN_APP_NOTIFY</code> broadcast intent.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional keys are then added to the
+bundle prior to invoking the <code>sendBillingRequest()</code> method. The
+<code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you
+must generate. The Android Market application returns this nonce with the
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the integrity of the
+transaction information. The <code>NOTIFY_IDS</code> key contains an array of notification IDs,
+which you received in the <code>IN_APP_NOTIFY</code> broadcast intent.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys: <code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys:
+<code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides
+you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique
+request identifier for the request.</p>
 
-<p>A <code>GET_PURCHASE_INFORMATION</code> request also triggers two asynchronous responses (broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status and error information about the request. Next, if the request was successful, the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code> broadcast intent. This message contains detailed transaction information. The transaction information is contained in a signed JSON string (unencrypted). The message includes the signature so you can verify the integrity of the signed string.</p>
+<p>A <code>GET_PURCHASE_INFORMATION</code> request also triggers two asynchronous responses
+(broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code>
+broadcast intent, which provides status and error information about the request. Next, if the
+request was successful, the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code>
+broadcast intent. This message contains detailed transaction information. The transaction
+information is contained in a signed JSON string (unencrypted). The message includes the signature
+so you can verify the integrity of the signed string.</p>
 
 <h4>Acknowledging transaction information (CONFIRM_NOTIFICATIONS)</h4>
 
-<p>To acknowledge that you received transaction information you send a <code>CONFIRM_NOTIFICATIONS</code> request. You must specify four keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>To acknowledge that you received transaction information you send a
+<code>CONFIRM_NOTIFICATIONS</code> request. You must specify four keys in the request {@link
+android.os.Bundle}. The following code sample shows how to set these keys and make the request. In
+the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code>
+interface.</p>
 
 <pre>
 /**
@@ -488,17 +722,35 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>NOTIFY_IDS</code> key is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The <code>NOTIFY_IDS</code> key contains an array of notification IDs, which you received in an <code>IN_APP_NOTIFY</code> broadcast intent and also used in a <code>GET_PURCHASE_INFORMATION</code> request.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>NOTIFY_IDS</code> key
+is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The
+<code>NOTIFY_IDS</code> key contains an array of notification IDs, which you received in an
+<code>IN_APP_NOTIFY</code> broadcast intent and also used in a <code>GET_PURCHASE_INFORMATION</code>
+request.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys: <code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys:
+<code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides
+you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique
+request identifier for the request.</p>
 
-<p>A <code>CONFIRM_NOTIFICATIONS</code> request triggers a single asynchronous response&mdash;a <code>RESPONSE_CODE</code> broadcast intent. This broadcast intent provides status and error information about the request.</p>
+<p>A <code>CONFIRM_NOTIFICATIONS</code> request triggers a single asynchronous response&mdash;a
+<code>RESPONSE_CODE</code> broadcast intent. This broadcast intent provides status and error
+information about the request.</p>
 
-<p class="note"><strong>Note:</strong> As a best practice, you should not send a <code>CONFIRM_NOTIFICATIONS</code> request for a purchased item until you have delivered the item to the user. This way, if your application crashes or something else prevents your application from delivering the product, your application will still receive an <code>IN_APP_NOTIFY</code> broadcast intent from Android Market indicating that you need to deliver the product.</p>
+<p class="note"><strong>Note:</strong> As a best practice, you should not send a
+<code>CONFIRM_NOTIFICATIONS</code> request for a purchased item until you have delivered the item to
+the user. This way, if your application crashes or something else prevents your application from
+delivering the product, your application will still receive an <code>IN_APP_NOTIFY</code> broadcast
+intent from Android Market indicating that you need to deliver the product.</p>
 
 <h4>Restoring transaction information (RESTORE_TRANSACTIONS)</h4>
 
-<p>To restore a user's transaction information, you send a <code>RESTORE_TRANSACTIONS</code> request. You must specify four keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>To restore a user's transaction information, you send a <code>RESTORE_TRANSACTIONS</code>
+request. You must specify four keys in the request {@link android.os.Bundle}. The following code
+sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an
+instance of the <code>MarketBillingService</code> interface.</p>
 
 <pre>
 /**
@@ -510,36 +762,73 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>REQUEST_NONCE</code> key is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The <code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you must generate. The Android Market application returns this nonce with the transactions information contained in the <code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the integrity of the transaction information.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>REQUEST_NONCE</code>
+key is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The
+<code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you
+must generate. The Android Market application returns this nonce with the transactions information
+contained in the <code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the
+integrity of the transaction information.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys: <code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys:
+<code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides
+you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique
+request identifier for the request.</p>
 
-<p>A <code>RESTORE_TRANSACTIONS</code> request also triggers two asynchronous responses (broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status and error information about the request. Next, if the request was successful, the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code> broadcast intent. This message contains the detailed transaction information. The transaction information is contained in a signed JSON string (unencrypted). The message includes the signature so you can verify the integrity of the signed string.</p>
-
+<p>A <code>RESTORE_TRANSACTIONS</code> request also triggers two asynchronous responses (broadcast
+intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent,
+which provides status and error information about the request. Next, if the request was successful,
+the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code> broadcast intent. This
+message contains the detailed transaction information. The transaction information is contained in a
+signed JSON string (unencrypted). The message includes the signature so you can verify the integrity
+of the signed string.</p>
 
 <h3>Other service tasks</h3>
 
-<p>You may also want your {@link android.app.Service} to receive intent messages from your {@link android.content.BroadcastReceiver}. You can use these intent messages to convey the information that was sent asynchronously from the Android Market application to your {@link android.content.BroadcastReceiver}. To see an example of how you can send and receive these intent messages, see the <code>BillingReceiver.java</code> and <code>BillingService.java</code> files in the sample application. You can use these samples as a basis for your own implementation. However, if you use any of the code from the sample application, be sure you follow the guidelines in <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p>You may also want your {@link android.app.Service} to receive intent messages from your {@link
+android.content.BroadcastReceiver}. You can use these intent messages to convey the information that
+was sent asynchronously from the Android Market application to your {@link
+android.content.BroadcastReceiver}. To see an example of how you can send and receive these intent
+messages, see the <code>BillingReceiver.java</code> and <code>BillingService.java</code> files in
+the sample application. You can use these samples as a basis for your own implementation. However,
+if you use any of the code from the sample application, be sure you follow the guidelines in <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
 
 <h2 id="billing-broadcast-receiver">Creating a BroadcastReceiver</h2>
 
-<p>The Android Market application uses broadcast intents to send asynchronous billing responses to your application. To receive these intent messages, you need to create a {@link android.content.BroadcastReceiver} that can handle the following intents:</p>
+<p>The Android Market application uses broadcast intents to send asynchronous billing responses to
+your application. To receive these intent messages, you need to create a {@link
+android.content.BroadcastReceiver} that can handle the following intents:</p>
 
 <ul>
   <li>com.android.vending.billing.RESPONSE_CODE
-  <p>This broadcast intent contains an Android Market response code, and is sent after you make an in-app billing request. For more information about the response codes that are sent with this response, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Android Market Response Codes for In-app Billing</a>.</p>
+  <p>This broadcast intent contains an Android Market response code, and is sent after you make an
+  in-app billing request. For more information about the response codes that are sent with this
+  response, see <a
+  href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Android Market Response
+  Codes for In-app Billing</a>.</p>
   </li>
   <li>com.android.vending.billing.IN_APP_NOTIFY
-  <p>This response indicates that a purchase has changed state, which means a purchase succeeded, was canceled, or was refunded. For more information about notification messages, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing Broadcast Intents</a></p>
+  <p>This response indicates that a purchase has changed state, which means a purchase succeeded,
+  was canceled, or was refunded. For more information about notification messages, see <a
+  href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing
+  Broadcast Intents</a></p>
   </li>
   <li>com.android.vending.billing.PURCHASE_STATE_CHANGED
-  <p>This broadcast intent contains detailed information about one or more transactions. For more information about purchase state messages, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing Broadcast Intents</a></p>
+  <p>This broadcast intent contains detailed information about one or more transactions. For more
+  information about purchase state messages, see <a
+  href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing
+  Broadcast Intents</a></p>
   </li>
 </ul>
 
-<p>Each of these broadcast intents provide intent extras, which your {@link android.content.BroadcastReceiver} must handle. The intent extras are listed in the following table (see table 1).</p>
+<p>Each of these broadcast intents provide intent extras, which your {@link
+android.content.BroadcastReceiver} must handle. The intent extras are listed in the following table
+(see table 1).</p>
 
-<p class="table-caption"><strong>Table 1.</strong> Description of broadcast intent extras that are sent in response to billing requests.</p>
+<p class="table-caption"><strong>Table 1.</strong> Description of broadcast intent extras that are
+sent in response to billing requests.</p>
 
 <table>
 
@@ -551,7 +840,8 @@
 <tr>
   <td><code>com.android.vending.billing.RESPONSE_CODE</code></td>
   <td><code>request_id</code></td>
-  <td>A <code>long</code> representing a request ID. A request ID identifies a specific billing request and is returned by Android Market at the time a request is made.</td>
+  <td>A <code>long</code> representing a request ID. A request ID identifies a specific billing
+  request and is returned by Android Market at the time a request is made.</td>
 </tr>
 <tr>
   <td><code>com.android.vending.billing.RESPONSE_CODE</code></td>
@@ -561,12 +851,17 @@
 <tr>
   <td><code>com.android.vending.billing.IN_APP_NOTIFY</code></td>
   <td><code>notification_id</code></td>
-  <td>A <code>String</code> representing the notification ID for a given purchase state change. Android Market notifies you when there is a purchase state change and the notification includes a unique notification ID. To get the details of the purchase state change, you send the notification ID with the <code>GET_PURCHASE_INFORMATION</code> request.</td>
+  <td>A <code>String</code> representing the notification ID for a given purchase state change.
+  Android Market notifies you when there is a purchase state change and the notification includes a
+  unique notification ID. To get the details of the purchase state change, you send the notification
+  ID with the <code>GET_PURCHASE_INFORMATION</code> request.</td>
 </tr>
 <tr>
   <td><code>com.android.vending.billing.PURCHASE_STATE_CHANGED</code></td>
   <td><code>inapp_signed_data</code></td>
-  <td>A <code>String</code> representing the signed JSON string. The JSON string contains information about the billing transaction, such as order number, amount, and the item that was purchased or refunded.</td>
+  <td>A <code>String</code> representing the signed JSON string. The JSON string contains
+  information about the billing transaction, such as order number, amount, and the item that was
+  purchased or refunded.</td>
 </tr>
 <tr>
   <td><code>com.android.vending.billing.PURCHASE_STATE_CHANGED</code></td>
@@ -575,7 +870,9 @@
 </tr>
 </table>
 
-<p>The following code sample shows how to handle these broadcast intents and intent extras within a {@link android.content.BroadcastReceiver}. The BroadcastReceiver in this case is named <code>BillingReceiver</code>, just as it is in the sample application.</p>
+<p>The following code sample shows how to handle these broadcast intents and intent extras within a
+{@link android.content.BroadcastReceiver}. The BroadcastReceiver in this case is named
+<code>BillingReceiver</code>, just as it is in the sample application.</p>
 
 <pre>
 public class BillingReceiver extends BroadcastReceiver {
@@ -623,13 +920,28 @@
 }
 </pre>
 
-<p>In addition to receiving broadcast intents from the Android Market application, your {@link android.content.BroadcastReceiver} must handle the information it received in the broadcast intents. Usually, your {@link android.content.BroadcastReceiver} does this by sending the information to a local service (discussed in the next section). The <code>BillingReceiver.java</code> file in the sample application shows you how to do this. You can use this sample as a basis for your own {@link android.content.BroadcastReceiver}. However, if you use any of the code from the sample application, be sure you follow the guidelines that are discussed in <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design </a>.</p>
+<p>In addition to receiving broadcast intents from the Android Market application, your {@link
+android.content.BroadcastReceiver} must handle the information it received in the broadcast intents.
+Usually, your {@link android.content.BroadcastReceiver} does this by sending the information to a
+local service (discussed in the next section). The <code>BillingReceiver.java</code> file in the
+sample application shows you how to do this. You can use this sample as a basis for your own {@link
+android.content.BroadcastReceiver}. However, if you use any of the code from the sample application,
+be sure you follow the guidelines that are discussed in <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design </a>.</p>
 
 <h2 id="billing-signatures">Verifying Signatures and Nonces</h2>
 
-<p>Android Market's in-app billing service uses two mechanisms to help verify the integrity of the transaction information you receive from Android Market: nonces and signatures. A nonce (number used once) is a cryptographically secure number that your application generates and sends with every <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, enabling you to verify that any given <code>PURCHASE_STATE_CHANGED</code> response corresponds to an actual request that you made. Every <code>PURCHASE_STATE_CHANGED</code> broadcast intent also includes a signed JSON string and a signature, which you can use to verify the integrity of the response.</p>
+<p>Android Market's in-app billing service uses two mechanisms to help verify the integrity of the
+transaction information you receive from Android Market: nonces and signatures. A nonce (number used
+once) is a cryptographically secure number that your application generates and sends with every
+<code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is
+returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, enabling you to verify that
+any given <code>PURCHASE_STATE_CHANGED</code> response corresponds to an actual request that you
+made. Every <code>PURCHASE_STATE_CHANGED</code> broadcast intent also includes a signed JSON string
+and a signature, which you can use to verify the integrity of the response.</p>
 
-<p>Your application must provide a way to generate, manage, and verify nonces. The following sample code shows some simple methods you can use to do this.</p>
+<p>Your application must provide a way to generate, manage, and verify nonces. The following sample
+code shows some simple methods you can use to do this.</p>
 
 <pre>
   private static final SecureRandom RANDOM = new SecureRandom();
@@ -650,27 +962,42 @@
   }
 </pre>
 
-<p>Your application must also provide a way to verify the signatures that accompany every <code>PURCHASE_STATE_CHANGED</code> broadcast intent. The <code>Security.java</code> file in the sample application shows you how to do this. If you use this file as a basis for your own security implementation, be sure to follow the guidelines in <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a> and obfuscate your code.</p>
+<p>Your application must also provide a way to verify the signatures that accompany every
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent. The <code>Security.java</code> file in the
+sample application shows you how to do this. If you use this file as a basis for your own security
+implementation, be sure to follow the guidelines in <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a> and
+obfuscate your code.</p>
 
-<p>You will need to use your Android Market public key to perform the signature verification. The following procedure shows you how to retrieve Base64-encoded public key from the Android Market publisher site.</p>
+<p>You will need to use your Android Market public key to perform the signature verification. The
+following procedure shows you how to retrieve Base64-encoded public key from the Android Market
+publisher site.</p>
 
 <ol>
   <li>Log in to your <a href="http://market.android.com/publish">publisher account</a>.</li>
   <li>On the upper left part of the page, under your name, click <strong>Edit profile</strong>.</li>
-  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure 2).</li>
+  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure
+  2).</li>
   <li>Copy your public key.</li>
 </ol>
 
-<p class="caution"><strong>Important</strong>: To keep your public key safe from malicious users and hackers, do not embed your public key as an entire literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the actual key. The key itself is not secret information, but you do not want to make it easy for a hacker or malicious user to replace the public key with another key.</p>
+<p class="caution"><strong>Important</strong>: To keep your public key safe from malicious users and
+hackers, do not embed your public key as an entire literal string. Instead, construct the string at
+runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the
+actual key. The key itself is not secret information, but you do not want to make it easy for a
+hacker or malicious user to replace the public key with another key.</p>
 
 <img src="{@docRoot}images/billing_public_key.png" height="510" id="figure2" />
 <p class="img-caption">
-  <strong>Figure 2.</strong> The Licensing and In-app Billing panel of your account's Edit Profile page lets you see your public key.
+  <strong>Figure 2.</strong> The Licensing and In-app Billing panel of your account's Edit Profile
+  page lets you see your public key.
 </p>
 
 <h2 id="billing-implement">Modifying Your Application Code</h2>
 
-<p>After you finish adding in-app billing components to your project, you are ready to modify your application's code. For a typical implementation, like the one that is demonstrated in the sample application, this means you need to write code to do the following: </p>
+<p>After you finish adding in-app billing components to your project, you are ready to modify your
+application's code. For a typical implementation, like the one that is demonstrated in the sample
+application, this means you need to write code to do the following: </p>
 
 <ul>
   <li>Create a storage mechanism for storing users' purchase information.</li>
@@ -681,13 +1008,26 @@
 
 <h3>Creating a storage mechanism for storing purchase information</h3>
 
-<p>You must set up a database or some other mechanism for storing users' purchase information. The sample application provides an example database (PurchaseDatabase.java); however, the example database has been simplified for clarity and does not exhibit the security best practices that we recommend. If you have a remote server, we recommend that you store purchase information on your server instead of in a local database on a device. For more information about security best practices, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p>You must set up a database or some other mechanism for storing users' purchase information. The
+sample application provides an example database (PurchaseDatabase.java); however, the example
+database has been simplified for clarity and does not exhibit the security best practices that we
+recommend. If you have a remote server, we recommend that you store purchase information on your
+server instead of in a local database on a device. For more information about security best
+practices, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+Design</a>.</p>
 
-<p class="note"><strong>Note</strong>: If you store any purchase information on a device, be sure to encrypt the data and use a device-specific encryption key.</p>
+<p class="note"><strong>Note</strong>: If you store any purchase information on a device, be sure to
+encrypt the data and use a device-specific encryption key.</p>
 
 <h3>Creating a user interface for selecting items</h3>
 
-<p>You must provide users with a means for selecting items that they want to purchase. Android Market provides the checkout user interface (which is where the user provides a form of payment and approves the purchase), but your application must provide a control (widget) that invokes the <code>sendBillingRequest()</code> method when a user selects an item for purchase.</p>
+<p>You must provide users with a means for selecting items that they want to purchase. Android
+Market provides the checkout user interface (which is where the user provides a form of payment and
+approves the purchase), but your application must provide a control (widget) that invokes the
+<code>sendBillingRequest()</code> method when a user selects an item for purchase.</p>
 
-<p>You can render the control and trigger the <code>sendBillingRequest()</code> method any way you want. The sample application uses a spinner widget and a button to present items to a user and trigger a billing request (see <code>Dungeons.java</code>). The user interface also shows a list of recently purchased items.</p>
+<p>You can render the control and trigger the <code>sendBillingRequest()</code> method any way you
+want. The sample application uses a spinner widget and a button to present items to a user and
+trigger a billing request (see <code>Dungeons.java</code>). The user interface also shows a list of
+recently purchased items.</p>
 
diff --git a/docs/html/guide/market/billing/billing_overview.jd b/docs/html/guide/market/billing/billing_overview.jd
index feac5b0..a42b772 100755
--- a/docs/html/guide/market/billing/billing_overview.jd
+++ b/docs/html/guide/market/billing/billing_overview.jd
@@ -20,110 +20,210 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
     <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>Android Market In-app Billing is an Android Market service that provides checkout processing for in-app purchases. To use the service, your application sends a billing request for a specific in-app product. The service then handles all of the checkout details for the transaction, including requesting and validating the form of payment and processing the financial transaction. When the checkout process is complete, the service sends your application the purchase details, such as the order number, the order date and time, and the price paid. At no point does your application have to handle any financial transactions; that role is provided by Android Market's in-app billing service.</p>
+<p>Android Market In-app Billing is an Android Market service that provides checkout processing for
+in-app purchases. To use the service, your application sends a billing request for a specific in-app
+product. The service then handles all of the checkout details for the transaction, including
+requesting and validating the form of payment and processing the financial transaction. When the
+checkout process is complete, the service sends your application the purchase details, such as the
+order number, the order date and time, and the price paid. At no point does your application have to
+handle any financial transactions; that role is provided by Android Market's in-app billing
+service.</p>
 
 <h2 id="billing-arch">In-app Billing Architecture</h2>
 
-<p>In-app billing uses an asynchronous message loop to convey billing requests and billing responses between your application and the Android Market server. In practice, your application never directly communicates with the Android Market server (see figure 1). Instead, your application sends billing requests to the Android Market application over interprocess communication (IPC) and receives purchase responses from the Android Market application in the form of asynchronous broadcast intents. Your application does not manage any network connections between itself and the Android Market server or use any special APIs from the Android platform.</p>
+<p>In-app billing uses an asynchronous message loop to convey billing requests and billing responses
+between your application and the Android Market server. In practice, your application never directly
+communicates with the Android Market server (see figure 1). Instead, your application sends billing
+requests to the Android Market application over interprocess communication (IPC) and receives
+purchase responses from the Android Market application in the form of asynchronous broadcast
+intents. Your application does not manage any network connections between itself and the Android
+Market server or use any special APIs from the Android platform.</p>
 
-<p>Some in-app billing implementations may also use a private remote server to deliver content or validate transactions, but a remote server is not required to implement in-app billing. A remote server can be useful if you are selling digital content that needs to be delivered to a user's device, such as media files or photos. You might also use a remote server to store users' transaction history or perform various in-app billing security tasks, such as signature verification. Although you can handle all security-related tasks in your application, performing those tasks on a remote server is recommended because it helps make your application less vulnerable to security attacks.</p>
+<p>Some in-app billing implementations may also use a private remote server to deliver content or
+validate transactions, but a remote server is not required to implement in-app billing. A remote
+server can be useful if you are selling digital content that needs to be delivered to a user's
+device, such as media files or photos. You might also use a remote server to store users'
+transaction history or perform various in-app billing security tasks, such as signature
+verification. Although you can handle all security-related tasks in your application, performing
+those tasks on a remote server is recommended because it helps make your application less vulnerable
+to security attacks.</p>
 
 <div class="figure" style="width:440px">
 <img src="{@docRoot}images/billing_arch.png" alt="" height="582" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> Your application sends and receives billing messages through the Android Market application, which handles all communication with the Android Market server.</p>
+  <strong>Figure 1.</strong> Your application sends and receives billing messages through the
+  Android Market application, which handles all communication with the Android Market server.</p>
 </div>
 
 <p>A typical in-app billing implementation relies on three components:</p>
 <ul>
-  <li>A {@link android.app.Service} (named <code>BillingService</code> in the sample application), which processes purchase messages from the application and sends billing requests to Android Market's in-app billing service.</li>
-  <li>A {@link android.content.BroadcastReceiver} (named <code>BillingReceiver</code> in the sample application), which receives all asynchronous billing responses from the Android Market application.</li>
-  <li>A security component (named <code>Security</code> in the sample application), which performs security-related tasks, such as signature verification and nonce generation. For more information about in-app billing security, see <a href="#billing-security">Security controls</a> later in this document.</li>
+  <li>A {@link android.app.Service} (named <code>BillingService</code> in the sample application),
+  which processes purchase messages from the application and sends billing requests to Android
+  Market's in-app billing service.</li>
+  <li>A {@link android.content.BroadcastReceiver} (named <code>BillingReceiver</code> in the sample
+  application), which receives all asynchronous billing responses from the Android Market
+  application.</li>
+  <li>A security component (named <code>Security</code> in the sample application), which performs
+  security-related tasks, such as signature verification and nonce generation. For more information
+  about in-app billing security, see <a href="#billing-security">Security controls</a> later in this
+  document.</li>
 </ul>
 
 <p>You may also want to incorporate two other components to support in-app billing:</p>
 <ul>
-  <li>A response {@link android.os.Handler} (named <code>ResponseHandler</code> in the sample application), which provides application-specific processing of purchase notifications, errors, and other status messages.</li>
-  <li>An observer (named <code>PurchaseObserver</code> in the sample application), which is responsible for sending callbacks to your application so you can update your user interface with purchase information and status.</li>
+  <li>A response {@link android.os.Handler} (named <code>ResponseHandler</code> in the sample
+  application), which provides application-specific processing of purchase notifications, errors,
+  and other status messages.</li>
+  <li>An observer (named <code>PurchaseObserver</code> in the sample application), which is
+  responsible for sending callbacks to your application so you can update your user interface with
+  purchase information and status.</li>
 </ul>
 
-<p>In addition to these components, your application must provide a way to store information about users' purchases and some sort of user interface that lets users select items to purchase. You do not need to provide a checkout user interface. When a user initiates an in-app purchase, the Android Market application presents the checkout user interface to your user. When the user completes the checkout process, your application resumes.</p>
+<p>In addition to these components, your application must provide a way to store information about
+users' purchases and some sort of user interface that lets users select items to purchase. You do
+not need to provide a checkout user interface. When a user initiates an in-app purchase, the Android
+Market application presents the checkout user interface to your user. When the user completes the
+checkout process, your application resumes.</p>
 
 <h2 id="billing-msgs">In-app Billing Messages</h2>
 
-<p>When the user initiates a purchase, your application sends billing messages to Android Market's in-app billing service (named <code>MarketBillingService</code>) using simple IPC method calls. The Android Market application responds to all billing requests synchronously, providing your application with status notifications and other information. The Android Market application also responds to some billing requests asynchronously, providing your application with error messages and detailed transaction information. The following section describes the basic request-response messaging that takes place between your application and the Android Market application.</p>
+<p>When the user initiates a purchase, your application sends billing messages to Android Market's
+in-app billing service (named <code>MarketBillingService</code>) using simple IPC method calls. The
+Android Market application responds to all billing requests synchronously, providing your
+application with status notifications and other information. The Android Market application also
+responds to some billing requests asynchronously, providing your application with error messages and
+detailed transaction information. The following section describes the basic request-response
+messaging that takes place between your application and the Android Market application.</p>
 
 <h3 id="billing-request">In-app billing requests</h3>
 
-<p>Your application sends in-app billing requests by invoking a single IPC method (<code>sendBillingRequest()</code>), which is exposed by the <code>MarketBillingService</code> interface. This interface is defined in an <a href="{@docRoot}guide/developing/tools/aidl.html">Android Interface Definition Language</a> file (<code>IMarketBillingService.aidl</code>). You can <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">download</a> this AIDL file with the in-app billing sample application.</p>
+<p>Your application sends in-app billing requests by invoking a single IPC method
+(<code>sendBillingRequest()</code>), which is exposed by the <code>MarketBillingService</code>
+interface. This interface is defined in an <a
+href="{@docRoot}guide/developing/tools/aidl.html">Android Interface Definition Language</a> file
+(<code>IMarketBillingService.aidl</code>). You can <a
+href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">download</a> this AIDL
+file with the in-app billing sample application.</p>
 
-<p>The <code>sendBillingRequest()</code> method has a single {@link android.os.Bundle} parameter. The Bundle that you deliver must include several key-value pairs that specify various parameters for the request, such as the type of billing request you are making, the item that is being purchased, and the application that is making the request. For more information about the Bundle keys that are sent with a request, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing Service Interface</a>.
+<p>The <code>sendBillingRequest()</code> method has a single {@link android.os.Bundle} parameter.
+The Bundle that you deliver must include several key-value pairs that specify various parameters for
+the request, such as the type of billing request you are making, the item that is being purchased,
+and the application that is making the request. For more information about the Bundle keys that are
+sent with a request, see <a
+href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing
+Service Interface</a>.
 
-<p>One of the most important keys that every request Bundle must have is the <code>BILLING_REQUEST</code> key. This key lets you specify the type of billing request you are making. Android Market's in-app billing service supports the following five types of billing requests:</p>
+<p>One of the most important keys that every request Bundle must have is the
+<code>BILLING_REQUEST</code> key. This key lets you specify the type of billing request you are
+making. Android Market's in-app billing service supports the following five types of billing
+requests:</p>
 
 <ul>
   <li><code>CHECK_BILLING_SUPPORTED</code>
-    <p>This request verifies that the Android Market application supports in-app billing. You usually send this request when your application first starts up. This request is useful if you want to enable or disable certain UI features that are relevant only to in-app billing.</p>
+    <p>This request verifies that the Android Market application supports in-app billing. You
+    usually send this request when your application first starts up. This request is useful if you
+    want to enable or disable certain UI features that are relevant only to in-app billing.</p>
   </li>
   <li><code>REQUEST_PURCHASE</code>
-    <p>This request sends a purchase message to the Android Market application and is the foundation of in-app billing. You send this request when a user indicates that he or she wants to purchase an item in your application. Android Market then handles the financial transaction by displaying the checkout user interface.</p>
+    <p>This request sends a purchase message to the Android Market application and is the foundation
+    of in-app billing. You send this request when a user indicates that he or she wants to purchase
+    an item in your application. Android Market then handles the financial transaction by displaying
+    the checkout user interface.</p>
   </li>
   <li><code>GET_PURCHASE_INFORMATION</code>
-    <p>This request retrieves the details of a purchase state change. A purchase changes state when a requested purchase is billed successfully or when a user cancels a transaction during checkout. It can also occur when a previous purchase is refunded. Android Market notifies your application when a purchase changes state, so you only need to send this request when there is transaction information to retrieve.</p>
+    <p>This request retrieves the details of a purchase state change. A purchase changes state when
+    a requested purchase is billed successfully or when a user cancels a transaction during
+    checkout. It can also occur when a previous purchase is refunded. Android Market notifies your
+    application when a purchase changes state, so you only need to send this request when there is
+    transaction information to retrieve.</p>
   </li>
   <li><code>CONFIRM_NOTIFICATIONS</code>
-    <p>This request acknowledges that your application received the details of a purchase state change. Android Market sends purchase state change notifications to your application until you confirm that you received them.</p>
+    <p>This request acknowledges that your application received the details of a purchase state
+    change. Android Market sends purchase state change notifications to your application until you
+    confirm that you received them.</p>
   </li>
   <li><code>RESTORE_TRANSACTIONS</code>
-    <p>This request retrieves a user's transaction status for <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed purchases</a>. You should send this request only when you need to retrieve a user's transaction status, which is usually only when your application is reinstalled or installed for the first time on a device.</p>
+    <p>This request retrieves a user's transaction status for <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed
+    purchases</a>. You should send this request only when you need to retrieve a user's transaction
+    status, which is usually only when your application is reinstalled or installed for the first
+    time on a device.</p>
   </li>
 </ul>
 
 <h3 id="billing-response">In-app Billing Responses</h3>
 
-<p>The Android Market application responds to in-app billing requests with both synchronous and asynchronous responses. The synchronous response is a {@link android.os.Bundle} with the following three keys:</p>
+<p>The Android Market application responds to in-app billing requests with both synchronous and
+asynchronous responses. The synchronous response is a {@link android.os.Bundle} with the following
+three keys:</p>
 
 <ul>
   <li><code>RESPONSE_CODE</code>
     <p>This key provides status information and error information about a request.</p>
   </li>
   <li><code>PURCHASE_INTENT</code>
-    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout activity.</p>
+    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout
+    activity.</p>
   </li>
   <li><code>REQUEST_ID</code>
-    <p>This key provides you with a request identifier, which you can use to match asynchronous responses with requests.</p>
+    <p>This key provides you with a request identifier, which you can use to match asynchronous
+    responses with requests.</p>
   </li>
 </ul>
-<p>Some of these keys are not relevant to every request. For more information, see <a href="#billing-message-sequence">Messaging sequence</a> later in this document.</p>
+<p>Some of these keys are not relevant to every request. For more information, see <a
+href="#billing-message-sequence">Messaging sequence</a> later in this document.</p>
 
-<p>The asynchronous response messages are sent in the form of individual broadcast intents and include the following:</p>
+<p>The asynchronous response messages are sent in the form of individual broadcast intents and
+include the following:</p>
 
 <ul>
     <li><code>com.android.vending.billing.RESPONSE_CODE</code>
-    <p>This response contains an Android Market server response code, and is sent after you make an in-app billing request. A server response code can indicate that a billing request was successfully sent to Android Market or it can indicate that some error occurred during a billing request. This response is <em>not</em> used to report any purchase state changes (such as refund or purchase information). For more information about the response codes that are sent with this response, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Server Response Codes for In-app Billing</a>.</p>
+    <p>This response contains an Android Market server response code, and is sent after you make an
+    in-app billing request. A server response code can indicate that a billing request was
+    successfully sent to Android Market or it can indicate that some error occurred during a billing
+    request. This response is <em>not</em> used to report any purchase state changes (such as refund
+    or purchase information). For more information about the response codes that are sent with this
+    response, see <a
+    href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Server Response Codes
+    for In-app Billing</a>.</p>
   </li>
   <li><code>com.android.vending.billing.IN_APP_NOTIFY</code>
-    <p>This response indicates that a purchase has changed state, which means a purchase succeeded, was canceled, or was refunded. This response contains one or more notification IDs. Each notification ID corresponds to a specific server-side message, and each messages contains information about one or more transactions. After your application receives an <code>IN_APP_NOTIFY</code> broadcast intent, you send a <code>GET_PURCHASE_INFORMATION</code> request with the notification IDs to retrieve message details.</p>
+    <p>This response indicates that a purchase has changed state, which means a purchase succeeded,
+    was canceled, or was refunded. This response contains one or more notification IDs. Each
+    notification ID corresponds to a specific server-side message, and each messages contains
+    information about one or more transactions. After your application receives an
+    <code>IN_APP_NOTIFY</code> broadcast intent, you send a <code>GET_PURCHASE_INFORMATION</code>
+    request with the notification IDs to retrieve message details.</p>
   </li>
   <li><code>com.android.vending.billing.PURCHASE_STATE_CHANGED</code>
-    <p>This response contains detailed information about one or more transactions. The transaction information is contained in a JSON string. The JSON string is signed and the signature is sent to your application along with the JSON string (unencrypted). To help ensure the security of your in-app billing messages, your application can verify the signature of this JSON string.</p>
+    <p>This response contains detailed information about one or more transactions. The transaction
+    information is contained in a JSON string. The JSON string is signed and the signature is sent
+    to your application along with the JSON string (unencrypted). To help ensure the security of
+    your in-app billing messages, your application can verify the signature of this JSON string.</p>
   </li>
 </ul>
 
-<p>The JSON string that is returned with the <code>PURCHASE_STATE_CHANGED</code> intent provides your application with the details of one or more billing transactions. An example of this JSON string is shown below:</p>
+<p>The JSON string that is returned with the <code>PURCHASE_STATE_CHANGED</code> intent provides
+your application with the details of one or more billing transactions. An example of this JSON
+string is shown below:</p>
 <pre class="no-pretty-print" style="color:black">
 { "nonce" : 1836535032137741465,
   "orders" :
@@ -137,34 +237,57 @@
 }
 </pre>
 
-<p>For more information about the fields in this JSON string, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing Broadcast Intents</a>.</p>
+<p>For more information about the fields in this JSON string, see <a
+href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing
+Broadcast Intents</a>.</p>
 
 <h3 id="billing-message-sequence">Messaging sequence</h3>
 
-<p>The messaging sequence for a typical purchase request is shown in figure 2. Request types for each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are shown in <em>italic</em>. For clarity, figure 2 does not show the <code>RESPONSE_CODE</code> broadcast intents that are sent for every request.</p>
+<p>The messaging sequence for a typical purchase request is shown in figure 2. Request types for
+each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents
+are shown in <em>italic</em>. For clarity, figure 2 does not show the <code>RESPONSE_CODE</code>
+broadcast intents that are sent for every request.</p>
 
 <p>The basic message sequence for an in-app purchase request is as follows:</p>
 
 <ol>
-  <li>Your application sends a purchase request (<code>REQUEST_PURCHASE</code> type), specifying a product ID and other parameters.</li>
-  <li>The Android Market application sends your application a Bundle with the following keys: <code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The <code>PURCHASE_INTENT</code> key provides a {@link android.app.PendingIntent}, which your application uses to start the checkout UI for the given product ID.</li>
+  <li>Your application sends a purchase request (<code>REQUEST_PURCHASE</code> type), specifying a
+  product ID and other parameters.</li>
+  <li>The Android Market application sends your application a Bundle with the following keys:
+  <code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The
+  <code>PURCHASE_INTENT</code> key provides a {@link android.app.PendingIntent}, which your
+  application uses to start the checkout UI for the given product ID.</li>
   <li>Your application launches the pending intent, which launches the checkout UI.</li>
-  <li>When the checkout flow finishes (that is, the user successfully purchases the item or cancels the purchase), Android Market sends your application a notification message (an <code>IN_APP_NOTIFY</code> broadcast intent). The notification message includes a notification ID, which references the transaction.</li>
-  <li>Your application requests the transaction information by sending a <code>GET_PURCHASE_STATE_CHANGED</code> request, specifying the notification ID for the transaction.</li>
-  <li>The Android Market application sends a Bundle with a <code>RESPONSE_CODE</code> key and a  <code>REQUEST_ID</code> key.
-  <li>Android Market sends the transaction information to your application in a <code>PURCHASE_STATE_CHANGED</code> broadcast intent.</li>
-  <li>Your application confirms that you received the transaction information for the given notification ID by sending a confirmation message (<code>CONFIRM_NOTIFICATIONS</code> type), specifying the notification ID for which you received transaction information.</li>
-  <li>The Android Market application sends your application a Bundle with a <code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key.</li>
+  <li>When the checkout flow finishes (that is, the user successfully purchases the item or cancels
+  the purchase), Android Market sends your application a notification message (an
+  <code>IN_APP_NOTIFY</code> broadcast intent). The notification message includes a notification ID,
+  which references the transaction.</li>
+  <li>Your application requests the transaction information by sending a
+  <code>GET_PURCHASE_STATE_CHANGED</code> request, specifying the notification ID for the
+  transaction.</li>
+  <li>The Android Market application sends a Bundle with a <code>RESPONSE_CODE</code> key and a 
+  <code>REQUEST_ID</code> key.
+  <li>Android Market sends the transaction information to your application in a
+  <code>PURCHASE_STATE_CHANGED</code> broadcast intent.</li>
+  <li>Your application confirms that you received the transaction information for the given
+  notification ID by sending a confirmation message (<code>CONFIRM_NOTIFICATIONS</code> type),
+  specifying the notification ID for which you received transaction information.</li>
+  <li>The Android Market application sends your application a Bundle with a
+  <code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key.</li>
 </ol>
 
-<p class="note"><strong>Note:</strong> You must launch the pending intent from an activity context and not an application context.</p>
+<p class="note"><strong>Note:</strong> You must launch the pending intent from an activity context
+and not an application context.</p>
 
 <img src="{@docRoot}images/billing_request_purchase.png" height="231" id="figure2" />
 <p class="img-caption">
   <strong>Figure 2.</strong> Message sequence for a purchase request.
 </p>
 
-<p>The messaging sequence for a restore transaction request is shown in figure 3. Request types for each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are shown in <em>italic</em>. For clarity, figure 3 does not show the <code>RESPONSE_CODE</code> broadcast intents that are sent for every request.</p>
+<p>The messaging sequence for a restore transaction request is shown in figure 3. Request types for
+each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents
+are shown in <em>italic</em>. For clarity, figure 3 does not show the <code>RESPONSE_CODE</code>
+broadcast intents that are sent for every request.</p>
 
 <div class="figure" style="width:490px">
 <img src="{@docRoot}images/billing_restore_transactions.png" alt="" height="168" />
@@ -173,11 +296,20 @@
 </p>
 </div>
 
-<p>The request triggers three responses. The first is a {@link android.os.Bundle} with a <code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key. Next, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status information or error information about the request. As always, the <code>RESPONSE_CODE</code> message references a specific request ID, so you can determine which request a <code>RESPONSE_CODE</code> message pertains to.</p>
+<p>The request triggers three responses. The first is a {@link android.os.Bundle} with a
+<code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key. Next, the Android Market
+application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status information
+or error information about the request. As always, the <code>RESPONSE_CODE</code> message references
+a specific request ID, so you can determine which request a <code>RESPONSE_CODE</code> message
+pertains to.</p>
 
-<p>The <code>RESTORE_TRANSACTIONS</code> request type also triggers a <code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the same type of transaction information that is sent during a purchase request, although you do not need to respond to this intent with a <code>CONFIRM_NOTIFICATIONS</code> message.</p>
+<p>The <code>RESTORE_TRANSACTIONS</code> request type also triggers a
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the same type of transaction
+information that is sent during a purchase request, although you do not need to respond to this
+intent with a <code>CONFIRM_NOTIFICATIONS</code> message.</p>
 
-<p>The messaging sequence for checking whether in-app billing is supported is shown in figure 4. The request type for the <code>sendBillingRequest()</code> method is shown in <strong>bold</strong>.</p>
+<p>The messaging sequence for checking whether in-app billing is supported is shown in figure 4. The
+request type for the <code>sendBillingRequest()</code> method is shown in <strong>bold</strong>.</p>
 
 <div class="figure" style="width:454px">
 <img src="{@docRoot}images/billing_check_supported.png" alt="" height="168" />
@@ -186,15 +318,43 @@
 </p>
 </div>
 
-<p>The synchronous response for a <code>CHECK_BILLING_SUPPORTED</code> request provides a Bundle with a server response code.  A <code>RESULT_OK</code> response code indicates that in-app billing is supported; a <code>RESULT_BILLING_UNAVAILABLE</code> response code indicates that in-app billing is unavailable because the API version you specified is unrecognized or the user is not eligible to make in-app purchases (for example, the user resides in a country that does not allow in-app billing). A <code>SERVER_ERROR</code> can also be returned, indicating that there was a problem with the Android Market server.</p>
+<p>The synchronous response for a <code>CHECK_BILLING_SUPPORTED</code> request provides a Bundle
+with a server response code.  A <code>RESULT_OK</code> response code indicates that in-app billing
+is supported; a <code>RESULT_BILLING_UNAVAILABLE</code> response code indicates that in-app billing
+is unavailable because the API version you specified is unrecognized or the user is not eligible to
+make in-app purchases (for example, the user resides in a country that does not allow in-app
+billing). A <code>SERVER_ERROR</code> can also be returned, indicating that there was a problem with
+the Android Market server.</p>
 
 <h3 id="billing-action-notify">Handling IN_APP_NOTIFY messages</h3>
 
-<p>Usually, your application receives an <code>IN_APP_NOTIFY</code> broadcast intent from Android Market in response to a <code>REQUEST_PURCHASE</code> message (see figure 2). The <code>IN_APP_NOTIFY</code> broadcast intent informs your application that the state of a requested purchase has changed. To retrieve the details of that purchase, your application sends a <code>GET_PURCHASE_INFORMATION</code> request. Android Market responds with a <code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the details of the purchase state change. Your application then sends a <code>CONFIRM_NOTIFICATIONS</code> message, informing Android Market that you've received the purchase state change information.</p>
+<p>Usually, your application receives an <code>IN_APP_NOTIFY</code> broadcast intent from Android
+Market in response to a <code>REQUEST_PURCHASE</code> message (see figure 2). The
+<code>IN_APP_NOTIFY</code> broadcast intent informs your application that the state of a requested
+purchase has changed. To retrieve the details of that purchase, your application sends a
+<code>GET_PURCHASE_INFORMATION</code> request. Android Market responds with a
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the details of the purchase
+state change. Your application then sends a <code>CONFIRM_NOTIFICATIONS</code> message, informing
+Android Market that you've received the purchase state change information.</p>
 
-<p>When Android Market receives a <code>CONFIRM_NOTIFICATIONS</code> message for a given message, it usually stops sending <code>IN_APP_NOTIFY</code> intents for that message. However, there are some cases where Android Market may send repeated <code>IN_APP_NOTIFY</code> intents for a message even though your application has sent a <code>CONFIRM_NOTIFICATIONS</code> message. This can occur if a device loses network connectivity while you are sending the <code>CONFIRM_NOTIFICATIONS</code> message. In this case, Android Market might not receive your <code>CONFIRM_NOTIFICATIONS</code> message and it could send multiple <code>IN_APP_NOTIFY</code> messages until it receives acknowledgement that you received the message. Therefore, your application must be able to recognize that the subsequent <code>IN_APP_NOTIFY</code> messages are for a previously processed transaction. You can do this by checking the <code>orderID</code> that's contained in the JSON string because every transaction has a unique <code>orderId</code>.</p>
+<p>When Android Market receives a <code>CONFIRM_NOTIFICATIONS</code> message for a given message, it
+usually stops sending <code>IN_APP_NOTIFY</code> intents for that message. However, there are some
+cases where Android Market may send repeated <code>IN_APP_NOTIFY</code> intents for a message even
+though your application has sent a <code>CONFIRM_NOTIFICATIONS</code> message. This can occur if a
+device loses network connectivity while you are sending the <code>CONFIRM_NOTIFICATIONS</code>
+message. In this case, Android Market might not receive your <code>CONFIRM_NOTIFICATIONS</code>
+message and it could send multiple <code>IN_APP_NOTIFY</code> messages until it receives
+acknowledgement that you received the message. Therefore, your application must be able to recognize
+that the subsequent <code>IN_APP_NOTIFY</code> messages are for a previously processed transaction.
+You can do this by checking the <code>orderID</code> that's contained in the JSON string because
+every transaction has a unique <code>orderId</code>.</p>
 
-<p>There are two cases where your application may also receive <code>IN_APP_NOTIFY</code> broadcast intents even though your application has not sent a <code>REQUEST_PURCHASE</code> message. Figure 5 shows the messaging sequence for both of these cases. Request types for each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are shown in <em>italic</em>. For clarity, figure 5 does not show the <code>RESPONSE_CODE</code> broadcast intents that are sent for every request.</p>
+<p>There are two cases where your application may also receive <code>IN_APP_NOTIFY</code> broadcast
+intents even though your application has not sent a <code>REQUEST_PURCHASE</code> message. Figure 5
+shows the messaging sequence for both of these cases. Request types for each
+<code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are
+shown in <em>italic</em>. For clarity, figure 5 does not show the <code>RESPONSE_CODE</code>
+broadcast intents that are sent for every request.</p>
 
 <div class="figure" style="width:481px">
 <img src="{@docRoot}images/billing_refund.png" alt="" height="189" />
@@ -203,32 +363,77 @@
 </p>
 </div>
 
-<p>In the first case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent when a user has your application installed on two (or more) devices and the user makes an in-app purchase from one of the devices. In this case, Android Market sends an <code>IN_APP_NOTIFY</code> message to the second device, informing the application that there is a purchase state change. Your application can handle this message the same way it handles the response from an application-initiated <code>REQUEST_PURCHASE</code> message, so that ultimately your application receives a <code>PURCHASE_STATE_CHANGED</code> broadcast intent message that includes information about the item that has been purchased. This applies only to items that have their <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">purchase type</a> set to "managed per user account."</p>
+<p>In the first case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent
+when a user has your application installed on two (or more) devices and the user makes an in-app
+purchase from one of the devices. In this case, Android Market sends an <code>IN_APP_NOTIFY</code>
+message to the second device, informing the application that there is a purchase state change. Your
+application can handle this message the same way it handles the response from an
+application-initiated <code>REQUEST_PURCHASE</code> message, so that ultimately your application
+receives a <code>PURCHASE_STATE_CHANGED</code> broadcast intent message that includes information
+about the item that has been purchased. This applies only to items that have their <a
+href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">purchase type</a> set
+to "managed per user account."</p>
 
-<p>In the second case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent when Android Market receives a refund notification from Google Checkout. In this case, Android Market sends an <code>IN_APP_NOTIFY</code> message to your application. Your application can handle this message the same way it handles responses from an application-initiated <code>REQUEST_PURCHASE</code> message so that ultimately your application receives a <code>PURCHASE_STATE_CHANGED</code> message that includes information about the item that has been refunded. The refund information is included in the JSON string that accompanies the <code>PURCHASE_STATE_CHANGED</code> broadcast intent. Also, the <code>purchaseState</code> field in the JSON string is set to 2.</p>
+<p>In the second case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent
+when Android Market receives a refund notification from Google Checkout. In this case, Android
+Market sends an <code>IN_APP_NOTIFY</code> message to your application. Your application can handle
+this message the same way it handles responses from an application-initiated
+<code>REQUEST_PURCHASE</code> message so that ultimately your application receives a
+<code>PURCHASE_STATE_CHANGED</code> message that includes information about the item that has been
+refunded. The refund information is included in the JSON string that accompanies the
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent. Also, the <code>purchaseState</code> field in
+the JSON string is set to 2.</p>
 
 <h2 id="billing-security">Security Controls</h2>
 
-<p>To help ensure the integrity of the transaction information that is sent to your application, Android Market signs the JSON string that is contained in the <code>PURCHASE_STATE_CHANGED</code> broadcast intent. Android Market uses the private key that is associated with your publisher account to create this signature. The publisher site generates an RSA key pair for each publisher account. You can find the public key portion of this key pair on your account's profile page. It is the same public key that is used with Android Market licensing.</p>
+<p>To help ensure the integrity of the transaction information that is sent to your application,
+Android Market signs the JSON string that is contained in the <code>PURCHASE_STATE_CHANGED</code>
+broadcast intent. Android Market uses the private key that is associated with your publisher account
+to create this signature. The publisher site generates an RSA key pair for each publisher account.
+You can find the public key portion of this key pair on your account's profile page. It is the same
+public key that is used with Android Market licensing.</p>
 
-<p>When Android Market signs a billing response, it includes the signed JSON string (unencrypted) and the signature. When your application receives this signed response you can use the public key portion of your RSA key pair to verify the signature. By performing signature verification you can help detect responses that have been tampered with or that have been spoofed. You can perform this signature verification step in your application; however, if your application connects to a secure remote server then we recommend that you perform the signature verification on that server.</p>
+<p>When Android Market signs a billing response, it includes the signed JSON string (unencrypted)
+and the signature. When your application receives this signed response you can use the public key
+portion of your RSA key pair to verify the signature. By performing signature verification you can
+help detect responses that have been tampered with or that have been spoofed. You can perform this
+signature verification step in your application; however, if your application connects to a secure
+remote server then we recommend that you perform the signature verification on that server.</p>
 
-<p>In-app billing also uses nonces (a random number used once) to help verify the integrity of the purchase information that's returned from Android Market. Your application must generate a nonce and send it with a <code>GET_PURCHASE_INFORMATION</code> request and a <code>RESTORE_TRANSACTIONS</code> request. When Android Market receives the request, it adds the nonce to the JSON string that contains the transaction information. The JSON string is then signed and returned to your application. When your application receives the JSON string, you need to verify the nonce as well as the signature of the JSON string.</p>
+<p>In-app billing also uses nonces (a random number used once) to help verify the integrity of the
+purchase information that's returned from Android Market. Your application must generate a nonce and
+send it with a <code>GET_PURCHASE_INFORMATION</code> request and a <code>RESTORE_TRANSACTIONS</code>
+request. When Android Market receives the request, it adds the nonce to the JSON string that
+contains the transaction information. The JSON string is then signed and returned to your
+application. When your application receives the JSON string, you need to verify the nonce as well as
+the signature of the JSON string.</p>
 
-<p>For more information about best practices for security and design, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p>For more information about best practices for security and design, see <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
 
 <h2 id="billing-limitations">In-app Billing Requirements and Limitations</h2>
 
-<p>Before you get started with in-app billing, be sure to review the following requirements and limitations.</p>
+<p>Before you get started with in-app billing, be sure to review the following requirements and
+limitations.</p>
 
 <ul>
-  <li>In-app billing can be implemented only in applications that you publish through Android Market.</li>
+  <li>In-app billing can be implemented only in applications that you publish through Android
+  Market.</li>
   <li>You must have a Google Checkout Merchant account to use Android Market In-app Billing.</li>
-  <li>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application.</li>
-  <li>An application can use in-app billing only if the device is running Android 1.6 (API level 4) or higher.</li>
-  <li>You can use in-app billing to sell only digital content. You cannot use in-app billing to sell physical goods, personal services, or anything that requires physical delivery.</li>
-  <li>Android Market does not provide any form of content delivery. You are responsible for delivering the digital content that you sell in your applications.</li>
-  <li>You cannot implement in-app billing on a device that never connects to the network. To complete in-app purchase requests, a device must be able to access the Android Market server over the network. </li>
+  <li>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+  the MyApps application. If your device is running any other version of Android, in-app billing
+  requires version 2.3.4 (or higher) of the Android Market application.</li>
+  <li>An application can use in-app billing only if the device is running Android 1.6 (API level 4)
+  or higher.</li>
+  <li>You can use in-app billing to sell only digital content. You cannot use in-app billing to sell
+  physical goods, personal services, or anything that requires physical delivery.</li>
+  <li>Android Market does not provide any form of content delivery. You are responsible for
+  delivering the digital content that you sell in your applications.</li>
+  <li>You cannot implement in-app billing on a device that never connects to the network. To
+  complete in-app purchase requests, a device must be able to access the Android Market server over
+  the network. </li>
 </ul>
 
-<p>For more information about in-app billing requirements, see <a href="http://market.android.com/support/bin/answer.py?answer=1153481">In-App Billing Availability and Policies</a>.</p>
+<p>For more information about in-app billing requirements, see <a
+href="http://market.android.com/support/bin/answer.py?answer=1153481">In-App Billing Availability
+and Policies</a>.</p>
diff --git a/docs/html/guide/market/billing/billing_reference.jd b/docs/html/guide/market/billing/billing_reference.jd
index 292823d..a95f389 100755
--- a/docs/html/guide/market/billing/billing_reference.jd
+++ b/docs/html/guide/market/billing/billing_reference.jd
@@ -14,15 +14,21 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
   </ol>
 </div>
 </div>
@@ -37,9 +43,13 @@
 
 <h2 id="billing-codes">Android Market Server Response Codes for In-app Billing</h2>
 
-<p>The following table lists all of the server response codes that are sent from Android Market to your application. Android Market sends these response codes asynchronously as <code>response_code</code> extras in the <code>com.android.vending.billing.RESPONSE_CODE</code> broadcast intent. Your application must handle all of these response codes.</p>
+<p>The following table lists all of the server response codes that are sent from Android Market to
+your application. Android Market sends these response codes asynchronously as
+<code>response_code</code> extras in the <code>com.android.vending.billing.RESPONSE_CODE</code>
+broadcast intent. Your application must handle all of these response codes.</p>
 
-<p class="table-caption" id="response-codes-table"><strong>Table 1.</strong> Summary of response codes returned by Android Market.</p>
+<p class="table-caption" id="response-codes-table"><strong>Table 1.</strong> Summary of response
+codes returned by Android Market.</p>
 
 <table>
 
@@ -49,11 +59,14 @@
 </tr>
 <tr>
   <td><code>RESULT_OK</code></td>
-  <td>Indicates that the request was sent to the server successfully. When this code is returned in response to a <code>CHECK_BILLING_SUPPORTED</code> request, indicates that billing is supported.</td>
+  <td>Indicates that the request was sent to the server successfully. When this code is returned in
+  response to a <code>CHECK_BILLING_SUPPORTED</code> request, indicates that billing is
+  supported.</td>
 </tr>
 <tr>
   <td><code>RESULT_USER_CANCELED</code></td>
-  <td>Indicates that the user pressed the back button on the checkout page instead of buying the item.</td>
+  <td>Indicates that the user pressed the back button on the checkout page instead of buying the
+  item.</td>
 </tr>
 <tr>
   <td><code>RESULT_SERVICE_UNAVAILABLE</code></td>
@@ -61,11 +74,15 @@
 </tr>
 <tr>
   <td><code>RESULT_BILLING_UNAVAILABLE</code></td>
-  <td>Indicates that in-app billing is not available because the <code>API_VERSION</code> that you specified is not recognized by the Android Market application or the user is ineligible for in-app billing (for example, the user resides in a country that prohibits in-app purchases).</td>
+  <td>Indicates that in-app billing is not available because the <code>API_VERSION</code> that you
+  specified is not recognized by the Android Market application or the user is ineligible for in-app
+  billing (for example, the user resides in a country that prohibits in-app purchases).</td>
 </tr>
 <tr>
   <td><code>RESULT_ITEM_UNAVAILABLE</code></td>
-  <td>Indicates that Android Market cannot find the requested item in the application's product list. This can happen if the product ID is misspelled in your <code>REQUEST_PURCHASE</code> request or if an item is unpublished in the application's product list.</td>
+  <td>Indicates that Android Market cannot find the requested item in the application's product
+  list. This can happen if the product ID is misspelled in your <code>REQUEST_PURCHASE</code>
+  request or if an item is unpublished in the application's product list.</td>
 </tr>
 <tr>
   <td><code>RESULT_ERROR</code></td>
@@ -74,16 +91,26 @@
 
 <tr>
   <td><code>RESULT_DEVELOPER_ERROR</code></td>
-  <td>Indicates that an application is trying to make an in-app billing request but the application has not declared the com.android.vending.BILLING permission in its manifest. Can also indicate that an application is not properly signed, or that you sent a malformed request, such as a request with missing Bundle keys or a request that uses an unrecognized request type.</td>
+  <td>Indicates that an application is trying to make an in-app billing request but the application
+  has not declared the com.android.vending.BILLING permission in its manifest. Can also indicate
+  that an application is not properly signed, or that you sent a malformed request, such as a
+  request with missing Bundle keys or a request that uses an unrecognized request type.</td>
 </tr>
 </table>
 
 <h2 id="billing-interface">In-app Billing Service Interface</h2>
 
-<p>The following section describes the interface for Android Market's in-app billing service. The interface is defined in the <code>IMarketBillingService.aidl</code> file, which is included with the in-app billing <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample application</a>.</p>
-<p>The interface consists of a single request method <code>sendBillingRequest()</code>. This method takes a single {@link android.os.Bundle} parameter. The Bundle parameter includes several key-value pairs, which are summarized in table 2.</p>
+<p>The following section describes the interface for Android Market's in-app billing service. The
+interface is defined in the <code>IMarketBillingService.aidl</code> file, which is included with the
+in-app billing <a
+href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample
+application</a>.</p>
+<p>The interface consists of a single request method <code>sendBillingRequest()</code>. This method
+takes a single {@link android.os.Bundle} parameter. The Bundle parameter includes several key-value
+pairs, which are summarized in table 2.</p>
 
-<p class="table-caption"><strong>Table 2.</strong> Description of Bundle keys passed in a <code>sendBillingRequest()</code> request.</p>
+<p class="table-caption"><strong>Table 2.</strong> Description of Bundle keys passed in a
+<code>sendBillingRequest()</code> request.</p>
 
 <table>
 
@@ -97,16 +124,20 @@
 <tr>
   <td><code>BILLING_REQUEST</code></td>
   <td><code>String</code></td>
-  <td><code>CHECK_BILLING_SUPPORTED</code>, <code>REQUEST_PURCHASE</code>, <code>GET_PURCHASE_INFORMATION</code>, <code>CONFIRM_NOTIFICATIONS</code>, or <code>RESTORE_TRANSACTIONS</code></td>
+  <td><code>CHECK_BILLING_SUPPORTED</code>, <code>REQUEST_PURCHASE</code>,
+  <code>GET_PURCHASE_INFORMATION</code>, <code>CONFIRM_NOTIFICATIONS</code>, or
+  <code>RESTORE_TRANSACTIONS</code></td>
   <td>Yes</td>
-  <td>The type of billing request you are making with the <code>sendBillingRequest()</code> request. The possible values are discussed more below this table.</td>
+  <td>The type of billing request you are making with the <code>sendBillingRequest()</code> request.
+  The possible values are discussed more below this table.</td>
 </tr>
 <tr>
   <td><code>API_VERSION</code></td>
   <td><code>int</code></td>
   <td>1</td>
   <td>Yes</td>
-  <td>The version of Android Market's in-app billing service you are using. The current version is 1.</td>
+  <td>The version of Android Market's in-app billing service you are using. The current version is
+  1.</td>
 </tr>
 <tr>
   <td><code>PACKAGE_NAME</code></td>
@@ -120,28 +151,42 @@
   <td><code>String</code></td>
   <td>Any valid product identifier.</td>
   <td>Required for <code>REQUEST_PURCHASE</code> requests.</td>
-  <td>The product ID of the item you are making a billing request for. Every in-app item that you sell using Android Market's in-app billing service must have a unique product ID, which you specify on the Android Market publisher site.</td>
+  <td>The product ID of the item you are making a billing request for. Every in-app item that you
+  sell using Android Market's in-app billing service must have a unique product ID, which you
+  specify on the Android Market publisher site.</td>
 </tr>
 <tr>
   <td><code>NONCE</code></td>
   <td><code>long</code></td>
   <td>Any valid <code>long</code> value.</td>
-  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> requests.</td>
-  <td>A number used once. Your application must generate and send a nonce with each <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, so you can use this value to verify the integrity of transaction responses form Android Market.</td>
+  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code>
+  requests.</td>
+  <td>A number used once. Your application must generate and send a nonce with each
+  <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is
+  returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, so you can use this value
+  to verify the integrity of transaction responses form Android Market.</td>
 </tr>
 <tr>
   <td><code>NOTIFY_IDS</code></td>
   <td>Array of <code>long</code> values</td>
   <td>Any valid array of <code>long</code> values</td>
-  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>CONFIRM_NOTIFICATIONS</code> requests.</td>
-  <td>An array of notification identifiers. A notification ID is sent to your application in an <code>IN_APP_NOTIFY</code> broadcast intent every time a purchase changes state. You use the notification to retrieve the details of the purchase state change.</td>
+  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>CONFIRM_NOTIFICATIONS</code>
+  requests.</td>
+  <td>An array of notification identifiers. A notification ID is sent to your application in an
+  <code>IN_APP_NOTIFY</code> broadcast intent every time a purchase changes state. You use the
+  notification to retrieve the details of the purchase state change.</td>
 </tr>
 <tr>
   <td><code>DEVELOPER_PAYLOAD</code></td>
   <td><code>String</code></td>
   <td>Any valid <code>String</code> less than 256 characters long.</td>
   <td>No</td>
-  <td>A developer-specified string that can be specified when you make a <code>REQUEST_PURCHASE</code> request. This field is returned in the JSON string that contains transaction information for an order. You can use this key to send supplemental information with an order. For example, you can use this key to send index keys with an order, which is useful if you are using a database to store purchase information. We recommend that you do not use this key to send data or content.</td>
+  <td>A developer-specified string that can be specified when you make a
+  <code>REQUEST_PURCHASE</code> request. This field is returned in the JSON string that contains
+  transaction information for an order. You can use this key to send supplemental information with
+  an order. For example, you can use this key to send index keys with an order, which is useful if
+  you are using a database to store purchase information. We recommend that you do not use this key
+  to send data or content.</td>
 </tr>
 </table>
 
@@ -149,39 +194,60 @@
 
 <ul>
   <li><code>CHECK_BILLING_SUPPORTED</code>
-    <p>This request verifies that the Android Market application supports in-app billing. You usually send this request when your application first starts up. This request is useful if you want to enable or disable certain UI features that are relevant only to in-app billing.</p>
+    <p>This request verifies that the Android Market application supports in-app billing. You
+    usually send this request when your application first starts up. This request is useful if you
+    want to enable or disable certain UI features that are relevant only to in-app billing.</p>
   </li>
   <li><code>REQUEST_PURCHASE</code>
-    <p>This request sends a purchase message to the Android Market application and is the foundation of in-app billing. You send this request when a user indicates that he or she wants to purchase an item in your application. Android Market then handles the financial transaction by displaying the checkout user interface.</p>
+    <p>This request sends a purchase message to the Android Market application and is the foundation
+    of in-app billing. You send this request when a user indicates that he or she wants to purchase
+    an item in your application. Android Market then handles the financial transaction by displaying
+    the checkout user interface.</p>
   </li>
   <li><code>GET_PURCHASE_INFORMATION</code>
-    <p>This request retrieves the details of a purchase state change. A purchase state change can occur when a purchase request is billed successfully or when a user cancels a transaction during checkout. It can also occur when a previous purchase is refunded. Android Market notifies your application when a purchase changes state, so you only need to send this request when there is transaction information to retrieve.</p>
+    <p>This request retrieves the details of a purchase state change. A purchase state change can
+    occur when a purchase request is billed successfully or when a user cancels a transaction during
+    checkout. It can also occur when a previous purchase is refunded. Android Market notifies your
+    application when a purchase changes state, so you only need to send this request when there is
+    transaction information to retrieve.</p>
   </li>
   <li><code>CONFIRM_NOTIFICATIONS</code>
-    <p>This request acknowledges that your application received the details of a purchase state change. That is, this message confirms that you sent a <code>GET_PURCHASE_INFORMATION</code> request for a given notification and that you received the purchase information for the notification.</p>
+    <p>This request acknowledges that your application received the details of a purchase state
+    change. That is, this message confirms that you sent a <code>GET_PURCHASE_INFORMATION</code>
+    request for a given notification and that you received the purchase information for the
+    notification.</p>
   </li>
   <li><code>RESTORE_TRANSACTIONS</code>
-    <p>This request retrieves a user's transaction status for managed purchases (see <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">Choosing a Purchase Type</a> for more information). You should send this message only when you need to retrieve a user's transaction status, which is usually only when your application is reinstalled or installed for the first time on a device.</p>
+    <p>This request retrieves a user's transaction status for managed purchases (see <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">Choosing a
+    Purchase Type</a> for more information). You should send this message only when you need to
+    retrieve a user's transaction status, which is usually only when your application is reinstalled
+    or installed for the first time on a device.</p>
   </li>
 </ul>
 
-<p>Every in-app billing request generates a synchronous response. The response is a {@link android.os.Bundle} and can include one or more of the following keys:</p>
+<p>Every in-app billing request generates a synchronous response. The response is a {@link
+android.os.Bundle} and can include one or more of the following keys:</p>
 
 <ul>
   <li><code>RESPONSE_CODE</code>
     <p>This key provides status information and error information about a request.</p>
   </li>
   <li><code>PURCHASE_INTENT</code>
-    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout activity.</p>
+    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout
+    activity.</p>
   </li>
   <li><code>REQUEST_ID</code>
-    <p>This key provides you with a request identifier, which you can use to match asynchronous responses with requests.</p>
+    <p>This key provides you with a request identifier, which you can use to match asynchronous
+    responses with requests.</p>
   </li>
 </ul>
 
-<p>Some of these keys are not relevant to certain types of requests. Table 3 shows which keys are returned for each request type.</p>
+<p>Some of these keys are not relevant to certain types of requests. Table 3 shows which keys are
+returned for each request type.</p>
 
-<p class="table-caption"><strong>Table 3.</strong> Description of Bundle keys that are returned with each in-app billing request type.</p>
+<p class="table-caption"><strong>Table 3.</strong> Description of Bundle keys that are returned with
+each in-app billing request type.</p>
 
 <table>
 
@@ -193,7 +259,8 @@
 <tr>
   <td><code>CHECK_BILLING_SUPPORTED</code></td>
   <td><code>RESPONSE_CODE</code></td>
-  <td><code>RESULT_OK</code>, <code>RESULT_BILLING_UNAVAILABLE</code>, <code>RESULT_ERROR</code>, <code>RESULT_DEVELOPER_ERROR</code></td>
+  <td><code>RESULT_OK</code>, <code>RESULT_BILLING_UNAVAILABLE</code>, <code>RESULT_ERROR</code>,
+  <code>RESULT_DEVELOPER_ERROR</code></td>
 </tr>
 <tr>
   <td><code>REQUEST_PURCHASE</code></td>
@@ -219,45 +286,77 @@
 
 <h2 id="billing-intents">In-app Billing Broadcast Intents</h2>
 
-<p>The following section describes the in-app billing broadcast intents that are sent by the Android Market application. These broadcast intents inform your application about in-app billing actions that have occurred. Your application must implement a {@link android.content.BroadcastReceiver} to receive these broadcast intents, such as the <code>BillingReceiver</code> that's shown in the in-app billing <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample application</a>.</p>
+<p>The following section describes the in-app billing broadcast intents that are sent by the Android
+Market application. These broadcast intents inform your application about in-app billing actions
+that have occurred. Your application must implement a {@link android.content.BroadcastReceiver} to
+receive these broadcast intents, such as the <code>BillingReceiver</code> that's shown in the in-app
+billing <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample
+application</a>.</p>
 
 <h4>com.android.vending.billing.RESPONSE_CODE</h4>
 
-<p>This broadcast intent contains an Android Market response code, and is sent after you make an in-app billing request. A server response code can indicate that a billing request was successfully sent to Android Market or it can indicate that some error occurred during a billing request. This intent is not used to report any purchase state changes (such as refund or purchase information). For more information about the response codes that are sent with this response, see <a href="#billing-codes">Android Market Response Codes for In-app Billing</a>. The sample application assigns this broadcast intent to a constant named <code>ACTION_RESPONSE_CODE</code>.</p>
+<p>This broadcast intent contains an Android Market response code, and is sent after you make an
+in-app billing request. A server response code can indicate that a billing request was successfully
+sent to Android Market or it can indicate that some error occurred during a billing request. This
+intent is not used to report any purchase state changes (such as refund or purchase information).
+For more information about the response codes that are sent with this response, see <a
+href="#billing-codes">Android Market Response Codes for In-app Billing</a>. The sample application
+assigns this broadcast intent to a constant named <code>ACTION_RESPONSE_CODE</code>.</p>
 
 <h5>Extras</h5>
 
 <ul type="none">
-  <li><code>request_id</code>&mdash;a <code>long</code> representing a request ID. A request ID identifies a specific billing request and is returned by Android Market at the time a request is made.</li>
-  <li><code>response_code</code>&mdash;an <code>int</code> representing the Android Market server response code.</li>
+  <li><code>request_id</code>&mdash;a <code>long</code> representing a request ID. A request ID
+  identifies a specific billing request and is returned by Android Market at the time a request is
+  made.</li>
+  <li><code>response_code</code>&mdash;an <code>int</code> representing the Android Market server
+  response code.</li>
 </ul>
 
 <h4>com.android.vending.billing.IN_APP_NOTIFY</h4>
 
-<p>This response indicates that a purchase has changed state, which means a purchase succeeded, was canceled, or was refunded. This response contains one or more notification IDs. Each notification ID corresponds to a specific server-side message, and each messages contains information about one or more transactions. After your application receives an <code>IN_APP_NOTIFY</code> broadcast intent, you send a <code>GET_PURCHASE_INFORMATION</code> request with the notification IDs to retrieve the message details. The sample application assigns this broadcast intent to a constant named <code>ACTION_NOTIFY</code>.</p>
+<p>This response indicates that a purchase has changed state, which means a purchase succeeded, was
+canceled, or was refunded. This response contains one or more notification IDs. Each notification ID
+corresponds to a specific server-side message, and each messages contains information about one or
+more transactions. After your application receives an <code>IN_APP_NOTIFY</code> broadcast intent,
+you send a <code>GET_PURCHASE_INFORMATION</code> request with the notification IDs to retrieve the
+message details. The sample application assigns this broadcast intent to a constant named
+<code>ACTION_NOTIFY</code>.</p>
 
 <h5>Extras</h5>
 
 <ul type="none">
-  <li><code>notification_id</code>&mdash;a <code>String</code> representing the notification ID for a given purchase state change. Android Market notifies you when there is a purchase state change and the notification includes a unique notification ID. To get the details of the purchase state change, you send the notification ID with the <code>GET_PURCHASE_INFORMATION</code> request.</li>
+  <li><code>notification_id</code>&mdash;a <code>String</code> representing the notification ID for
+  a given purchase state change. Android Market notifies you when there is a purchase state change
+  and the notification includes a unique notification ID. To get the details of the purchase state
+  change, you send the notification ID with the <code>GET_PURCHASE_INFORMATION</code> request.</li>
 </ul>
 
 <h4>com.android.vending.billing.PURCHASE_STATE_CHANGED</h4>
 
-<p>This broadcast intent contains detailed information about one or more transactions. The transaction information is contained in a JSON string. The JSON string is signed and the signature is sent to your application along with the JSON string (unencrypted). To help ensure the security of your in-app billing messages, your application can verify the signature of this JSON string. The sample application assigns this broadcast intent to a constant named <code>ACTION_PURCHASE_STATE_CHANGED</code>.</p>
+<p>This broadcast intent contains detailed information about one or more transactions. The
+transaction information is contained in a JSON string. The JSON string is signed and the signature
+is sent to your application along with the JSON string (unencrypted). To help ensure the security of
+your in-app billing messages, your application can verify the signature of this JSON string. The
+sample application assigns this broadcast intent to a constant named
+<code>ACTION_PURCHASE_STATE_CHANGED</code>.</p>
 
 <h5>Extras</h5>
 
 <ul type="none">
-  <li><code>inapp_signed_data</code>&mdash;a <code>String</code> representing the signed JSON string.</li>
+  <li><code>inapp_signed_data</code>&mdash;a <code>String</code> representing the signed JSON
+  string.</li>
   <li><code>inapp_signature</code>&mdash;a <code>String</code> representing the signature.</li>
 </ul>
 
-<p class="note"><strong>Note:</strong> Your application should map the broadcast intents and extras to constants that are unique to your application. See the <code>Consts.java</code> file in the sample application to see how this is done.</p>
+<p class="note"><strong>Note:</strong> Your application should map the broadcast intents and extras
+to constants that are unique to your application. See the <code>Consts.java</code> file in the
+sample application to see how this is done.</p>
 
 <p>The fields in the JSON string are described in the following table (see table 4):</p>
 
-<p class="table-caption"><strong>Table 4.</strong> Description of JSON fields that are returned with a <code>PURCHASE_STATE_CHANGED</code> intent.</p>
+<p class="table-caption"><strong>Table 4.</strong> Description of JSON fields that are returned with
+a <code>PURCHASE_STATE_CHANGED</code> intent.</p>
 
 <table>
 
@@ -267,15 +366,22 @@
 </tr>
 <tr>
   <td>nonce</td>
-  <td>A number used once. Your application generates the nonce and sends it with the <code>GET_PURCHASE_INFORMATION</code> request. Android Market sends the nonce back as part of the JSON string so you can verify the integrity of the message.</td>
+  <td>A number used once. Your application generates the nonce and sends it with the
+  <code>GET_PURCHASE_INFORMATION</code> request. Android Market sends the nonce back as part of the
+  JSON string so you can verify the integrity of the message.</td>
 </tr>
 <tr>
   <td>notificationId</td>
-  <td>A unique identifier that is sent with an <code>IN_APP_NOTIFY</code> broadcast intent. Each <code>notificationId</code> corresponds to a specify message that is waiting to be retrieved on the Android Market server. Your application sends back the <code>notificationId</code> with the <code>GET_PURCHASE_INFORMATION</code> message so Android Market can determine which messages you are retrieving.</td>
+  <td>A unique identifier that is sent with an <code>IN_APP_NOTIFY</code> broadcast intent. Each
+  <code>notificationId</code> corresponds to a specify message that is waiting to be retrieved on
+  the Android Market server. Your application sends back the <code>notificationId</code> with the
+  <code>GET_PURCHASE_INFORMATION</code> message so Android Market can determine which messages you
+  are retrieving.</td>
 </tr>
 <tr>
   <td>orderId</td>
-  <td>A unique order identifier for the transaction. This corresponds to the Google Checkout Order ID.</td>
+  <td>A unique order identifier for the transaction. This corresponds to the Google Checkout Order
+  ID.</td>
 </tr>
 <tr>
   <td>packageName</td>
@@ -283,7 +389,8 @@
 </tr>
 <tr>
   <td>productId</td>
-  <td>The item's product identifier. Every item has a product ID, which you must specify in the application's product list on the Android Market publisher site.</td>
+  <td>The item's product identifier. Every item has a product ID, which you must specify in the
+  application's product list on the Android Market publisher site.</td>
 </tr>
 <tr>
   <td>purchaseTime</td>
@@ -292,10 +399,12 @@
 
 <tr>
   <td>purchaseState</td>
-  <td>The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded).</td>
+  <td>The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2
+  (refunded).</td>
 </tr>
 <tr>
   <td>developerPayload</td>
-  <td>A developer-specified string that contains supplemental information about an order. You can specify a value for this field when you make a <code>REQUEST_PURCHASE</code> request.</td>
+  <td>A developer-specified string that contains supplemental information about an order. You can
+  specify a value for this field when you make a <code>REQUEST_PURCHASE</code> request.</td>
 </tr>
 </table>
diff --git a/docs/html/guide/market/billing/billing_testing.jd b/docs/html/guide/market/billing/billing_testing.jd
index 742e7ef4d..84d25b2 100755
--- a/docs/html/guide/market/billing/billing_testing.jd
+++ b/docs/html/guide/market/billing/billing_testing.jd
@@ -13,57 +13,104 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>The Android Market publisher site provides several tools that help you test your in-app billing implementation before it is published. You can use these tools to create test accounts and purchase special reserved items that send static billing responses to your application.</p>
+<p>The Android Market publisher site provides several tools that help you test your in-app billing
+implementation before it is published. You can use these tools to create test accounts and purchase
+special reserved items that send static billing responses to your application.</p>
 
-<p>To test in-app billing in an application you must install the application on an Android-powered device. You cannot use the Android emulator to test in-app billing.  The device you use for testing must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have the most current version of the Android Market application installed. If a device is not running the most current Android Market application, your application won't be able to send in-app billing requests to Android Market. 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>
+<p>To test in-app billing in an application you must install the application on an Android-powered
+device. You cannot use the Android emulator to test in-app billing.  The device you use for testing
+must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have
+the most current version of the Android Market application installed. If a device is not running the
+most current Android Market application, your application won't be able to send in-app billing
+requests to Android Market. 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>
 
 <p>The following section shows you how to set up and use the in-app billing test tools.</p>
 
 <h2 id="billing-testing-static">Testing in-app purchases with static responses</h2>
 
-<p>We recommend that you first test your in-app billing implementation using static responses from Android Market. This enables you to verify that your application is handling the primary Android Market responses correctly and that your application is able to verify signatures correctly.</p>
+<p>We recommend that you first test your in-app billing implementation using static responses from
+Android Market. This enables you to verify that your application is handling the primary Android
+Market responses correctly and that your application is able to verify signatures correctly.</p>
 
-<p>To test your implementation with static responses, you make an in-app billing request using a special item that has a reserved product ID. Each reserved product ID returns a specific static response from Android Market. No money is transferred when you make in-app billing requests with the reserved product IDs. Also, you cannot specify the form of payment when you make a billing request with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the product ID android.test.purchased.</p>
+<p>To test your implementation with static responses, you make an in-app billing request using a
+special item that has a reserved product ID. Each reserved product ID returns a specific static
+response from Android Market. No money is transferred when you make in-app billing requests with the
+reserved product IDs. Also, you cannot specify the form of payment when you make a billing request
+with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the
+product ID android.test.purchased.</p>
 
 <img src="{@docRoot}images/billing_test_flow.png" height="381" id="figure1" />
 <p class="img-caption">
   <strong>Figure 1.</strong> Checkout flow for the special reserved item android.test.purchased.
 </p>
 
-<p>You do not need to list the reserved products in your application's product list. Android Market already knows about the reserved product IDs. Also, you do not need to upload your application to the publisher site to perform static response tests with the reserved product IDs. You can simply install your application on a device, log into the device, and make billing requests using the reserved product IDs.</p>
+<p>You do not need to list the reserved products in your application's product list. Android Market
+already knows about the reserved product IDs. Also, you do not need to upload your application to
+the publisher site to perform static response tests with the reserved product IDs. You can simply
+install your application on a device, log into the device, and make billing requests using the
+reserved product IDs.</p>
 
 <p>There are four reserved product IDs for testing static in-app billing responses:</p>
 
 <ul>
   <li><strong>android.test.purchased</strong>
-    <p>When you make an in-app billing request with this product ID, Android Market responds as though you successfully purchased an item. The response includes a JSON string, which contains fake purchase information (for example, a fake order ID). In some cases, the JSON string is signed and the response includes the signature so you can test your signature verification implementation using these responses.</p>
+    <p>When you make an in-app billing request with this product ID, Android Market responds as
+    though you successfully purchased an item. The response includes a JSON string, which contains
+    fake purchase information (for example, a fake order ID). In some cases, the JSON string is
+    signed and the response includes the signature so you can test your signature verification
+    implementation using these responses.</p>
   </li>
   <li><strong>android.test.canceled</strong>
-    <p>When you make an in-app billing request with this product ID Android Market responds as though the purchase was canceled. This can occur when an error is encountered in the order process, such as an invalid credit card, or when you cancel a user's order before it is charged.</p>
+    <p>When you make an in-app billing request with this product ID Android Market responds as
+    though the purchase was canceled. This can occur when an error is encountered in the order
+    process, such as an invalid credit card, or when you cancel a user's order before it is
+    charged.</p>
   </li>
   <li><strong>android.test.refunded</strong>
-    <p>When you make an in-app billing request with this product ID, Android Market responds as though the purchase was refunded. Refunds cannot be initiated through Android Market's in-app billing service. Refunds must be initiated by you (the merchant). After you process a refund request through your Google Checkout account, a refund message is sent to your application by Android Market. This occurs only when Android Market gets notification from Google Checkout that a refund has been made. For more information about refunds, see <a href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling IN_APP_NOTIFY messages</a> and <a href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing Pricing</a>.</p>
+    <p>When you make an in-app billing request with this product ID, Android Market responds as
+    though the purchase was refunded. Refunds cannot be initiated through Android Market's in-app
+    billing service. Refunds must be initiated by you (the merchant). After you process a refund
+    request through your Google Checkout account, a refund message is sent to your application by
+    Android Market. This occurs only when Android Market gets notification from Google Checkout that
+    a refund has been made. For more information about refunds, see <a
+    href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling
+    IN_APP_NOTIFY messages</a> and <a
+    href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing
+    Pricing</a>.</p>
   </li>
   <li><strong>android.test.item_unavailable</strong>
-    <p>When you make an in-app billing request with this product ID, Android Market responds as though the item being purchased was not listed in your application's product list.</p>
+    <p>When you make an in-app billing request with this product ID, Android Market responds as
+    though the item being purchased was not listed in your application's product list.</p>
   </li>
 </ul>
 
-<p>In some cases, the reserved items may return signed static responses, which lets you test signature verification in your application. To test signature verification with the special reserved product IDs, you may need to set up <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> or upload your application as a unpublished draft application. Table 1 shows you the conditions under which static responses are signed.</p>
+<p>In some cases, the reserved items may return signed static responses, which lets you test
+signature verification in your application. To test signature verification with the special reserved
+product IDs, you may need to set up <a
+href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> or
+upload your application as a unpublished draft application. Table 1 shows you the conditions under
+which static responses are signed.</p>
 
 <p class="table-caption" id="static-responses-table"><strong>Table 1.</strong>
 Conditions under which static responses are signed.</p>
@@ -120,68 +167,118 @@
 
 </table>
 
-<p>To make an in-app billing request with a reserved product ID, you simply construct a normal <code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your application's product list you use one of the reserved product IDs.</p>
+<p>To make an in-app billing request with a reserved product ID, you simply construct a normal
+<code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your
+application's product list you use one of the reserved product IDs.</p>
 
 <p>To test your application using the reserved product IDs, follow these steps:</p>
 
 <ol>
   <li><strong>Install your application on an Android-powered device.</strong>
-    <p>You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.</p>
-    <p>To learn how to install an application on a device, see <a href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a device</a>.</p>
+    <p>You cannot use the emulator to test in-app billing; you must install your application on a
+    device to test in-app billing.</p>
+    <p>To learn how to install an application on a device, see <a
+    href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a
+    device</a>.</p>
   </li>
   <li><strong>Sign in to your device with your developer account.</strong>
-    <p>You do not need to use a test account if you are testing only with the reserved product IDs.</p>
+    <p>You do not need to use a test account if you are testing only with the reserved product
+    IDs.</p>
   </li>
-  <li><strong>Verify that your device is running a supported version of the Android Market application or the MyApps application.</strong>
-    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>.</p>
+  <li><strong>Verify that your device is running a supported version of the Android Market
+  application or the MyApps application.</strong>
+    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+    the MyApps application. If your device is running any other version of Android, in-app billing
+    requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the
+    version of the Android Market application, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android
+    Market</a>.</p>
   </li>
   <li><strong>Run your application and purchase the reserved product IDs.</strong></li>
 </ol>
 
-<p class="note"><strong>Note</strong>: Making in-app billing requests with the reserved product IDs overrides the usual Android Market production system. When you send an in-app billing request for a reserved product ID, the quality of service will not be comparable to the production environment.</p>
+<p class="note"><strong>Note</strong>: Making in-app billing requests with the reserved product IDs
+overrides the usual Android Market production system. When you send an in-app billing request for a
+reserved product ID, the quality of service will not be comparable to the production
+environment.</p>
 
 <h2 id="billing-testing-real">Testing In-app Purchases Using Your Own Product IDs</h2>
 
-<p>After you finish your static response testing, and you verify that signature verification is working in your application, you can test your in-app billing implementation by making actual in-app purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing experience, including the actual responses from Android Market and the actual checkout flow that users will experience in your application.</p>
+<p>After you finish your static response testing, and you verify that signature verification is
+working in your application, you can test your in-app billing implementation by making actual in-app
+purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing
+experience, including the actual responses from Android Market and the actual checkout flow that
+users will experience in your application.</p>
 
-<p class="note"><strong>Note</strong>: You do not need to publish your application to do end-to-end testing. You only need to upload your draft application to perform end-to-end testing.</p>
+<p class="note"><strong>Note</strong>: You do not need to publish your application to do end-to-end
+testing. You only need to upload your draft application to perform end-to-end testing.</p>
 
-<p>To test your in-app billing implementation with actual in-app purchases, you will need to register at least one test account on the Android Market publisher site. You cannot use your developer account to test the complete in-app purchase process because Google Checkout does not let you buy items from yourself. If you have not set up test accounts before, see <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">Setting up test accounts</a>.</p>
+<p>To test your in-app billing implementation with actual in-app purchases, you will need to
+register at least one test account on the Android Market publisher site. You cannot use your
+developer account to test the complete in-app purchase process because Google Checkout does not let
+you buy items from yourself. If you have not set up test accounts before, see <a
+href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">Setting up test
+accounts</a>.</p>
 
-<p>Also, a test account can purchase an item in your product list only if the item is published. The application does not need to be published, but the item does need to be published.</p>
+<p>Also, a test account can purchase an item in your product list only if the item is published. The
+application does not need to be published, but the item does need to be published.</p>
 
-<p>When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.</p>
+<p>When you use a test account to purchase items, the test account is billed through Google Checkout
+and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may
+want to refund purchases that are made with test accounts, otherwise the purchases will show up as
+actual payouts to your merchant account.</p>
 
 <p>To test your in-app billing implementation with actual purchases, follow these steps:</p>
 
 <ol>
   <li><strong>Upload your application as a draft application to the publisher site.</strong>
-    <p>You do not need to publish your application to perform end-to-end testing with real product IDs. To learn how to upload an application to Android Market, see <a href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading applications</a>.</p>
+    <p>You do not need to publish your application to perform end-to-end testing with real product
+    IDs. To learn how to upload an application to Android Market, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading
+    applications</a>.</p>
   </li>
   <li><strong>Add items to the application's product list.</strong>
-    <p>Make sure that you publish the items (the application can remain unpublished). See <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-catalog">Creating a product list</a> to learn how to do this.</p>
+    <p>Make sure that you publish the items (the application can remain unpublished). See <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-catalog">Creating a product
+    list</a> to learn how to do this.</p>
   </li>
   <li><strong>Install your application on an Android-powered device.</strong>
-    <p>You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.</p>
-    <p>To learn how to install an application on a device, see <a href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a device</a>.</p>
+    <p>You cannot use the emulator to test in-app billing; you must install your application on a
+    device to test in-app billing.</p>
+    <p>To learn how to install an application on a device, see <a
+    href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a
+    device</a>.</p>
   </li>
  <li><strong>Make one of your test accounts the primary account on your device.</strong>
-    <p>To perform end-to-end testing of in-app billing, the primary account on your device must be one of the <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:</p>
+    <p>To perform end-to-end testing of in-app billing, the primary account on your device must be
+    one of the <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a>
+    that you registered on the Android Market site. If the primary account on your device is not a
+    test account, you must do a factory reset of the device and then sign in with one of your test
+    accounts. To perform a factory reset, do the following:</p>
     <ol>
       <li>Open Settings on your device.</li>
       <li>Touch <strong>Privacy</strong>.</li>
       <li>Touch <strong>Factory data reset</strong>.</li>
       <li>Touch <strong>Reset phone</strong>.</li>
-      <li>After the phone resets, be sure to sign in with one of your test accounts during the device setup process.</li>
+      <li>After the phone resets, be sure to sign in with one of your test accounts during the
+      device setup process.</li>
     </ol>
   </li>
-  <li><strong>Verify that your device is running a supported version of the Android Market application or the MyApps application.</strong>
-    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>.</p>
+  <li><strong>Verify that your device is running a supported version of the Android Market
+  application or the MyApps application.</strong>
+    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+    the MyApps application. If your device is running any other version of Android, in-app billing
+    requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the
+    version of the Android Market application, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android
+    Market</a>.</p>
   </li>
   <li><strong>Make in-app purchases in your application.</strong></li>
 </ol>
 
-<p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to do a factory reset, making sure you log on with your primary account first.</p>
+<p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to
+do a factory reset, making sure you log on with your primary account first.</p>
 
 <p>When you are finished testing your in-app billing implementation, you are ready to
 publish your application on Android Market. You can follow the normal steps for <a
diff --git a/docs/html/guide/market/billing/index.jd b/docs/html/guide/market/billing/index.jd
index fb85fa6..fdfa6fa 100755
--- a/docs/html/guide/market/billing/index.jd
+++ b/docs/html/guide/market/billing/index.jd
@@ -6,52 +6,89 @@
 
   <h2>Topics</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
   </ol>
   <h2>Reference</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>  
 </div>
 </div>
 
-<p>Android Market In-app Billing is an Android Market service that lets you sell digital content in your applications. You can use the service to sell a wide range of content, including downloadable content such as media files or photos, and virtual content such as game levels or potions.</p>
+<p>Android Market In-app Billing is an Android Market service that lets you sell digital content in
+your applications. You can use the service to sell a wide range of content, including downloadable
+content such as media files or photos, and virtual content such as game levels or potions.</p>
 
-<p>When you use Android Market's in-app billing service to sell an item, Android Market handles all checkout details so your application never has to directly process any financial transactions. Android Market uses the same checkout service that is used for application purchases, so your users experience a consistent and familiar purchase flow (see figure 1). Also, the transaction fee for in-app purchases is the same as the transaction fee for application purchases (30%).</p>
+<p>When you use Android Market's in-app billing service to sell an item, Android Market handles all
+checkout details so your application never has to directly process any financial transactions.
+Android Market uses the same checkout service that is used for application purchases, so your users
+experience a consistent and familiar purchase flow (see figure 1). Also, the transaction fee for
+in-app purchases is the same as the transaction fee for application purchases (30%).</p>
 
-<p>Any application that you publish through Android Market can implement in-app billing. No special account or registration is required other than an Android Market publisher account and a Google Checkout Merchant account. Also, because the service uses no dedicated framework APIs, you can add in-app billing to any application that uses a minimum API level of 4 or higher.</p>
+<p>Any application that you publish through Android Market can implement in-app billing. No special
+account or registration is required other than an Android Market publisher account and a Google
+Checkout Merchant account. Also, because the service uses no dedicated framework APIs, you can add
+in-app billing to any application that uses a minimum API level of 4 or higher.</p>
 
-<p>To help you integrate in-app billing into your application, the Android SDK provides a sample application that demonstrates a simple implementation of in-app billing. The sample application contains examples of billing-related classes you can use to implement in-app billing in your application. It also contains examples of the database, user interface, and business logic you might use to implement in-app billing.</p>
+<p>To help you integrate in-app billing into your application, the Android SDK provides a sample
+application that demonstrates a simple implementation of in-app billing. The sample application
+contains examples of billing-related classes you can use to implement in-app billing in your
+application. It also contains examples of the database, user interface, and business logic you might
+use to implement in-app billing.</p>
 
-<p class="caution"><strong>Important</strong>: Although the sample application is a working example of how you can implement in-app billing, we <em>strongly recommend</em> that you modify and obfuscate the sample code before you use it in a production application. For more information, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p class="caution"><strong>Important</strong>: Although the sample application is a working example
+of how you can implement in-app billing, we <em>strongly recommend</em> that you modify and
+obfuscate the sample code before you use it in a production application. For more information, see
+<a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
 
 <img src="{@docRoot}images/billing_checkout_flow.png" height="382" id="figure1" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> Applications initiate in-app billing requests through their own UI (first screen). Android Market responds to the request by providing the checkout user interface (middle screen). When checkout is complete, the application resumes.
+  <strong>Figure 1.</strong> Applications initiate in-app billing requests through their own UI
+  (first screen). Android Market responds to the request by providing the checkout user interface
+  (middle screen). When checkout is complete, the application resumes.
 </p>
 
-<p>To learn more about Android Market's in-app billing service and start integrating it into your applications, read the following documents:</p>
+<p>To learn more about Android Market's in-app billing service and start integrating it into your
+applications, read the following documents:</p>
 
 <dl>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></strong></dt>
-    <dd>Learn how the service works and what a typical in-app billing implementation looks like.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></strong></dt>
-    <dd>Use this step-by-step guide to start incorporating in-app billing into your application.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></strong></dt>
-    <dd>Review these best practices to help ensure that your in-app billing implementation is secure and well designed.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></strong></dt>
-    <dd>Understand how the in-app billing test tools work and learn how to test your in-app billing implementation.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></strong></dt>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+  Billing</a></strong></dt>
+    <dd>Learn how the service works and what a typical in-app billing implementation looks
+    like.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing
+  In-app Billing</a></strong></dt>
+    <dd>Use this step-by-step guide to start incorporating in-app billing into your
+    application.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security
+  and Design</a></strong></dt>
+    <dd>Review these best practices to help ensure that your in-app billing implementation is
+    secure and well designed.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+  Billing</a></strong></dt>
+    <dd>Understand how the in-app billing test tools work and learn how to test your in-app billing
+    implementation.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering
+  In-app Billing</a></strong></dt>
     <dd>Learn how to set up your product list, register test accounts, and handle refunds.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></strong></dt>
-    <dd>Get detailed information about Android Market response codes and the in-app billing interface.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+  Reference</a></strong></dt>
+    <dd>Get detailed information about Android Market response codes and the in-app billing
+    interface.</dd>
 </dl>
 
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 1da2622..10d25bb 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -383,6 +383,46 @@
 which indicates whether the screen is long.</p>
       </td>
     </tr>
+    <tr id="ScreenWidthQualifier">
+      <td>Screen width</td>
+      <td>Examples:<br/>
+        <code>w720dp</code><br/>
+        <code>w1024dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum screen width, in "dp" units, at which the resource
+          should be used.  This configuration value will change when the orientation
+          changes between landscape and portrait to match the current actual width.
+          When multiple screen width configurations are available, the closest to
+          the current screen width will be used.  The value specified here is
+          approximate; screen decorations like a status bar or system bar may cause
+          the actual space available in your UI to be slightly smaller.
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
+          configuration field, which holds the current screen width.</p>
+      </td>
+    </tr>
+    <tr id="ScreenHeightQualifier">
+      <td>Screen height</td>
+      <td>Examples:<br/>
+        <code>h720dp</code><br/>
+        <code>h1024dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum screen height, in "dp" units, at which the resource
+          should be used.  This configuration value will change when the orientation
+          changes between landscape and portrait to match the current actual height.
+          When multiple screen height configurations are available, the closest to
+          the current screen height will be used.  The value specified here is
+          approximate; screen decorations like a status bar or system bar may cause
+          the actual space available in your UI to be slightly smaller.
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
+          configuration field, which holds the current screen width.</p>
+      </td>
+    </tr>
     <tr id="OrientationQualifier">
       <td>Screen orientation</td>
       <td>
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index b89d36d..cf8749b 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -55,18 +55,6 @@
         mCullMode = CullMode.BACK;
     }
 
-    void setLineWidth(float w) {
-        mRS.validate();
-        mLineWidth = w;
-        mRS.nProgramRasterSetLineWidth(getID(), w);
-    }
-
-    void setCullMode(CullMode m) {
-        mRS.validate();
-        mCullMode = m;
-        mRS.nProgramRasterSetCullMode(getID(), m.mID);
-    }
-
     public static ProgramRaster CULL_BACK(RenderScript rs) {
         if(rs.mProgramRaster_CULL_BACK == null) {
             ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
@@ -119,16 +107,11 @@
             return this;
         }
 
-        static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
-            int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite);
-            ProgramRaster pr = new ProgramRaster(id, rs);
-            pr.setCullMode(b.mCullMode);
-            return pr;
-        }
-
         public ProgramRaster create() {
             mRS.validate();
-            return internalCreate(mRS, this);
+            int id = mRS.nProgramRasterCreate(mPointSmooth, mLineSmooth, mPointSprite,
+                                             1.f, mCullMode.mID);
+            return new ProgramRaster(id, mRS);
         }
     }
 
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index c46e6b9..7a84d8b 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -333,27 +333,15 @@
             return this;
         }
 
-        static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
-            rs.nProgramStoreBegin(0, 0);
-            rs.nProgramStoreDepthFunc(b.mDepthFunc.mID);
-            rs.nProgramStoreDepthMask(b.mDepthMask);
-            rs.nProgramStoreColorMask(b.mColorMaskR,
-                                              b.mColorMaskG,
-                                              b.mColorMaskB,
-                                              b.mColorMaskA);
-            rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
-            rs.nProgramStoreDither(b.mDither);
-
-            int id = rs.nProgramStoreCreate();
-            return new ProgramStore(id, rs);
-        }
-
         /**
         * Creates a program store from the current state of the builder
         */
         public ProgramStore create() {
             mRS.validate();
-            return internalCreate(mRS, this);
+            int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
+                                             mDepthMask, mDither,
+                                             mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
+            return new ProgramStore(id, mRS);
         }
     }
 
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index f577532..8f05dc3 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -485,56 +485,24 @@
         return rsnSamplerCreate(mContext);
     }
 
-    native void rsnProgramStoreBegin(int con, int in, int out);
-    synchronized void nProgramStoreBegin(int in, int out) {
+    native int  rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
+                                      boolean depthMask, boolean dither,
+                                      int srcMode, int dstMode, int depthFunc);
+    synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
+                                         boolean depthMask, boolean dither,
+                                         int srcMode, int dstMode, int depthFunc) {
         validate();
-        rsnProgramStoreBegin(mContext, in, out);
-    }
-    native void rsnProgramStoreDepthFunc(int con, int func);
-    synchronized void nProgramStoreDepthFunc(int func) {
-        validate();
-        rsnProgramStoreDepthFunc(mContext, func);
-    }
-    native void rsnProgramStoreDepthMask(int con, boolean enable);
-    synchronized void nProgramStoreDepthMask(boolean enable) {
-        validate();
-        rsnProgramStoreDepthMask(mContext, enable);
-    }
-    native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a);
-    synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
-        validate();
-        rsnProgramStoreColorMask(mContext, r, g, b, a);
-    }
-    native void rsnProgramStoreBlendFunc(int con, int src, int dst);
-    synchronized void nProgramStoreBlendFunc(int src, int dst) {
-        validate();
-        rsnProgramStoreBlendFunc(mContext, src, dst);
-    }
-    native void rsnProgramStoreDither(int con, boolean enable);
-    synchronized void nProgramStoreDither(boolean enable) {
-        validate();
-        rsnProgramStoreDither(mContext, enable);
-    }
-    native int  rsnProgramStoreCreate(int con);
-    synchronized int nProgramStoreCreate() {
-        validate();
-        return rsnProgramStoreCreate(mContext);
+        return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
+                                     dstMode, depthFunc);
     }
 
-    native int  rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
-    synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) {
+    native int  rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth,
+                                       boolean pointSprite, float lineWidth, int cullMode);
+    synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth,
+                                          boolean pointSprite, float lineWidth, int cullMode) {
         validate();
-        return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite);
-    }
-    native void rsnProgramRasterSetLineWidth(int con, int pr, float v);
-    synchronized void nProgramRasterSetLineWidth(int pr, float v) {
-        validate();
-        rsnProgramRasterSetLineWidth(mContext, pr, v);
-    }
-    native void rsnProgramRasterSetCullMode(int con, int pr, int mode);
-    synchronized void nProgramRasterSetCullMode(int pr, int mode) {
-        validate();
-        rsnProgramRasterSetCullMode(mContext, pr, mode);
+        return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite, lineWidth,
+                                      cullMode);
     }
 
     native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index c7f4809..12c5940 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -897,53 +897,17 @@
 
 // ---------------------------------------------------------------------------
 
-static void
-nProgramStoreBegin(JNIEnv *_env, jobject _this, RsContext con, jint in, jint out)
-{
-    LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
-    rsProgramStoreBegin(con, (RsElement)in, (RsElement)out);
-}
-
-static void
-nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, RsContext con, jint func)
-{
-    LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func);
-    rsProgramStoreDepthFunc(con, (RsDepthFunc)func);
-}
-
-static void
-nProgramStoreDepthMask(JNIEnv *_env, jobject _this, RsContext con, jboolean enable)
-{
-    LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable);
-    rsProgramStoreDepthMask(con, enable);
-}
-
-static void
-nProgramStoreColorMask(JNIEnv *_env, jobject _this, RsContext con, jboolean r, jboolean g, jboolean b, jboolean a)
-{
-    LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a);
-    rsProgramStoreColorMask(con, r, g, b, a);
-}
-
-static void
-nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, RsContext con, int src, int dst)
-{
-    LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst);
-    rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst);
-}
-
-static void
-nProgramStoreDither(JNIEnv *_env, jobject _this, RsContext con, jboolean enable)
-{
-    LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable);
-    rsProgramStoreDither(con, enable);
-}
-
 static jint
-nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con)
+nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
+                    jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
+                    jboolean depthMask, jboolean ditherEnable,
+                    jint srcFunc, jint destFunc,
+                    jint depthFunc)
 {
     LOG_API("nProgramStoreCreate, con(%p)", con);
-    return (jint)rsProgramStoreCreate(con);
+    return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
+                                      depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
+                                      (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
 }
 
 // ---------------------------------------------------------------------------
@@ -1005,25 +969,12 @@
 // ---------------------------------------------------------------------------
 
 static jint
-nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite)
+nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth,
+                     jboolean lineSmooth, jboolean pointSprite, jfloat lineWidth, jint cull)
 {
     LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
             con, pointSmooth, lineSmooth, pointSprite);
-    return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite);
-}
-
-static void
-nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jfloat v)
-{
-    LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v);
-    rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v);
-}
-
-static void
-nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jint v)
-{
-    LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v);
-    rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v);
+    return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite, lineWidth, (RsCullMode)cull);
 }
 
 
@@ -1270,24 +1221,14 @@
 
 {"rsnScriptCCreate",                 "(ILjava/lang/String;Ljava/lang/String;[BI)I",  (void*)nScriptCCreate },
 
-{"rsnProgramStoreBegin",             "(III)V",                                (void*)nProgramStoreBegin },
-{"rsnProgramStoreDepthFunc",         "(II)V",                                 (void*)nProgramStoreDepthFunc },
-{"rsnProgramStoreDepthMask",         "(IZ)V",                                 (void*)nProgramStoreDepthMask },
-{"rsnProgramStoreColorMask",         "(IZZZZ)V",                              (void*)nProgramStoreColorMask },
-{"rsnProgramStoreBlendFunc",         "(III)V",                                (void*)nProgramStoreBlendFunc },
-{"rsnProgramStoreDither",            "(IZ)V",                                 (void*)nProgramStoreDither },
-{"rsnProgramStoreCreate",            "(I)I",                                  (void*)nProgramStoreCreate },
+{"rsnProgramStoreCreate",            "(IZZZZZZIII)I",                         (void*)nProgramStoreCreate },
 
 {"rsnProgramBindConstants",          "(IIII)V",                               (void*)nProgramBindConstants },
 {"rsnProgramBindTexture",            "(IIII)V",                               (void*)nProgramBindTexture },
 {"rsnProgramBindSampler",            "(IIII)V",                               (void*)nProgramBindSampler },
 
 {"rsnProgramFragmentCreate",         "(ILjava/lang/String;[I)I",              (void*)nProgramFragmentCreate },
-
-{"rsnProgramRasterCreate",           "(IZZZ)I",                               (void*)nProgramRasterCreate },
-{"rsnProgramRasterSetLineWidth",     "(IIF)V",                                (void*)nProgramRasterSetLineWidth },
-{"rsnProgramRasterSetCullMode",      "(III)V",                                (void*)nProgramRasterSetCullMode },
-
+{"rsnProgramRasterCreate",           "(IZZZFI)I",                             (void*)nProgramRasterCreate },
 {"rsnProgramVertexCreate",           "(ILjava/lang/String;[I)I",              (void*)nProgramVertexCreate },
 
 {"rsnContextBindRootScript",         "(II)V",                                 (void*)nContextBindRootScript },
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 2dc4beb..edf4b8b7 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -33,6 +33,7 @@
 {
 public:
 
+    // must match android/media/AudioSystem.java STREAM_* constants
     enum stream_type {
         DEFAULT          =-1,
         VOICE_CALL       = 0,
@@ -54,6 +55,8 @@
         PCM_SUB_8_BIT           = 0x2, // must be 2 for backward compatibility
     };
 
+    // FIXME These sub_format enums are currently unused
+
     // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
     // bit rate, stereo mode, version...
     enum mp3_sub_format {
@@ -100,7 +103,7 @@
     };
 
 
-    // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
+    // Channel mask definitions must be kept in sync with values in /media/java/android/media/AudioFormat.java
     enum audio_channels {
         // output channels
         CHANNEL_OUT_FRONT_LEFT = 0x4,
@@ -150,6 +153,7 @@
                 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
     };
 
+    // must match android/media/AudioSystem.java MODE_* values
     enum audio_mode {
         MODE_INVALID = -2,
         MODE_CURRENT = -1,
@@ -189,6 +193,7 @@
     // set/get master volume
     static status_t setMasterVolume(float value);
     static status_t getMasterVolume(float* volume);
+
     // mute/unmute audio outputs
     static status_t setMasterMute(bool mute);
     static status_t getMasterMute(bool* mute);
@@ -234,7 +239,7 @@
     static status_t setVoiceVolume(float volume);
 
     // return the number of audio frames written by AudioFlinger to audio HAL and
-    // audio dsp to DAC since the output on which the specificed stream is playing
+    // audio dsp to DAC since the output on which the specified stream is playing
     // has exited standby.
     // returned status (from utils/Errors.h) can be:
     // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
@@ -321,7 +326,7 @@
         FORCE_DEFAULT = FORCE_NONE
     };
 
-    // usages used for setForceUse()
+    // usages used for setForceUse(), must match AudioSystem.java
     enum force_use {
         FOR_COMMUNICATION,
         FOR_MEDIA,
diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h
index 70519ef..9b1af6b 100644
--- a/include/media/IMediaPlayer.h
+++ b/include/media/IMediaPlayer.h
@@ -24,7 +24,6 @@
 namespace android {
 
 class Parcel;
-class ISurface;
 class Surface;
 class ISurfaceTexture;
 
diff --git a/include/media/IOMX.h b/include/media/IOMX.h
index 16a9342..3c65147 100644
--- a/include/media/IOMX.h
+++ b/include/media/IOMX.h
@@ -33,7 +33,6 @@
 class IMemory;
 class IOMXObserver;
 class IOMXRenderer;
-class ISurface;
 class Surface;
 
 class IOMX : public IInterface {
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index 117d7eb..447942b 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -32,7 +32,6 @@
 namespace android {
 
 class Parcel;
-class ISurface;
 class Surface;
 class ISurfaceTexture;
 
diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h
index a59d9e5..3923e61 100644
--- a/include/surfaceflinger/Surface.h
+++ b/include/surfaceflinger/Surface.h
@@ -102,10 +102,6 @@
     friend class Test;
     // videoEditor preview classes
     friend class VideoEditorPreviewController;
-
-    const sp<ISurface>& getISurface() const { return mSurface; }
-    
-
     friend class Surface;
 
     SurfaceControl(
@@ -169,6 +165,7 @@
     // setSwapRectangle() is intended to be used by GL ES clients
     void        setSwapRectangle(const Rect& r);
 
+    sp<IBinder> asBinder() const;
 
 private:
     /*
@@ -242,7 +239,6 @@
      */
     void init();
     status_t validate(bool inCancelBuffer = false) const;
-    sp<ISurface> getISurface() const;
 
     // When the buffer pool is a fixed size we want to make sure SurfaceFlinger
     // won't stall clients, so we require an extra buffer.
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index 6227f3e..35792dc 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -972,6 +972,14 @@
         uint32_t screenConfig;
     };
     
+    union {
+        struct {
+            uint16_t screenWidthDp;
+            uint16_t screenHeightDp;
+        };
+        uint32_t screenSizeDp;
+    };
+
     inline void copyFromDeviceNoSwap(const ResTable_config& o) {
         const size_t size = dtohl(o.size);
         if (size >= sizeof(ResTable_config)) {
@@ -992,6 +1000,8 @@
         screenHeight = dtohs(screenHeight);
         sdkVersion = dtohs(sdkVersion);
         minorVersion = dtohs(minorVersion);
+        screenWidthDp = dtohs(screenWidthDp);
+        screenHeightDp = dtohs(screenHeightDp);
     }
     
     inline void swapHtoD() {
@@ -1003,6 +1013,8 @@
         screenHeight = htods(screenHeight);
         sdkVersion = htods(sdkVersion);
         minorVersion = htods(minorVersion);
+        screenWidthDp = htods(screenWidthDp);
+        screenHeightDp = htods(screenHeightDp);
     }
     
     inline int compare(const ResTable_config& o) const {
@@ -1021,6 +1033,8 @@
         diff = (int32_t)(screenLayout - o.screenLayout);
         if (diff != 0) return diff;
         diff = (int32_t)(uiMode - o.uiMode);
+        if (diff != 0) return diff;
+        diff = (int32_t)(screenSizeDp - o.screenSizeDp);
         return (int)diff;
     }
     
@@ -1061,6 +1075,7 @@
         if (version != o.version) diffs |= CONFIG_VERSION;
         if (screenLayout != o.screenLayout) diffs |= CONFIG_SCREEN_LAYOUT;
         if (uiMode != o.uiMode) diffs |= CONFIG_UI_MODE;
+        if (screenSizeDp != o.screenSizeDp) diffs |= CONFIG_SCREEN_SIZE;
         return diffs;
     }
     
@@ -1105,6 +1120,18 @@
             }
         }
 
+        if (screenSizeDp || o.screenSizeDp) {
+            if (screenWidthDp != o.screenWidthDp) {
+                if (!screenWidthDp) return false;
+                if (!o.screenWidthDp) return true;
+            }
+
+            if (screenHeightDp != o.screenHeightDp) {
+                if (!screenHeightDp) return false;
+                if (!o.screenHeightDp) return true;
+            }
+        }
+
         if (orientation != o.orientation) {
             if (!orientation) return false;
             if (!o.orientation) return true;
@@ -1243,6 +1270,30 @@
                 }
             }
 
+            if (screenSizeDp || o.screenSizeDp) {
+                // Better is based on the sum of the difference between both
+                // width and height from the requested dimensions.  We are
+                // assuming the invalid configs (with smaller dimens) have
+                // already been filtered.  Note that if a particular dimension
+                // is unspecified, we will end up with a large value (the
+                // difference between 0 and the requested dimension), which is
+                // good since we will prefer a config that has specified a
+                // dimension value.
+                int myDelta = 0, otherDelta = 0;
+                if (requested->screenWidthDp) {
+                    myDelta += requested->screenWidthDp - screenWidthDp;
+                    otherDelta += requested->screenWidthDp - o.screenWidthDp;
+                }
+                if (requested->screenHeightDp) {
+                    myDelta += requested->screenHeightDp - screenHeightDp;
+                    otherDelta += requested->screenHeightDp - o.screenHeightDp;
+                }
+                //LOGI("Comparing this %dx%d to other %dx%d in %dx%d: myDelta=%d otherDelta=%d",
+                //    screenWidthDp, screenHeightDp, o.screenWidthDp, o.screenHeightDp,
+                //    requested->screenWidthDp, requested->screenHeightDp, myDelta, otherDelta);
+                return (myDelta <= otherDelta);
+            }
+
             if ((orientation != o.orientation) && requested->orientation) {
                 return (orientation);
             }
@@ -1426,6 +1477,18 @@
                 return false;
             }
         }
+        if (screenSizeDp != 0) {
+            if (settings.screenWidthDp != 0 && screenWidthDp != 0
+                && screenWidthDp > settings.screenWidthDp) {
+                //LOGI("Filtering out width %d in requested %d", screenWidthDp, settings.screenWidthDp);
+                return false;
+            }
+            if (settings.screenHeightDp != 0 && screenHeightDp != 0
+                && screenHeightDp > settings.screenHeightDp) {
+                //LOGI("Filtering out height %d in requested %d", screenHeightDp, settings.screenHeightDp);
+                return false;
+            }
+        }
         if (screenType != 0) {
             if (settings.orientation != 0 && orientation != 0
                 && orientation != settings.orientation) {
@@ -1505,13 +1568,13 @@
     String8 toString() const {
         char buf[200];
         sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=%d touch=%d dens=%d "
-                "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d sz=%d long=%d "
+                "kbd=%d nav=%d input=%d ssz=%dx%d %ddp x %ddp sz=%d long=%d "
                 "ui=%d night=%d vers=%d.%d",
                 mcc, mnc,
                 language[0] ? language[0] : '-', language[1] ? language[1] : '-',
                 country[0] ? country[0] : '-', country[1] ? country[1] : '-',
                 orientation, touchscreen, density, keyboard, navigation, inputFlags,
-                screenWidth, screenHeight,
+                screenWidth, screenHeight, screenWidthDp, screenHeightDp,
                 screenLayout&MASK_SCREENSIZE, screenLayout&MASK_SCREENLONG,
                 uiMode&MASK_UI_MODE_TYPE, uiMode&MASK_UI_MODE_NIGHT,
                 sdkVersion, minorVersion);
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 0dfbf01..44d9b4b 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -502,8 +502,8 @@
     return NO_ERROR;
 }
 
-sp<ISurface> Surface::getISurface() const {
-    return mSurface;
+sp<IBinder> Surface::asBinder() const {
+    return mSurface!=0 ? mSurface->asBinder() : 0;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 9100693..3362c7d 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -116,7 +116,9 @@
 	rsType.cpp \
 	rsVertexArray.cpp \
 	driver/rsdBcc.cpp \
-	driver/rsdCore.cpp
+	driver/rsdCore.cpp \
+	driver/rsdProgramRaster.cpp \
+	driver/rsdProgramStore.cpp
 
 
 LOCAL_SHARED_LIBRARIES += libz libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc
diff --git a/libs/rs/driver/rsdBcc.h b/libs/rs/driver/rsdBcc.h
index 6723a36..ae7a7af 100644
--- a/libs/rs/driver/rsdBcc.h
+++ b/libs/rs/driver/rsdBcc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2011 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.
diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp
index 6546110..00d62ba 100644
--- a/libs/rs/driver/rsdCore.cpp
+++ b/libs/rs/driver/rsdCore.cpp
@@ -16,6 +16,8 @@
 
 #include "rsdCore.h"
 #include "rsdBcc.h"
+#include "rsdProgramStore.h"
+#include "rsdProgramRaster.h"
 
 #include <malloc.h>
 #include "rsContext.h"
@@ -48,7 +50,21 @@
         rsdScriptSetGlobalBind,
         rsdScriptSetGlobalObj,
         rsdScriptDestroy
+    },
+
+
+    {
+        rsdProgramStoreInit,
+        rsdProgramStoreSetActive,
+        rsdProgramStoreDestroy
+    },
+
+    {
+        rsdProgramRasterInit,
+        rsdProgramRasterSetActive,
+        rsdProgramRasterDestroy
     }
+
 };
 
 
diff --git a/libs/rs/driver/rsdProgramRaster.cpp b/libs/rs/driver/rsdProgramRaster.cpp
new file mode 100644
index 0000000..65995be
--- /dev/null
+++ b/libs/rs/driver/rsdProgramRaster.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+
+#include "rsdCore.h"
+#include "rsdProgramStore.h"
+
+#include "rsContext.h"
+#include "rsProgramStore.h"
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+
+using namespace android;
+using namespace android::renderscript;
+
+bool rsdProgramRasterInit(const Context *, const ProgramRaster *) {
+    return true;
+}
+
+void rsdProgramRasterSetActive(const Context *, const ProgramRaster *pr) {
+    switch (pr->mHal.state.cull) {
+        case RS_CULL_BACK:
+            glEnable(GL_CULL_FACE);
+            glCullFace(GL_BACK);
+            break;
+        case RS_CULL_FRONT:
+            glEnable(GL_CULL_FACE);
+            glCullFace(GL_FRONT);
+            break;
+        case RS_CULL_NONE:
+            glDisable(GL_CULL_FACE);
+            break;
+    }
+
+}
+
+void rsdProgramRasterDestroy(const Context *, const ProgramRaster *) {
+}
+
+
diff --git a/libs/rs/driver/rsdProgramRaster.h b/libs/rs/driver/rsdProgramRaster.h
new file mode 100644
index 0000000..20adaad
--- /dev/null
+++ b/libs/rs/driver/rsdProgramRaster.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#ifndef RSD_PROGRAM_RASTER_H
+#define RSD_PROGRAM_RASTER_H
+
+#include <rs_hal.h>
+
+
+bool rsdProgramRasterInit(const android::renderscript::Context *rsc,
+                         const android::renderscript::ProgramRaster *);
+void rsdProgramRasterSetActive(const android::renderscript::Context *rsc,
+                              const android::renderscript::ProgramRaster *);
+void rsdProgramRasterDestroy(const android::renderscript::Context *rsc,
+                            const android::renderscript::ProgramRaster *);
+
+
+#endif
diff --git a/libs/rs/driver/rsdProgramStore.cpp b/libs/rs/driver/rsdProgramStore.cpp
new file mode 100644
index 0000000..e591453
--- /dev/null
+++ b/libs/rs/driver/rsdProgramStore.cpp
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+
+#include "rsdCore.h"
+#include "rsdProgramStore.h"
+
+#include "rsContext.h"
+#include "rsProgramStore.h"
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+
+using namespace android;
+using namespace android::renderscript;
+
+struct DrvProgramStore {
+    GLenum blendSrc;
+    GLenum blendDst;
+    bool blendEnable;
+
+    GLenum depthFunc;
+    bool depthTestEnable;
+};
+
+bool rsdProgramStoreInit(const Context *rsc, const ProgramStore *ps) {
+    DrvProgramStore *drv = (DrvProgramStore *)calloc(1, sizeof(DrvProgramStore));
+    if (drv == NULL) {
+        return false;
+    }
+
+    ps->mHal.drv = drv;
+    drv->depthTestEnable = true;
+
+    switch (ps->mHal.state.depthFunc) {
+    case RS_DEPTH_FUNC_ALWAYS:
+        drv->depthTestEnable = false;
+        drv->depthFunc = GL_ALWAYS;
+        break;
+    case RS_DEPTH_FUNC_LESS:
+        drv->depthFunc = GL_LESS;
+        break;
+    case RS_DEPTH_FUNC_LEQUAL:
+        drv->depthFunc = GL_LEQUAL;
+        break;
+    case RS_DEPTH_FUNC_GREATER:
+        drv->depthFunc = GL_GREATER;
+        break;
+    case RS_DEPTH_FUNC_GEQUAL:
+        drv->depthFunc = GL_GEQUAL;
+        break;
+    case RS_DEPTH_FUNC_EQUAL:
+        drv->depthFunc = GL_EQUAL;
+        break;
+    case RS_DEPTH_FUNC_NOTEQUAL:
+        drv->depthFunc = GL_NOTEQUAL;
+        break;
+    default:
+        LOGE("Unknown depth function.");
+        goto error;
+    }
+
+
+
+    drv->blendEnable = true;
+    if ((ps->mHal.state.blendSrc == RS_BLEND_SRC_ONE) &&
+        (ps->mHal.state.blendDst == RS_BLEND_DST_ZERO)) {
+        drv->blendEnable = false;
+    }
+
+    switch (ps->mHal.state.blendSrc) {
+    case RS_BLEND_SRC_ZERO:
+        drv->blendSrc = GL_ZERO;
+        break;
+    case RS_BLEND_SRC_ONE:
+        drv->blendSrc = GL_ONE;
+        break;
+    case RS_BLEND_SRC_DST_COLOR:
+        drv->blendSrc = GL_DST_COLOR;
+        break;
+    case RS_BLEND_SRC_ONE_MINUS_DST_COLOR:
+        drv->blendSrc = GL_ONE_MINUS_DST_COLOR;
+        break;
+    case RS_BLEND_SRC_SRC_ALPHA:
+        drv->blendSrc = GL_SRC_ALPHA;
+        break;
+    case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA:
+        drv->blendSrc = GL_ONE_MINUS_SRC_ALPHA;
+        break;
+    case RS_BLEND_SRC_DST_ALPHA:
+        drv->blendSrc = GL_DST_ALPHA;
+        break;
+    case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA:
+        drv->blendSrc = GL_ONE_MINUS_DST_ALPHA;
+        break;
+    case RS_BLEND_SRC_SRC_ALPHA_SATURATE:
+        drv->blendSrc = GL_SRC_ALPHA_SATURATE;
+        break;
+    default:
+        LOGE("Unknown blend src mode.");
+        goto error;
+    }
+
+    switch (ps->mHal.state.blendDst) {
+    case RS_BLEND_DST_ZERO:
+        drv->blendDst = GL_ZERO;
+        break;
+    case RS_BLEND_DST_ONE:
+        drv->blendDst = GL_ONE;
+        break;
+    case RS_BLEND_DST_SRC_COLOR:
+        drv->blendDst = GL_SRC_COLOR;
+        break;
+    case RS_BLEND_DST_ONE_MINUS_SRC_COLOR:
+        drv->blendDst = GL_ONE_MINUS_SRC_COLOR;
+        break;
+    case RS_BLEND_DST_SRC_ALPHA:
+        drv->blendDst = GL_SRC_ALPHA;
+        break;
+    case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA:
+        drv->blendDst = GL_ONE_MINUS_SRC_ALPHA;
+        break;
+    case RS_BLEND_DST_DST_ALPHA:
+        drv->blendDst = GL_DST_ALPHA;
+        break;
+    case RS_BLEND_DST_ONE_MINUS_DST_ALPHA:
+        drv->blendDst = GL_ONE_MINUS_DST_ALPHA;
+        break;
+    default:
+        LOGE("Unknown blend dst mode.");
+        goto error;
+    }
+
+    return true;
+
+error:
+    free(drv);
+    ps->mHal.drv = NULL;
+    return false;
+}
+
+void rsdProgramStoreSetActive(const Context *rsc, const ProgramStore *ps) {
+    DrvProgramStore *drv = (DrvProgramStore *)ps->mHal.drv;
+
+    glColorMask(ps->mHal.state.colorRWriteEnable,
+                ps->mHal.state.colorGWriteEnable,
+                ps->mHal.state.colorBWriteEnable,
+                ps->mHal.state.colorAWriteEnable);
+
+    if (drv->blendEnable) {
+        glEnable(GL_BLEND);
+        glBlendFunc(drv->blendSrc, drv->blendDst);
+    } else {
+        glDisable(GL_BLEND);
+    }
+
+    if (rsc->mUserSurfaceConfig.depthMin > 0) {
+        glDepthMask(ps->mHal.state.depthWriteEnable);
+        if (drv->depthTestEnable || ps->mHal.state.depthWriteEnable) {
+            glEnable(GL_DEPTH_TEST);
+            glDepthFunc(drv->depthFunc);
+        } else {
+            glDisable(GL_DEPTH_TEST);
+        }
+    } else {
+        glDepthMask(false);
+        glDisable(GL_DEPTH_TEST);
+    }
+
+    /*
+    if (rsc->mUserSurfaceConfig.stencilMin > 0) {
+    } else {
+        glStencilMask(0);
+        glDisable(GL_STENCIL_TEST);
+    }
+    */
+
+    if (ps->mHal.state.ditherEnable) {
+        glEnable(GL_DITHER);
+    } else {
+        glDisable(GL_DITHER);
+    }
+}
+
+void rsdProgramStoreDestroy(const Context *rsc, const ProgramStore *ps) {
+    free(ps->mHal.drv);
+    ps->mHal.drv = NULL;
+}
+
+
diff --git a/libs/rs/driver/rsdProgramStore.h b/libs/rs/driver/rsdProgramStore.h
new file mode 100644
index 0000000..217a0ce
--- /dev/null
+++ b/libs/rs/driver/rsdProgramStore.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#ifndef RSD_PROGRAM_STORE_H
+#define RSD_PROGRAM_STORE_H
+
+#include <rs_hal.h>
+
+
+bool rsdProgramStoreInit(const android::renderscript::Context *rsc,
+                         const android::renderscript::ProgramStore *ps);
+void rsdProgramStoreSetActive(const android::renderscript::Context *rsc,
+                              const android::renderscript::ProgramStore *ps);
+void rsdProgramStoreDestroy(const android::renderscript::Context *rsc,
+                            const android::renderscript::ProgramStore *ps);
+
+
+#endif
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index bbb6200..a7f473c 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -251,36 +251,16 @@
 	}
 
 
-ProgramStoreBegin {
-	param RsElement in
-	param RsElement out
-	}
-
-ProgramStoreColorMask {
-	param bool r
-	param bool g
-	param bool b
-	param bool a
-	}
-
-ProgramStoreBlendFunc {
+ProgramStoreCreate {
+	param bool colorMaskR
+	param bool colorMaskG
+	param bool colorMaskB
+	param bool colorMaskA
+        param bool depthMask
+        param bool ditherEnable
 	param RsBlendSrcFunc srcFunc
 	param RsBlendDstFunc destFunc
-	}
-
-ProgramStoreDepthMask {
-	param bool enable
-}
-
-ProgramStoreDither {
-	param bool enable
-}
-
-ProgramStoreDepthFunc {
-	param RsDepthFunc func
-}
-
-ProgramStoreCreate {
+        param RsDepthFunc depthFunc
 	ret RsProgramStore
 	}
 
@@ -288,19 +268,11 @@
 	param bool pointSmooth
 	param bool lineSmooth
 	param bool pointSprite
+	param float lineWidth
+	param RsCullMode cull
 	ret RsProgramRaster
 }
 
-ProgramRasterSetLineWidth {
-	param RsProgramRaster pr
-	param float lw
-}
-
-ProgramRasterSetCullMode {
-	param RsProgramRaster pr
-	param RsCullMode mode
-}
-
 ProgramBindConstants {
 	param RsProgram vp
 	param uint32_t slot
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index d727ba1..c9a7060 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -405,16 +405,16 @@
         return false;
     }
 
-    mFragmentStore->setupGL2(this, &mStateFragmentStore);
+    mFragmentStore->setup(this, &mStateFragmentStore);
     mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
-    mRaster->setupGL2(this, &mStateRaster);
+    mRaster->setup(this, &mStateRaster);
     mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
     mFBOCache.setupGL2(this);
     return true;
 }
 
 void Context::setupProgramStore() {
-    mFragmentStore->setupGL2(this, &mStateFragmentStore);
+    mFragmentStore->setup(this, &mStateFragmentStore);
 }
 
 static bool getProp(const char *str) {
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index 595c89a..c30b857 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -507,12 +507,13 @@
     mFontSampler.set(sampler);
     mFontShaderF->bindSampler(mRSC, 0, sampler);
 
-    ProgramStore *fontStore = new ProgramStore(mRSC);
+    ProgramStore *fontStore = new ProgramStore(mRSC, true, true, true, true,
+                                               false, false,
+                                               RS_BLEND_SRC_SRC_ALPHA,
+                                               RS_BLEND_DST_ONE_MINUS_SRC_ALPHA,
+                                               RS_DEPTH_FUNC_ALWAYS);
     mFontProgramStore.set(fontStore);
-    mFontProgramStore->setDepthFunc(RS_DEPTH_FUNC_ALWAYS);
-    mFontProgramStore->setBlendFunc(RS_BLEND_SRC_SRC_ALPHA, RS_BLEND_DST_ONE_MINUS_SRC_ALPHA);
-    mFontProgramStore->setDitherEnable(false);
-    mFontProgramStore->setDepthMask(false);
+    mFontProgramStore->init();
 }
 
 void FontState::initTextTexture() {
diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp
index ace1572..9617c4d 100644
--- a/libs/rs/rsProgramRaster.cpp
+++ b/libs/rs/rsProgramRaster.cpp
@@ -15,11 +15,6 @@
  */
 
 #include "rsContext.h"
-#ifndef ANDROID_RS_SERIALIZE
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#endif //ANDROID_RS_SERIALIZE
-
 #include "rsProgramRaster.h"
 
 using namespace android;
@@ -27,49 +22,33 @@
 
 
 ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth,
-                             bool lineSmooth, bool pointSprite)
+                             bool lineSmooth, bool pointSprite,
+                             float lineWidth, RsCullMode cull)
     : Program(rsc) {
 
-    mPointSmooth = pointSmooth;
-    mLineSmooth = lineSmooth;
-    mPointSprite = pointSprite;
-    mLineWidth = 1.0f;
-    mCull = RS_CULL_BACK;
+    memset(&mHal, 0, sizeof(mHal));
+
+    mHal.state.pointSmooth = pointSmooth;
+    mHal.state.lineSmooth = lineSmooth;
+    mHal.state.pointSprite = pointSprite;
+    mHal.state.lineWidth = lineWidth;
+    mHal.state.cull = cull;
+
+    rsc->mHal.funcs.raster.init(rsc, this);
 }
 
 ProgramRaster::~ProgramRaster() {
+    mRSC->mHal.funcs.raster.destroy(mRSC, this);
 }
 
-void ProgramRaster::setLineWidth(float s) {
-    mLineWidth = s;
-    mDirty = true;
-}
-
-void ProgramRaster::setCullMode(RsCullMode mode) {
-    mCull = mode;
-    mDirty = true;
-}
-
-void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) {
+void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) {
     if (state->mLast.get() == this && !mDirty) {
         return;
     }
     state->mLast.set(this);
     mDirty = false;
 
-    switch (mCull) {
-        case RS_CULL_BACK:
-            glEnable(GL_CULL_FACE);
-            glCullFace(GL_BACK);
-            break;
-        case RS_CULL_FRONT:
-            glEnable(GL_CULL_FACE);
-            glCullFace(GL_FRONT);
-            break;
-        case RS_CULL_NONE:
-            glDisable(GL_CULL_FACE);
-            break;
-    }
+    rsc->mHal.funcs.raster.setActive(rsc, this);
 }
 
 void ProgramRaster::serialize(OStream *stream) const {
@@ -86,7 +65,7 @@
 }
 
 void ProgramRasterState::init(Context *rsc) {
-    ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
+    ProgramRaster *pr = new ProgramRaster(rsc, false, false, false, 1.f, RS_CULL_BACK);
     mDefault.set(pr);
 }
 
@@ -101,27 +80,15 @@
 RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
                                       bool pointSmooth,
                                       bool lineSmooth,
-                                      bool pointSprite) {
+                                      bool pointSprite,
+                                      float lineWidth,
+                                      RsCullMode cull) {
     ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth,
-                                          lineSmooth, pointSprite);
+                                          lineSmooth, pointSprite, lineWidth, cull);
     pr->incUserRef();
     return pr;
 }
 
-void rsi_ProgramRasterSetLineWidth(Context * rsc,
-                                   RsProgramRaster vpr,
-                                   float s) {
-    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
-    pr->setLineWidth(s);
-}
-
-void rsi_ProgramRasterSetCullMode(Context * rsc,
-                                  RsProgramRaster vpr,
-                                  RsCullMode mode) {
-    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
-    pr->setCullMode(mode);
-}
-
 }
 }
 
diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h
index 7958af9..045a7c1 100644
--- a/libs/rs/rsProgramRaster.h
+++ b/libs/rs/rsProgramRaster.h
@@ -30,23 +30,31 @@
     ProgramRaster(Context *rsc,
                   bool pointSmooth,
                   bool lineSmooth,
-                  bool pointSprite);
+                  bool pointSprite,
+                  float lineWidth,
+                  RsCullMode cull);
     virtual ~ProgramRaster();
 
-    virtual void setupGL2(const Context *, ProgramRasterState *);
+    virtual void setup(const Context *, ProgramRasterState *);
     virtual void serialize(OStream *stream) const;
     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; }
     static ProgramRaster *createFromStream(Context *rsc, IStream *stream);
 
-    void setLineWidth(float w);
-    void setCullMode(RsCullMode mode);
+    struct Hal {
+        mutable void *drv;
+
+        struct State {
+            bool pointSmooth;
+            bool lineSmooth;
+            bool pointSprite;
+            float lineWidth;
+            RsCullMode cull;
+        };
+        State state;
+    };
+    Hal mHal;
 
 protected:
-    bool mPointSmooth;
-    bool mLineSmooth;
-    bool mPointSprite;
-    float mLineWidth;
-    RsCullMode mCull;
 };
 
 class ProgramRasterState {
diff --git a/libs/rs/rsProgramStore.cpp b/libs/rs/rsProgramStore.cpp
index 09b759d..2ad65e9 100644
--- a/libs/rs/rsProgramStore.cpp
+++ b/libs/rs/rsProgramStore.cpp
@@ -15,82 +15,43 @@
  */
 
 #include "rsContext.h"
-#ifndef ANDROID_RS_SERIALIZE
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#endif //ANDROID_RS_SERIALIZE
-
 #include "rsProgramStore.h"
 
 using namespace android;
 using namespace android::renderscript;
 
 
-ProgramStore::ProgramStore(Context *rsc) : Program(rsc) {
-    mDitherEnable = true;
-    mBlendEnable = false;
-    mColorRWriteEnable = true;
-    mColorGWriteEnable = true;
-    mColorBWriteEnable = true;
-    mColorAWriteEnable = true;
-    mBlendSrc = GL_ONE;
-    mBlendDst = GL_ZERO;
+ProgramStore::ProgramStore(Context *rsc,
+                           bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
+                           bool depthMask, bool ditherEnable,
+                           RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
+                           RsDepthFunc depthFunc) : Program(rsc) {
+    memset(&mHal, 0, sizeof(mHal));
 
-    mDepthTestEnable = false;
-    mDepthWriteEnable = true;
-    mDepthFunc = GL_LESS;
+    mHal.state.ditherEnable = ditherEnable;
+
+    mHal.state.colorRWriteEnable = colorMaskR;
+    mHal.state.colorGWriteEnable = colorMaskG;
+    mHal.state.colorBWriteEnable = colorMaskB;
+    mHal.state.colorAWriteEnable = colorMaskA;
+    mHal.state.blendSrc = srcFunc;
+    mHal.state.blendDst = destFunc;
+
+    mHal.state.depthWriteEnable = depthMask;
+    mHal.state.depthFunc = depthFunc;
 }
 
 ProgramStore::~ProgramStore() {
+    mRSC->mHal.funcs.store.destroy(mRSC, this);
 }
 
-void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) {
+void ProgramStore::setup(const Context *rsc, ProgramStoreState *state) {
     if (state->mLast.get() == this) {
         return;
     }
     state->mLast.set(this);
 
-    glColorMask(mColorRWriteEnable,
-                mColorGWriteEnable,
-                mColorBWriteEnable,
-                mColorAWriteEnable);
-    if (mBlendEnable) {
-        glEnable(GL_BLEND);
-        glBlendFunc(mBlendSrc, mBlendDst);
-    } else {
-        glDisable(GL_BLEND);
-    }
-
-    //LOGE("pfs  %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc);
-
-    if (rsc->mUserSurfaceConfig.depthMin > 0) {
-        glDepthMask(mDepthWriteEnable);
-        if (mDepthTestEnable || mDepthWriteEnable) {
-            glEnable(GL_DEPTH_TEST);
-            glDepthFunc(mDepthFunc);
-        } else {
-            glDisable(GL_DEPTH_TEST);
-        }
-    } else {
-        glDepthMask(false);
-        glDisable(GL_DEPTH_TEST);
-    }
-
-    if (rsc->mUserSurfaceConfig.stencilMin > 0) {
-    } else {
-        glStencilMask(0);
-        glDisable(GL_STENCIL_TEST);
-    }
-
-    if (mDitherEnable) {
-        glEnable(GL_DITHER);
-    } else {
-        glDisable(GL_DITHER);
-    }
-}
-
-void ProgramStore::setDitherEnable(bool enable) {
-    mDitherEnable = enable;
+    rsc->mHal.funcs.store.setActive(rsc, this);
 }
 
 void ProgramStore::serialize(OStream *stream) const {
@@ -100,123 +61,24 @@
     return NULL;
 }
 
-void ProgramStore::setDepthFunc(RsDepthFunc func) {
-    mDepthTestEnable = true;
-
-    switch (func) {
-    case RS_DEPTH_FUNC_ALWAYS:
-        mDepthTestEnable = false;
-        mDepthFunc = GL_ALWAYS;
-        break;
-    case RS_DEPTH_FUNC_LESS:
-        mDepthFunc = GL_LESS;
-        break;
-    case RS_DEPTH_FUNC_LEQUAL:
-        mDepthFunc = GL_LEQUAL;
-        break;
-    case RS_DEPTH_FUNC_GREATER:
-        mDepthFunc = GL_GREATER;
-        break;
-    case RS_DEPTH_FUNC_GEQUAL:
-        mDepthFunc = GL_GEQUAL;
-        break;
-    case RS_DEPTH_FUNC_EQUAL:
-        mDepthFunc = GL_EQUAL;
-        break;
-    case RS_DEPTH_FUNC_NOTEQUAL:
-        mDepthFunc = GL_NOTEQUAL;
-        break;
-    }
-}
-
-void ProgramStore::setDepthMask(bool mask) {
-    mDepthWriteEnable = mask;
-}
-
-void ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst) {
-    mBlendEnable = true;
-    if ((src == RS_BLEND_SRC_ONE) &&
-        (dst == RS_BLEND_DST_ZERO)) {
-        mBlendEnable = false;
-    }
-
-    switch (src) {
-    case RS_BLEND_SRC_ZERO:
-        mBlendSrc = GL_ZERO;
-        break;
-    case RS_BLEND_SRC_ONE:
-        mBlendSrc = GL_ONE;
-        break;
-    case RS_BLEND_SRC_DST_COLOR:
-        mBlendSrc = GL_DST_COLOR;
-        break;
-    case RS_BLEND_SRC_ONE_MINUS_DST_COLOR:
-        mBlendSrc = GL_ONE_MINUS_DST_COLOR;
-        break;
-    case RS_BLEND_SRC_SRC_ALPHA:
-        mBlendSrc = GL_SRC_ALPHA;
-        break;
-    case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA:
-        mBlendSrc = GL_ONE_MINUS_SRC_ALPHA;
-        break;
-    case RS_BLEND_SRC_DST_ALPHA:
-        mBlendSrc = GL_DST_ALPHA;
-        break;
-    case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA:
-        mBlendSrc = GL_ONE_MINUS_DST_ALPHA;
-        break;
-    case RS_BLEND_SRC_SRC_ALPHA_SATURATE:
-        mBlendSrc = GL_SRC_ALPHA_SATURATE;
-        break;
-    }
-
-    switch (dst) {
-    case RS_BLEND_DST_ZERO:
-        mBlendDst = GL_ZERO;
-        break;
-    case RS_BLEND_DST_ONE:
-        mBlendDst = GL_ONE;
-        break;
-    case RS_BLEND_DST_SRC_COLOR:
-        mBlendDst = GL_SRC_COLOR;
-        break;
-    case RS_BLEND_DST_ONE_MINUS_SRC_COLOR:
-        mBlendDst = GL_ONE_MINUS_SRC_COLOR;
-        break;
-    case RS_BLEND_DST_SRC_ALPHA:
-        mBlendDst = GL_SRC_ALPHA;
-        break;
-    case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA:
-        mBlendDst = GL_ONE_MINUS_SRC_ALPHA;
-        break;
-    case RS_BLEND_DST_DST_ALPHA:
-        mBlendDst = GL_DST_ALPHA;
-        break;
-    case RS_BLEND_DST_ONE_MINUS_DST_ALPHA:
-        mBlendDst = GL_ONE_MINUS_DST_ALPHA;
-        break;
-    }
-}
-
-void ProgramStore::setColorMask(bool r, bool g, bool b, bool a) {
-    mColorRWriteEnable = r;
-    mColorGWriteEnable = g;
-    mColorBWriteEnable = b;
-    mColorAWriteEnable = a;
+void ProgramStore::init() {
+    mRSC->mHal.funcs.store.init(mRSC, this);
 }
 
 ProgramStoreState::ProgramStoreState() {
-    mPFS = NULL;
 }
 
 ProgramStoreState::~ProgramStoreState() {
-    ObjectBase::checkDelete(mPFS);
-    mPFS = NULL;
 }
 
 void ProgramStoreState::init(Context *rsc) {
-    ProgramStore *pfs = new ProgramStore(rsc);
-    mDefault.set(pfs);
+    ProgramStore *ps = new ProgramStore(rsc,
+                                        true, true, true, true,
+                                        true, true,
+                                        RS_BLEND_SRC_ONE, RS_BLEND_DST_ZERO,
+                                        RS_DEPTH_FUNC_LESS);
+    ps->init();
+    mDefault.set(ps);
 }
 
 void ProgramStoreState::deinit(Context *rsc) {
@@ -224,40 +86,24 @@
     mLast.clear();
 }
 
+
 namespace android {
 namespace renderscript {
 
-void rsi_ProgramStoreBegin(Context * rsc, RsElement in, RsElement out) {
-    ObjectBase::checkDelete(rsc->mStateFragmentStore.mPFS);
-    rsc->mStateFragmentStore.mPFS = new ProgramStore(rsc);
-}
+RsProgramStore rsi_ProgramStoreCreate(Context *rsc,
+                                      bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
+                                      bool depthMask, bool ditherEnable,
+                                      RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
+                                      RsDepthFunc depthFunc) {
 
-void rsi_ProgramStoreDepthFunc(Context *rsc, RsDepthFunc func) {
-    rsc->mStateFragmentStore.mPFS->setDepthFunc(func);
-}
-
-void rsi_ProgramStoreDepthMask(Context *rsc, bool mask) {
-    rsc->mStateFragmentStore.mPFS->setDepthMask(mask);
-}
-
-void rsi_ProgramStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a) {
-    rsc->mStateFragmentStore.mPFS->setColorMask(r, g, b, a);
-}
-
-void rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst) {
-    rsc->mStateFragmentStore.mPFS->setBlendFunc(src, dst);
-}
-
-RsProgramStore rsi_ProgramStoreCreate(Context *rsc) {
-    ProgramStore *pfs = rsc->mStateFragmentStore.mPFS;
+    ProgramStore *pfs = new ProgramStore(rsc,
+                                         colorMaskR, colorMaskG, colorMaskB, colorMaskA,
+                                         depthMask, ditherEnable,
+                                         srcFunc, destFunc, depthFunc);
+    pfs->init();
     pfs->incUserRef();
-    rsc->mStateFragmentStore.mPFS = 0;
     return pfs;
 }
 
-void rsi_ProgramStoreDither(Context *rsc, bool enable) {
-    rsc->mStateFragmentStore.mPFS->setDitherEnable(enable);
-}
-
 }
 }
diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h
index f8eb7cf..bfe276d 100644
--- a/libs/rs/rsProgramStore.h
+++ b/libs/rs/rsProgramStore.h
@@ -28,39 +28,46 @@
 
 class ProgramStore : public Program {
 public:
-    ProgramStore(Context *);
+    ProgramStore(Context *,
+                 bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
+                 bool depthMask, bool ditherEnable,
+                 RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
+                 RsDepthFunc depthFunc);
     virtual ~ProgramStore();
 
-    virtual void setupGL2(const Context *, ProgramStoreState *);
-
-    void setDepthFunc(RsDepthFunc);
-    void setDepthMask(bool);
-
-    void setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst);
-    void setColorMask(bool, bool, bool, bool);
-
-    void setDitherEnable(bool);
+    virtual void setup(const Context *, ProgramStoreState *);
 
     virtual void serialize(OStream *stream) const;
     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; }
     static ProgramStore *createFromStream(Context *rsc, IStream *stream);
 
+    void init();
+
+    struct Hal {
+        mutable void *drv;
+
+        struct State {
+            bool ditherEnable;
+
+            //bool blendEnable;
+            bool colorRWriteEnable;
+            bool colorGWriteEnable;
+            bool colorBWriteEnable;
+            bool colorAWriteEnable;
+            RsBlendSrcFunc blendSrc;
+            RsBlendDstFunc blendDst;
+
+            //bool depthTestEnable;
+            bool depthWriteEnable;
+            RsDepthFunc depthFunc;
+        };
+        State state;
+
+
+    };
+    Hal mHal;
+
 protected:
-    bool mDitherEnable;
-
-    bool mBlendEnable;
-    bool mColorRWriteEnable;
-    bool mColorGWriteEnable;
-    bool mColorBWriteEnable;
-    bool mColorAWriteEnable;
-    int32_t mBlendSrc;
-    int32_t mBlendDst;
-
-    bool mDepthTestEnable;
-    bool mDepthWriteEnable;
-    int32_t mDepthFunc;
-
-    bool mStencilTestEnable;
 };
 
 class ProgramStoreState {
@@ -72,9 +79,6 @@
 
     ObjectBaseRef<ProgramStore> mDefault;
     ObjectBaseRef<ProgramStore> mLast;
-
-
-    ProgramStore *mPFS;
 };
 
 }
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index d5c486b..8e95891 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -185,7 +185,7 @@
 
     //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
 
-    rsc->mHal.funcs.script.scriptInit(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup);
+    rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup);
 
     mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
     mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h
index 17983ce..93d7476 100644
--- a/libs/rs/rs_hal.h
+++ b/libs/rs/rs_hal.h
@@ -29,7 +29,8 @@
 class Allocation;
 class Script;
 class ScriptC;
-
+class ProgramStore;
+class ProgramRaster;
 
 typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
 
@@ -50,13 +51,13 @@
 
 
     struct {
-        bool (*scriptInit)(const Context *rsc, ScriptC *s,
-                           char const *resName,
-                           char const *cacheDir,
-                           uint8_t const *bitcode,
-                           size_t bitcodeSize,
-                           uint32_t flags,
-                           RsHalSymbolLookupFunc lookupFunc);
+        bool (*init)(const Context *rsc, ScriptC *s,
+                     char const *resName,
+                     char const *cacheDir,
+                     uint8_t const *bitcode,
+                     size_t bitcodeSize,
+                     uint32_t flags,
+                     RsHalSymbolLookupFunc lookupFunc);
 
         void (*invokeFunction)(const Context *rsc, Script *s,
                                uint32_t slot,
@@ -87,6 +88,18 @@
     } script;
 
 
+    struct {
+        bool (*init)(const Context *rsc, const ProgramStore *ps);
+        void (*setActive)(const Context *rsc, const ProgramStore *ps);
+        void (*destroy)(const Context *rsc, const ProgramStore *ps);
+    } store;
+
+    struct {
+        bool (*init)(const Context *rsc, const ProgramRaster *ps);
+        void (*setActive)(const Context *rsc, const ProgramRaster *ps);
+        void (*destroy)(const Context *rsc, const ProgramRaster *ps);
+    } raster;
+
 
 } RsdHalFunctions;
 
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index 7197ad7..ac9cdf9 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -2424,7 +2424,7 @@
 {
     mLock.lock();
     TABLE_GETENTRY(LOGI("Setting parameters: imsi:%d/%d lang:%c%c cnt:%c%c "
-                        "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                        "orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                        params->mcc, params->mnc,
                        params->language[0] ? params->language[0] : '-',
                        params->language[1] ? params->language[1] : '-',
@@ -2437,7 +2437,9 @@
                        params->inputFlags,
                        params->navigation,
                        params->screenWidth,
-                       params->screenHeight));
+                       params->screenHeight,
+                       params->screenWidthDp,
+                       params->screenHeightDp));
     mParams = *params;
     for (size_t i=0; i<mPackageGroups.size(); i++) {
         TABLE_NOISY(LOGI("CLEARING BAGS FOR GROUP %d!", i));
@@ -3758,8 +3760,10 @@
         ResTable_config thisConfig;
         thisConfig.copyFromDtoH(thisType->config);
 
-        TABLE_GETENTRY(LOGI("Match entry 0x%x in type 0x%x (sz 0x%x): imsi:%d/%d=%d/%d lang:%c%c=%c%c cnt:%c%c=%c%c "
-                            "orien:%d=%d touch:%d=%d density:%d=%d key:%d=%d inp:%d=%d nav:%d=%d w:%d=%d h:%d=%d\n",
+        TABLE_GETENTRY(LOGI("Match entry 0x%x in type 0x%x (sz 0x%x): imsi:%d/%d=%d/%d "
+                            "lang:%c%c=%c%c cnt:%c%c=%c%c orien:%d=%d touch:%d=%d "
+                            "density:%d=%d key:%d=%d inp:%d=%d nav:%d=%d w:%d=%d h:%d=%d "
+                            "wdp:%d=%d hdp:%d=%d\n",
                            entryIndex, typeIndex+1, dtohl(thisType->config.size),
                            thisConfig.mcc, thisConfig.mnc,
                            config ? config->mcc : 0, config ? config->mnc : 0,
@@ -3786,7 +3790,11 @@
                            thisConfig.screenWidth,
                            config ? config->screenWidth : 0,
                            thisConfig.screenHeight,
-                           config ? config->screenHeight : 0));
+                           config ? config->screenHeight : 0,
+                           thisConfig.screenWidthDp,
+                           config ? config->screenWidthDp : 0,
+                           thisConfig.screenHeightDp,
+                           config ? config->screenHeightDp : 0));
         
         // Check to make sure this one is valid for the current parameters.
         if (config && !thisConfig.match(*config)) {
@@ -4067,7 +4075,8 @@
                 ResTable_config thisConfig;
                 thisConfig.copyFromDtoH(type->config);
                 LOGI("Adding config to type %d: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                     "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d "
+                     "wdp:%d hdp:%d\n",
                       type->id,
                       thisConfig.mcc, thisConfig.mnc,
                       thisConfig.language[0] ? thisConfig.language[0] : '-',
@@ -4081,7 +4090,9 @@
                       thisConfig.inputFlags,
                       thisConfig.navigation,
                       thisConfig.screenWidth,
-                      thisConfig.screenHeight));
+                      thisConfig.screenHeight,
+                      thisConfig.screenWidthDp,
+                      thisConfig.screenHeightDp));
             t->configs.add(type);
         } else {
             status_t err = validate_chunk(chunk, sizeof(ResChunk_header),
@@ -4444,6 +4455,12 @@
                     if (type->config.screenHeight != 0) {
                         printf(" h=%d", dtohs(type->config.screenHeight));
                     }
+                    if (type->config.screenWidthDp != 0) {
+                        printf(" wdp=%d", dtohs(type->config.screenWidthDp));
+                    }
+                    if (type->config.screenHeightDp != 0) {
+                        printf(" hdp=%d", dtohs(type->config.screenHeightDp));
+                    }
                     if (type->config.sdkVersion != 0) {
                         printf(" sdk=%d", dtohs(type->config.sdkVersion));
                     }
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index 2492d47..95d93b2 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -64,44 +64,20 @@
     /*
      * Sets the microphone mute on or off.
      *
-     * param on set <var>true</var> to mute the microphone;
+     * @param on set <var>true</var> to mute the microphone;
      *           <var>false</var> to turn mute off
-     * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
+     * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
      */
     public static native int muteMicrophone(boolean on);
 
     /*
      * Checks whether the microphone mute is on or off.
      *
-     * return true if microphone is muted, false if it's not
+     * @return true if microphone is muted, false if it's not
      */
     public static native boolean isMicrophoneMuted();
 
-    /*
-     * Sets the audio mode.
-     *
-     * param mode  the requested audio mode (NORMAL, RINGTONE, or IN_CALL).
-     *              Informs the HAL about the current audio state so that
-     *              it can route the audio appropriately.
-     * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
-     */
-    /** @deprecated use {@link #setPhoneState(int)} */
-    public static int setMode(int mode) {
-        return AUDIO_STATUS_ERROR;
-    }
-    /*
-     * Returns the current audio mode.
-     *
-     * return      the current audio mode (NORMAL, RINGTONE, or IN_CALL).
-     *              Returns the current current audio state from the HAL.
-     *              
-     */
-    /** @deprecated Do not use. */
-    public static int getMode() {
-        return MODE_INVALID;
-    }
-
-    /* modes for setPhoneState */
+    /* modes for setPhoneState, must match AudioSystem.h audio_mode */
     public static final int MODE_INVALID            = -2;
     public static final int MODE_CURRENT            = -1;
     public static final int MODE_NORMAL             = 0;
@@ -111,7 +87,7 @@
     public static final int NUM_MODES               = 4;
 
 
-    /* Routing bits for setRouting/getRouting API */
+    /* Routing bits for the former setRouting/getRouting API */
     /** @deprecated */
     @Deprecated public static final int ROUTE_EARPIECE          = (1 << 0);
     /** @deprecated */
@@ -128,33 +104,6 @@
     @Deprecated public static final int ROUTE_ALL               = 0xFFFFFFFF;
 
     /*
-     * Sets the audio routing for a specified mode
-     *
-     * param mode   audio mode to change route. E.g., MODE_RINGTONE.
-     * param routes bit vector of routes requested, created from one or
-     *               more of ROUTE_xxx types. Set bits indicate that route should be on
-     * param mask   bit vector of routes to change, created from one or more of
-     * ROUTE_xxx types. Unset bits indicate the route should be left unchanged
-     * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
-     */
-    /** @deprecated use {@link #setDeviceConnectionState(int,int,String)} */
-    public static int setRouting(int mode, int routes, int mask) {
-        return AUDIO_STATUS_ERROR;
-    }
-
-    /*
-     * Returns the current audio routing bit vector for a specified mode.
-     *
-     * param mode audio mode to change route (e.g., MODE_RINGTONE)
-     * return an audio route bit vector that can be compared with ROUTE_xxx
-     * bits
-     */
-    /** @deprecated use {@link #getDeviceConnectionState(int,String)} */
-    public static int getRouting(int mode) {
-        return 0;
-    }
-
-    /*
      * Checks whether the specified stream type is active.
      *
      * return true if any track playing on this stream is active.
@@ -163,7 +112,7 @@
 
     /*
      * Sets a group generic audio configuration parameters. The use of these parameters
-     * are platform dependant, see libaudio
+     * are platform dependent, see libaudio
      *
      * param keyValuePairs  list of parameters key value pairs in the form:
      *    key1=value1;key2=value2;...
@@ -172,7 +121,7 @@
 
     /*
      * Gets a group generic audio configuration parameters. The use of these parameters
-     * are platform dependant, see libaudio
+     * are platform dependent, see libaudio
      *
      * param keys  list of parameters
      * return value: list of parameters key value pairs in the form:
@@ -180,15 +129,7 @@
      */
     public static native String getParameters(String keys);
 
-    /*
-    private final static String TAG = "audio";
-
-    private void log(String msg) {
-        Log.d(TAG, "[AudioSystem] " + msg);
-    }
-    */
-
-    // These match the enum in libs/android_runtime/android_media_AudioSystem.cpp
+    // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp
     /* Command sucessful or Media server restarted. see ErrorCallback */
     public static final int AUDIO_STATUS_OK = 0;
     /* Command failed or unspecified audio error.  see ErrorCallback */
@@ -215,7 +156,7 @@
 
     /*
      * Registers a callback to be invoked when an error occurs.
-     * param cb the callback to run
+     * @param cb the callback to run
      */
     public static void setErrorCallback(ErrorCallback cb)
     {
@@ -272,16 +213,17 @@
     public static final int DEVICE_IN_AUX_DIGITAL = 0x800000;
     public static final int DEVICE_IN_DEFAULT = 0x80000000;
 
-    // device states
+    // device states, must match AudioSystem::device_connection_state
     public static final int DEVICE_STATE_UNAVAILABLE = 0;
     public static final int DEVICE_STATE_AVAILABLE = 1;
+    private static final int NUM_DEVICE_STATES = 1;
 
-    // phone state
+    // phone state, match audio_mode???
     public static final int PHONE_STATE_OFFCALL = 0;
     public static final int PHONE_STATE_RINGING = 1;
     public static final int PHONE_STATE_INCALL = 2;
 
-    // config for setForceUse
+    // device categories config for setForceUse, must match AudioSystem::forced_config
     public static final int FORCE_NONE = 0;
     public static final int FORCE_SPEAKER = 1;
     public static final int FORCE_HEADPHONES = 2;
@@ -292,13 +234,15 @@
     public static final int FORCE_BT_DESK_DOCK = 7;
     public static final int FORCE_ANALOG_DOCK = 8;
     public static final int FORCE_DIGITAL_DOCK = 9;
+    private static final int NUM_FORCE_CONFIG = 10;
     public static final int FORCE_DEFAULT = FORCE_NONE;
 
-    // usage for serForceUse
+    // usage for setForceUse, must match AudioSystem::force_use
     public static final int FOR_COMMUNICATION = 0;
     public static final int FOR_MEDIA = 1;
     public static final int FOR_RECORD = 2;
     public static final int FOR_DOCK = 3;
+    private static final int NUM_FORCE_USE = 4;
 
     public static native int setDeviceConnectionState(int device, int state, String device_address);
     public static native int getDeviceConnectionState(int device, String device_address);
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index e2dee00..0b0d145a 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -1462,11 +1462,16 @@
     public interface OnBufferingUpdateListener
     {
         /**
-         * Called to update status in buffering a media stream.
+         * Called to update status in buffering a media stream received through
+         * progressive HTTP download. The received buffering percentage
+         * indicates how much of the content has been buffered or played.
+         * For example a buffering update of 80 percent when half the content
+         * has already been played indicates that the next 30 percent of the
+         * content to play has been buffered.
          *
          * @param mp      the MediaPlayer the update pertains to
-         * @param percent the percentage (0-100) of the buffer
-         *                that has been filled thus far
+         * @param percent the percentage (0-100) of the content
+         *                that has been buffered or played thus far
          */
         void onBufferingUpdate(MediaPlayer mp, int percent);
     }
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 5d9a3c5..27b37b7 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -441,19 +441,20 @@
 {
     jclass clazz = env->FindClass(kClassPathName);
     if (clazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find android/media/MediaMetadataRetriever");
         return;
     }
 
     fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
     if (fields.context == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaMetadataRetriever.mNativeContext");
         return;
     }
 
-    fields.bitmapClazz = env->FindClass("android/graphics/Bitmap");
+    jclass bitmapClazz = env->FindClass("android/graphics/Bitmap");
+    if (bitmapClazz == NULL) {
+        return;
+    }
+    fields.bitmapClazz = (jclass) env->NewGlobalRef(bitmapClazz);
     if (fields.bitmapClazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find android/graphics/Bitmap");
         return;
     }
     fields.createBitmapMethod =
@@ -461,8 +462,6 @@
                     "(IILandroid/graphics/Bitmap$Config;)"
                     "Landroid/graphics/Bitmap;");
     if (fields.createBitmapMethod == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap.createBitmap(int, int, Config)  method");
         return;
     }
     fields.createScaledBitmapMethod =
@@ -470,28 +469,25 @@
                     "(Landroid/graphics/Bitmap;IIZ)"
                     "Landroid/graphics/Bitmap;");
     if (fields.createScaledBitmapMethod == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap.createScaledBitmap(Bitmap, int, int, boolean)  method");
         return;
     }
     fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "I");
     if (fields.nativeBitmap == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap.mNativeBitmap field");
+        return;
     }
 
-    fields.configClazz = env->FindClass("android/graphics/Bitmap$Config");
+    jclass configClazz = env->FindClass("android/graphics/Bitmap$Config");
+    if (configClazz == NULL) {
+        return;
+    }
+    fields.configClazz = (jclass) env->NewGlobalRef(configClazz);
     if (fields.configClazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                               "Can't find Bitmap$Config class");
         return;
     }
     fields.createConfigMethod =
             env->GetStaticMethodID(fields.configClazz, "nativeToConfig",
                     "(I)Landroid/graphics/Bitmap$Config;");
     if (fields.createConfigMethod == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap$Config.nativeToConfig(int)  method");
         return;
     }
 }
diff --git a/media/jni/android_mtp_MtpDatabase.cpp b/media/jni/android_mtp_MtpDatabase.cpp
index 17d39e3..2f88fd1 100644
--- a/media/jni/android_mtp_MtpDatabase.cpp
+++ b/media/jni/android_mtp_MtpDatabase.cpp
@@ -427,6 +427,9 @@
                 jstring stringValue = (jstring)env->GetObjectArrayElement(stringValuesArray, 0);
                 if (stringValue) {
                     const char* str = env->GetStringUTFChars(stringValue, NULL);
+                    if (str == NULL) {
+                        return MTP_RESPONSE_GENERAL_ERROR;
+                    }
                     packet.putString(str);
                     env->ReleaseStringUTFChars(stringValue, str);
                 } else {
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index f5fcb4e..40bbaa3 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -110,6 +110,10 @@
 #ifdef HAVE_ANDROID_OS
     LOGD("open\n");
     const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
+    if (deviceNameStr == NULL) {
+        return false;
+    }
+
     MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
     env->ReleaseStringUTFChars(deviceName, deviceNameStr);
 
@@ -426,12 +430,16 @@
     MtpDevice* device = get_device_from_object(env, thiz);
     if (device) {
         const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
+        if (destPathStr == NULL) {
+            return false;
+        }
+
         bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
         env->ReleaseStringUTFChars(dest_path, destPathStr);
         return result;
     }
 #endif
-    return NULL;
+    return false;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index c55189f..84c2c7e 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -97,7 +97,7 @@
     void removeStorage(MtpStorageID id) {
         MtpStorage* storage = mServer->getStorage(id);
         if (storage) {
-            for (int i = 0; i < mStorageList.size(); i++) {
+            for (size_t i = 0; i < mStorageList.size(); i++) {
                 if (mStorageList[i] == storage) {
                     mStorageList.removeAt(i);
                     break;
@@ -122,7 +122,7 @@
                     (mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));
 
             mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
-            for (int i = 0; i < mStorageList.size(); i++) {
+            for (size_t i = 0; i < mStorageList.size(); i++) {
                 mServer->addStorage(mStorageList[i]);
             }
         } else {
@@ -247,13 +247,17 @@
         jlong reserveSpace = env->GetLongField(jstorage, field_MtpStorage_reserveSpace);
 
         const char *pathStr = env->GetStringUTFChars(path, NULL);
-        const char *descriptionStr = env->GetStringUTFChars(description, NULL);
-
-        MtpStorage* storage = new MtpStorage(storageID, pathStr, descriptionStr, reserveSpace);
-        thread->addStorage(storage);
-
-        env->ReleaseStringUTFChars(path, pathStr);
-        env->ReleaseStringUTFChars(description, descriptionStr);
+        if (pathStr != NULL) {
+            const char *descriptionStr = env->GetStringUTFChars(description, NULL);
+            if (descriptionStr != NULL) {
+                MtpStorage* storage = new MtpStorage(storageID, pathStr, descriptionStr, reserveSpace);
+                thread->addStorage(storage);
+                env->ReleaseStringUTFChars(path, pathStr);
+                env->ReleaseStringUTFChars(description, descriptionStr);
+            } else {
+                env->ReleaseStringUTFChars(path, pathStr);
+            }
+        }
     } else {
         LOGE("MtpThread is null in add_storage");
     }
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index 3401441..a549f51 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -139,7 +139,6 @@
                     showInvalidChargerDialog();
                     return;
                 } else if (oldInvalidCharger != 0 && mInvalidCharger == 0) {
-                    Slog.d(TAG, "closing invalid charger warning");
                     dismissInvalidChargerDialog();
                 } else if (mInvalidChargerDialog != null) {
                     // if invalid charger is showing, don't show low battery
@@ -150,10 +149,9 @@
                         && (bucket < oldBucket || oldPlugged)
                         && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
                         && bucket < 0) {
-                    Slog.d(TAG, "showing low battery warning: level=" + mBatteryLevel);
+                    Slog.i(TAG, "showing low battery warning: level=" + mBatteryLevel);
                     showLowBatteryWarning();
                 } else if (plugged || (bucket > oldBucket && bucket > 0)) {
-                    Slog.d(TAG, "closing low battery warning: level=" + mBatteryLevel);
                     dismissLowBatteryWarning();
                 } else if (mBatteryLevelTextView != null) {
                     showLowBatteryWarning();
@@ -166,6 +164,7 @@
 
     void dismissLowBatteryWarning() {
         if (mLowBatteryDialog != null) {
+            Slog.i(TAG, "closing low battery warning: level=" + mBatteryLevel);
             mLowBatteryDialog.dismiss();
         }
     }
@@ -237,6 +236,7 @@
 
     void dismissInvalidChargerDialog() {
         if (mInvalidChargerDialog != null) {
+            Slog.d(TAG, "closing invalid charger warning");
             mInvalidChargerDialog.dismiss();
         }
     }
diff --git a/packages/TtsService/jni/android_tts_SynthProxy.cpp b/packages/TtsService/jni/android_tts_SynthProxy.cpp
index 27d1fc0..e00fa85 100644
--- a/packages/TtsService/jni/android_tts_SynthProxy.cpp
+++ b/packages/TtsService/jni/android_tts_SynthProxy.cpp
@@ -53,7 +53,6 @@
 // ----------------------------------------------------------------------------
 struct fields_t {
     jfieldID    synthProxyFieldJniData;
-    jclass      synthProxyClass;
     jmethodID   synthProxyMethodPost;
 };
 
@@ -1043,7 +1042,6 @@
         goto bail;
     }
 
-    javaTTSFields.synthProxyClass = clazz;
     javaTTSFields.synthProxyFieldJniData = NULL;
     javaTTSFields.synthProxyMethodPost = NULL;
 
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 44f55b3..768c0cd 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -728,15 +728,11 @@
         mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
                 com.android.internal.R.array.config_safeModeEnabledVibePattern);
 
-        // watch for HDMI plug messages if the hdmi switch exists
-        if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
-            mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
-        }
-        mHdmiPlugged = !readHdmiState();
-        setHdmiPlugged(!mHdmiPlugged);
-
         // Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
         // config_statusBarCanHide because the latter depends on the screen size
+
+        // Controls rotation and the like.
+        initializeHdmiState();
     }
 
     public void updateSettings() {
@@ -2075,31 +2071,37 @@
         }
     }
 
-    boolean readHdmiState() {
-        final String filename = "/sys/class/switch/hdmi/state";
-        FileReader reader = null;
-        try {
-            reader = new FileReader(filename);
-            char[] buf = new char[15];
-            int n = reader.read(buf);
-            if (n > 1) {
-                return 0 != Integer.parseInt(new String(buf, 0, n-1));
-            } else {
-                return false;
-            }
-        } catch (IOException ex) {
-            Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
-            return false;
-        } catch (NumberFormatException ex) {
-            Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
-            return false;
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException ex) {
+    void initializeHdmiState() {
+        // watch for HDMI plug messages if the hdmi switch exists
+        if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
+            mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
+
+            boolean plugged = false;
+            final String filename = "/sys/class/switch/hdmi/state";
+            FileReader reader = null;
+            try {
+                reader = new FileReader(filename);
+                char[] buf = new char[15];
+                int n = reader.read(buf);
+                if (n > 1) {
+                    plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
+                }
+            } catch (IOException ex) {
+                Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
+            } catch (NumberFormatException ex) {
+                Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
+            } finally {
+                if (reader != null) {
+                    try {
+                        reader.close();
+                    } catch (IOException ex) {
+                    }
                 }
             }
+
+            // This dance forces the code in setHdmiPlugged to run.
+            mHdmiPlugged = !plugged;
+            setHdmiPlugged(!mHdmiPlugged);
         }
     }
 
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index e27a10f..04cfa08 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -5704,7 +5704,7 @@
         const uint32_t i = 31 - __builtin_clz(device);
         device &= ~(1 << i);
         if (i >= sizeof(sDeviceConvTable)/sizeof(uint32_t)) {
-            LOGE("device convertion error for AudioSystem device 0x%08x", device);
+            LOGE("device conversion error for AudioSystem device 0x%08x", device);
             return 0;
         }
         deviceOut |= (uint32_t)sDeviceConvTable[i];
diff --git a/services/audioflinger/AudioPolicyManagerBase.cpp b/services/audioflinger/AudioPolicyManagerBase.cpp
index f653dc5..c0ac669 100644
--- a/services/audioflinger/AudioPolicyManagerBase.cpp
+++ b/services/audioflinger/AudioPolicyManagerBase.cpp
@@ -542,7 +542,7 @@
     }
 
 
-    LOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
+    LOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
                 stream, samplingRate, format, channels, flags);
 
     return output;
@@ -2107,7 +2107,7 @@
                                     uint32_t device)
 {
    return ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) ||
-          (format !=0 && !AudioSystem::isLinearPCM(format)));
+          (format != 0 && !AudioSystem::isLinearPCM(format)));
 }
 
 uint32_t AudioPolicyManagerBase::getMaxEffectsCpuLoad()
@@ -2159,7 +2159,7 @@
         return;
     }
     mRefCount[stream] += delta;
-    LOGV("changeRefCount() stream %d, count %d", stream, mRefCount[stream]);
+    LOGV("changeRefCount() delta %d, stream %d, refCount %d", delta, stream, mRefCount[stream]);
 }
 
 uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::refCount()
@@ -2215,7 +2215,8 @@
 
 AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor()
     : mSamplingRate(0), mFormat(0), mChannels(0),
-     mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice(0), mRefCount(0)
+      mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice(0), mRefCount(0),
+      mInputSource(0)
 {
 }
 
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index f3c9959..7e3c643 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -472,15 +472,15 @@
     result = NO_ERROR;
 
     // return if no change in surface.
-    // asBinder() is safe on NULL (returns NULL)
-    if (getISurface(surface)->asBinder() == mSurface) {
+    sp<IBinder> binder(surface != 0 ? surface->asBinder() : 0);
+    if (binder == mSurface) {
         return result;
     }
 
     if (mSurface != 0) {
         LOG1("clearing old preview surface %p", mSurface.get());
     }
-    mSurface = getISurface(surface)->asBinder();
+    mSurface = binder;
     mPreviewWindow = surface;
 
     // If preview has been already started, register preview
@@ -1241,12 +1241,4 @@
     return NO_ERROR;
 }
 
-sp<ISurface> CameraService::getISurface(const sp<Surface>& surface) {
-    if (surface != 0) {
-        return surface->getISurface();
-    } else {
-        return sp<ISurface>(0);
-    }
-}
-
 }; // namespace android
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 28e8cc0..9a9ab0e 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -79,12 +79,6 @@
     sp<MediaPlayer>     mSoundPlayer[NUM_SOUNDS];
     int                 mSoundRef;  // reference count (release all MediaPlayer when 0)
 
-    // Used by Client objects to extract the ISurface from a Surface object.
-    // This is used because making Client a friend class of Surface would
-    // require including this header in Surface.h since Client is a nested
-    // class.
-    static sp<ISurface> getISurface(const sp<Surface>& surface);
-
     class Client : public BnCamera
     {
     public:
diff --git a/services/java/com/android/server/TelephonyRegistry.java b/services/java/com/android/server/TelephonyRegistry.java
index eb14180..948118f 100644
--- a/services/java/com/android/server/TelephonyRegistry.java
+++ b/services/java/com/android/server/TelephonyRegistry.java
@@ -279,7 +279,6 @@
         if (!checkNotifyPermission("notifyServiceState()")){
             return;
         }
-        Slog.i(TAG, "notifyServiceState: " + state);
         synchronized (mRecords) {
             mServiceState = state;
             for (Record r : mRecords) {
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 915b679..a2d10df 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -937,7 +937,7 @@
                 evaluateTrafficStatsPolling();
                 mWifiStateMachine.enableRssiPolling(true);
                 if (mBackgroundScanSupported) {
-                    mWifiStateMachine.enableBackgroundScan(false);
+                    mWifiStateMachine.enableBackgroundScanCommand(false);
                 }
                 mWifiStateMachine.enableAllNetworks();
                 updateWifiState();
@@ -949,7 +949,7 @@
                 evaluateTrafficStatsPolling();
                 mWifiStateMachine.enableRssiPolling(false);
                 if (mBackgroundScanSupported) {
-                    mWifiStateMachine.enableBackgroundScan(true);
+                    mWifiStateMachine.enableBackgroundScanCommand(true);
                 }
                 /*
                  * Set a timer to put Wi-Fi to sleep, but only if the screen is off
diff --git a/services/java/com/android/server/pm/Installer.java b/services/java/com/android/server/pm/Installer.java
index 8d40000..da3ebaf 100644
--- a/services/java/com/android/server/pm/Installer.java
+++ b/services/java/com/android/server/pm/Installer.java
@@ -28,7 +28,7 @@
 class Installer {
     private static final String TAG = "Installer";
 
-    private static final boolean LOCAL_DEBUG = true;
+    private static final boolean LOCAL_DEBUG = false;
 
     InputStream mIn;
 
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 79c4518..e2874f8 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -5453,6 +5453,9 @@
         mDisplay.getMetrics(dm);
         CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
 
+        config.screenWidthDp = (int)(dm.widthPixels / dm.density);
+        config.screenHeightDp = (int)(dm.heightPixels / dm.density);
+
         if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
             // Note we only do this once because at this point we don't
             // expect the screen to change in this way at runtime, and want
diff --git a/services/jni/com_android_server_UsbService.cpp b/services/jni/com_android_server_UsbService.cpp
index 6aeede2..00ee7e3 100644
--- a/services/jni/com_android_server_UsbService.cpp
+++ b/services/jni/com_android_server_UsbService.cpp
@@ -260,7 +260,7 @@
         return -1;
     }
 
-   clazz = env->FindClass("java/io/FileDescriptor");
+    clazz = env->FindClass("java/io/FileDescriptor");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor");
     gFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
     gFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "()V");
@@ -268,7 +268,7 @@
     LOG_FATAL_IF(gFileDescriptorOffsets.mDescriptor == NULL,
                  "Unable to find descriptor field in java.io.FileDescriptor");
 
-   clazz = env->FindClass("android/os/ParcelFileDescriptor");
+    clazz = env->FindClass("android/os/ParcelFileDescriptor");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
     gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
     gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
diff --git a/services/surfaceflinger/tests/resize/resize.cpp b/services/surfaceflinger/tests/resize/resize.cpp
index 0ccca77..18c54b3 100644
--- a/services/surfaceflinger/tests/resize/resize.cpp
+++ b/services/surfaceflinger/tests/resize/resize.cpp
@@ -29,13 +29,6 @@
 using namespace android;
 
 namespace android {
-class Test {
-public:
-    static const sp<ISurface>& getISurface(const sp<Surface>& s) {
-        return s->getISurface();
-    }
-};
-};
 
 int main(int argc, char** argv)
 {
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index 2b2ec7b..a2271d9 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -156,6 +156,20 @@
         return 0;
     }
 
+    // screen dp width
+    if (getScreenWidthDpName(part.string(), &config)) {
+        *axis = AXIS_SCREENWIDTHDP;
+        *value = config.screenWidthDp;
+        return 0;
+    }
+
+    // screen dp height
+    if (getScreenHeightDpName(part.string(), &config)) {
+        *axis = AXIS_SCREENHEIGHTDP;
+        *value = config.screenHeightDp;
+        return 0;
+    }
+
     // orientation
     if (getOrientationName(part.string(), &config)) {
         *axis = AXIS_ORIENTATION;
@@ -243,7 +257,7 @@
 
     String8 mcc, mnc, loc, layoutsize, layoutlong, orient, den;
     String8 touch, key, keysHidden, nav, navHidden, size, vers;
-    String8 uiModeType, uiModeNight;
+    String8 uiModeType, uiModeNight, widthdp, heightdp;
 
     const char *p = dir;
     const char *q;
@@ -354,6 +368,30 @@
         //printf("not screen layout long: %s\n", part.string());
     }
 
+    if (getScreenWidthDpName(part.string())) {
+        widthdp = part;
+
+        index++;
+        if (index == N) {
+            goto success;
+        }
+        part = parts[index];
+    } else {
+        //printf("not screen width dp: %s\n", part.string());
+    }
+
+    if (getScreenHeightDpName(part.string())) {
+        heightdp = part;
+
+        index++;
+        if (index == N) {
+            goto success;
+        }
+        part = parts[index];
+    } else {
+        //printf("not screen height dp: %s\n", part.string());
+    }
+
     // orientation
     if (getOrientationName(part.string())) {
         orient = part;
@@ -503,6 +541,8 @@
     this->locale = loc;
     this->screenLayoutSize = layoutsize;
     this->screenLayoutLong = layoutlong;
+    this->screenWidthDp = widthdp;
+    this->screenHeightDp = heightdp;
     this->orientation = orient;
     this->uiModeType = uiModeType;
     this->uiModeNight = uiModeNight;
@@ -534,6 +574,10 @@
     s += ",";
     s += screenLayoutLong;
     s += ",";
+    s += screenWidthDp;
+    s += ",";
+    s += screenHeightDp;
+    s += ",";
     s += this->orientation;
     s += ",";
     s += uiModeType;
@@ -582,6 +626,14 @@
         s += "-";
         s += screenLayoutLong;
     }
+    if (this->screenWidthDp != "") {
+        s += "-";
+        s += screenWidthDp;
+    }
+    if (this->screenHeightDp != "") {
+        s += "-";
+        s += screenHeightDp;
+    }
     if (this->orientation != "") {
         s += "-";
         s += orientation;
@@ -1039,8 +1091,7 @@
     return false;
 }
 
-bool AaptGroupEntry::getScreenSizeName(const char* name,
-                                       ResTable_config* out)
+bool AaptGroupEntry::getScreenSizeName(const char* name, ResTable_config* out)
 {
     if (strcmp(name, kWildcardName) == 0) {
         if (out) {
@@ -1075,8 +1126,53 @@
     return true;
 }
 
-bool AaptGroupEntry::getVersionName(const char* name,
-                                    ResTable_config* out)
+bool AaptGroupEntry::getScreenWidthDpName(const char* name, ResTable_config* out)
+{
+    if (strcmp(name, kWildcardName) == 0) {
+        if (out) {
+            out->screenWidthDp = out->SCREENWIDTH_ANY;
+        }
+        return true;
+    }
+
+    if (*name != 'w') return false;
+    name++;
+    const char* x = name;
+    while (*x >= '0' && *x <= '9') x++;
+    if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false;
+    String8 xName(name, x-name);
+
+    if (out) {
+        out->screenWidthDp = (uint16_t)atoi(xName.string());
+    }
+
+    return true;
+}
+
+bool AaptGroupEntry::getScreenHeightDpName(const char* name, ResTable_config* out)
+{
+    if (strcmp(name, kWildcardName) == 0) {
+        if (out) {
+            out->screenHeightDp = out->SCREENWIDTH_ANY;
+        }
+        return true;
+    }
+
+    if (*name != 'h') return false;
+    name++;
+    const char* x = name;
+    while (*x >= '0' && *x <= '9') x++;
+    if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false;
+    String8 xName(name, x-name);
+
+    if (out) {
+        out->screenHeightDp = (uint16_t)atoi(xName.string());
+    }
+
+    return true;
+}
+
+bool AaptGroupEntry::getVersionName(const char* name, ResTable_config* out)
 {
     if (strcmp(name, kWildcardName) == 0) {
         if (out) {
@@ -1112,6 +1208,8 @@
     if (v == 0) v = vendor.compare(o.vendor);
     if (v == 0) v = screenLayoutSize.compare(o.screenLayoutSize);
     if (v == 0) v = screenLayoutLong.compare(o.screenLayoutLong);
+    if (v == 0) v = screenWidthDp.compare(o.screenWidthDp);
+    if (v == 0) v = screenHeightDp.compare(o.screenHeightDp);
     if (v == 0) v = orientation.compare(o.orientation);
     if (v == 0) v = uiModeType.compare(o.uiModeType);
     if (v == 0) v = uiModeNight.compare(o.uiModeNight);
@@ -1135,6 +1233,8 @@
     getLocaleName(locale.string(), &params);
     getScreenLayoutSizeName(screenLayoutSize.string(), &params);
     getScreenLayoutLongName(screenLayoutLong.string(), &params);
+    getScreenWidthDpName(screenWidthDp.string(), &params);
+    getScreenHeightDpName(screenHeightDp.string(), &params);
     getOrientationName(orientation.string(), &params);
     getUiModeTypeName(uiModeType.string(), &params);
     getUiModeNightName(uiModeNight.string(), &params);
@@ -1149,7 +1249,10 @@
     
     // Fix up version number based on specified parameters.
     int minSdk = 0;
-    if ((params.uiMode&ResTable_config::MASK_UI_MODE_TYPE)
+    if (params.screenWidthDp != ResTable_config::SCREENWIDTH_ANY
+            || params.screenHeightDp != ResTable_config::SCREENHEIGHT_ANY) {
+        minSdk = SDK_ICS;
+    } else if ((params.uiMode&ResTable_config::MASK_UI_MODE_TYPE)
                 != ResTable_config::UI_MODE_TYPE_ANY
             ||  (params.uiMode&ResTable_config::MASK_UI_MODE_NIGHT)
                 != ResTable_config::UI_MODE_NIGHT_ANY) {
diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h
index eeb00c0..e5afd1b 100644
--- a/tools/aapt/AaptAssets.h
+++ b/tools/aapt/AaptAssets.h
@@ -42,6 +42,8 @@
     AXIS_NAVHIDDEN,
     AXIS_NAVIGATION,
     AXIS_SCREENSIZE,
+    AXIS_SCREENWIDTHDP,
+    AXIS_SCREENHEIGHTDP,
     AXIS_VERSION
 };
 
@@ -52,6 +54,7 @@
     SDK_ECLAIR_0_1 = 6,
     SDK_MR1 = 7,
     SDK_FROYO = 8,
+    SDK_ICS = 13,
 };
 
 /**
@@ -71,6 +74,8 @@
     String8 vendor;
     String8 screenLayoutSize;
     String8 screenLayoutLong;
+    String8 screenWidthDp;
+    String8 screenHeightDp;
     String8 orientation;
     String8 uiModeType;
     String8 uiModeNight;
@@ -102,6 +107,8 @@
     static bool getNavigationName(const char* name, ResTable_config* out = NULL);
     static bool getNavHiddenName(const char* name, ResTable_config* out = NULL);
     static bool getScreenSizeName(const char* name, ResTable_config* out = NULL);
+    static bool getScreenWidthDpName(const char* name, ResTable_config* out = NULL);
+    static bool getScreenHeightDpName(const char* name, ResTable_config* out = NULL);
     static bool getVersionName(const char* name, ResTable_config* out = NULL);
 
     int compare(const AaptGroupEntry& o) const;
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 10815a1..3dcc093 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -2607,6 +2607,12 @@
     if (!match(AXIS_SCREENSIZE, config.screenSize)) {
         return false;
     }
+    if (!match(AXIS_SCREENWIDTHDP, config.screenWidthDp)) {
+        return false;
+    }
+    if (!match(AXIS_SCREENHEIGHTDP, config.screenHeightDp)) {
+        return false;
+    }
     if (!match(AXIS_SCREENLAYOUTSIZE, config.screenLayout&ResTable_config::MASK_SCREENSIZE)) {
         return false;
     }
@@ -2803,7 +2809,7 @@
                 ConfigDescription config = t->getUniqueConfigs().itemAt(ci);
 
                 NOISY(printf("Writing config %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                       ti+1,
                       config.mcc, config.mnc,
                       config.language[0] ? config.language[0] : '-',
@@ -2818,7 +2824,9 @@
                       config.inputFlags,
                       config.navigation,
                       config.screenWidth,
-                      config.screenHeight));
+                      config.screenHeight,
+                      config.screenWidthDp,
+                      config.screenHeightDp));
                       
                 if (filterable && !filter.match(config)) {
                     continue;
@@ -2841,7 +2849,7 @@
                 tHeader->entriesStart = htodl(typeSize);
                 tHeader->config = config;
                 NOISY(printf("Writing type %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                       ti+1,
                       tHeader->config.mcc, tHeader->config.mnc,
                       tHeader->config.language[0] ? tHeader->config.language[0] : '-',
@@ -2856,7 +2864,9 @@
                       tHeader->config.inputFlags,
                       tHeader->config.navigation,
                       tHeader->config.screenWidth,
-                      tHeader->config.screenHeight));
+                      tHeader->config.screenHeight,
+                      tHeader->config.screenWidthDp,
+                      tHeader->config.screenHeightDp));
                 tHeader->config.swapHtoD();
 
                 // Build the entries inside of this type.
@@ -3438,7 +3448,7 @@
     if (e == NULL) {
         if (config != NULL) {
             NOISY(printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c "
-                    "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                    "orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                       sourcePos.file.string(), sourcePos.line,
                       config->mcc, config->mnc,
                       config->language[0] ? config->language[0] : '-',
@@ -3452,7 +3462,9 @@
                       config->inputFlags,
                       config->navigation,
                       config->screenWidth,
-                      config->screenHeight));
+                      config->screenHeight,
+                      config->screenWidthDp,
+                      config->screenHeightDp));
         } else {
             NOISY(printf("New entry at %s:%d: NULL config\n",
                       sourcePos.file.string(), sourcePos.line));
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 2fd58e4..c5eaef9 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -372,8 +372,6 @@
             if (mViewRoot == null) {
                 return ERROR_NOT_INFLATED.createResult();
             }
-            // measure the views
-            int w_spec, h_spec;
 
             RenderingMode renderingMode = params.getRenderingMode();
 
@@ -385,38 +383,64 @@
                 mMeasuredScreenHeight = params.getScreenHeight();
 
                 if (renderingMode != RenderingMode.NORMAL) {
-                    // measure the full size needed by the layout.
-                    w_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenWidth,
-                            renderingMode.isHorizExpand() ?
-                                    MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
-                                    : MeasureSpec.EXACTLY);
-                    h_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenHeight,
-                            renderingMode.isVertExpand() ?
-                                    MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
-                                    : MeasureSpec.EXACTLY);
-                    mViewRoot.measure(w_spec, h_spec);
+                    int widthMeasureSpecMode = renderingMode.isHorizExpand() ?
+                            MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
+                            : MeasureSpec.EXACTLY;
+                    int heightMeasureSpecMode = renderingMode.isVertExpand() ?
+                            MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
+                            : MeasureSpec.EXACTLY;
 
+                    // We used to compare the measured size of the content to the screen size but
+                    // this does not work anymore due to the 2 following issues:
+                    // - If the content is in a decor (system bar, title/action bar), the root view
+                    //   will not resize even with the UNSPECIFIED because of the embedded layout.
+                    // - If there is no decor, but a dialog frame, then the dialog padding prevents
+                    //   comparing the size of the content to the screen frame (as it would not
+                    //   take into account the dialog padding).
+
+                    // The solution is to first get the content size in a normal rendering, inside
+                    // the decor or the dialog padding.
+                    // Then measure only the content with UNSPECIFIED to see the size difference
+                    // and apply this to the screen size.
+
+                    // first measure the full layout, with EXACTLY to get the size of the
+                    // content as it is inside the decor/dialog
+                    Pair<Integer, Integer> exactMeasure = measureView(
+                            mViewRoot, mContentRoot.getChildAt(0),
+                            mMeasuredScreenWidth, MeasureSpec.EXACTLY,
+                            mMeasuredScreenHeight, MeasureSpec.EXACTLY);
+
+                    // now measure the content only using UNSPECIFIED (where applicable, based on
+                    // the rendering mode). This will give us the size the content needs.
+                    Pair<Integer, Integer> result = measureView(
+                            mContentRoot, mContentRoot.getChildAt(0),
+                            mMeasuredScreenWidth, widthMeasureSpecMode,
+                            mMeasuredScreenHeight, heightMeasureSpecMode);
+
+                    // now look at the difference and add what is needed.
                     if (renderingMode.isHorizExpand()) {
-                        int neededWidth = mViewRoot.getChildAt(0).getMeasuredWidth();
-                        if (neededWidth > mMeasuredScreenWidth) {
-                            mMeasuredScreenWidth = neededWidth;
+                        int measuredWidth = exactMeasure.getFirst();
+                        int neededWidth = result.getFirst();
+                        if (neededWidth > measuredWidth) {
+                            mMeasuredScreenWidth += neededWidth - measuredWidth;
                         }
                     }
 
                     if (renderingMode.isVertExpand()) {
-                        int neededHeight = mViewRoot.getChildAt(0).getMeasuredHeight();
-                        if (neededHeight > mMeasuredScreenHeight) {
-                            mMeasuredScreenHeight = neededHeight;
+                        int measuredHeight = exactMeasure.getSecond();
+                        int neededHeight = result.getSecond();
+                        if (neededHeight > measuredHeight) {
+                            mMeasuredScreenHeight += neededHeight - measuredHeight;
                         }
                     }
                 }
             }
 
-            // remeasure with the size we need
+            // measure again with the size we need
             // This must always be done before the call to layout
-            w_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenWidth, MeasureSpec.EXACTLY);
-            h_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenHeight, MeasureSpec.EXACTLY);
-            mViewRoot.measure(w_spec, h_spec);
+            measureView(mViewRoot, null /*measuredView*/,
+                    mMeasuredScreenWidth, MeasureSpec.EXACTLY,
+                    mMeasuredScreenHeight, MeasureSpec.EXACTLY);
 
             // now do the layout.
             mViewRoot.layout(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
@@ -494,6 +518,34 @@
     }
 
     /**
+     * Executes {@link View#measure(int, int)} on a given view with the given parameters (used
+     * to create measure specs with {@link MeasureSpec#makeMeasureSpec(int, int)}.
+     *
+     * if <var>measuredView</var> is non null, the method returns a {@link Pair} of (width, height)
+     * for the view (using {@link View#getMeasuredWidth()} and {@link View#getMeasuredHeight()}).
+     *
+     * @param viewToMeasure the view on which to execute measure().
+     * @param measuredView if non null, the view to query for its measured width/height.
+     * @param width the width to use in the MeasureSpec.
+     * @param widthMode the MeasureSpec mode to use for the width.
+     * @param height the height to use in the MeasureSpec.
+     * @param heightMode the MeasureSpec mode to use for the height.
+     * @return the measured width/height if measuredView is non-null, null otherwise.
+     */
+    private Pair<Integer, Integer> measureView(ViewGroup viewToMeasure, View measuredView,
+            int width, int widthMode, int height, int heightMode) {
+        int w_spec = MeasureSpec.makeMeasureSpec(width, widthMode);
+        int h_spec = MeasureSpec.makeMeasureSpec(height, heightMode);
+        viewToMeasure.measure(w_spec, h_spec);
+
+        if (measuredView != null) {
+            return Pair.of(measuredView.getMeasuredWidth(), measuredView.getMeasuredHeight());
+        }
+
+        return null;
+    }
+
+    /**
      * Animate an object
      * <p>
      * {@link #acquire(long)} must have been called before this.
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 909605d..6e13d0f 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -171,5 +171,7 @@
      */
     public native static String waitForEvent();
 
-    public native static void enableBackgroundScan(boolean enable);
+    public native static void enableBackgroundScanCommand(boolean enable);
+
+    public native static void setScanIntervalCommand(int scanInterval);
 }
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 4346b327..46c07a3 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -339,10 +339,20 @@
     private static final int POWER_MODE_AUTO = 0;
 
     /**
-     * See {@link Settings.Secure#WIFI_SCAN_INTERVAL_MS}. This is the default value if a
-     * Settings.Secure value is not present.
+     * Default framework scan interval in milliseconds. This is used in the scenario in which
+     * wifi chipset does not support background scanning to set up a
+     * periodic wake up scan so that the device can connect to a new access
+     * point on the move. {@link Settings.Secure#WIFI_FRAMEWORK_SCAN_INTERVAL_MS} can
+     * override this.
      */
-    private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
+    private final int mDefaultFrameworkScanIntervalMs;
+
+    /**
+     * Default supplicant scan interval in milliseconds.
+     * {@link Settings.Secure#WIFI_SUPPLICANT_SCAN_INTERVAL_MS} can override this.
+     */
+    private final int mDefaultSupplicantScanIntervalMs;
+
 
     private static final int MIN_RSSI = -200;
     private static final int MAX_RSSI = 256;
@@ -472,6 +482,12 @@
         Intent scanIntent = new Intent(ACTION_START_SCAN, null);
         mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0);
 
+        mDefaultFrameworkScanIntervalMs = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_wifi_framework_scan_interval);
+
+        mDefaultSupplicantScanIntervalMs = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_wifi_supplicant_scan_interval);
+
         mContext.registerReceiver(
             new BroadcastReceiver() {
                 @Override
@@ -819,7 +835,7 @@
        sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
     }
 
-    public void enableBackgroundScan(boolean enabled) {
+    public void enableBackgroundScanCommand(boolean enabled) {
        sendMessage(obtainMessage(CMD_ENABLE_BACKGROUND_SCAN, enabled ? 1 : 0, 0));
     }
 
@@ -1949,6 +1965,11 @@
             mIsScanMode = false;
             /* Wifi is available as long as we have a connection to supplicant */
             mNetworkInfo.setIsAvailable(true);
+            /* Set scan interval */
+            long supplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
+                    Settings.Secure.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
+                    mDefaultSupplicantScanIntervalMs);
+            WifiNative.setScanIntervalCommand((int)supplicantScanIntervalMs / 1000);
         }
         @Override
         public boolean processMessage(Message message) {
@@ -2800,17 +2821,21 @@
 
     class DisconnectedState extends HierarchicalState {
         private boolean mAlarmEnabled = false;
-        private long mScanIntervalMs;
+        /* This is set from the overlay config file or from a secure setting.
+         * A value of 0 disables scanning in the framework.
+         */
+        private long mFrameworkScanIntervalMs;
 
         private void setScanAlarm(boolean enabled) {
             if (enabled == mAlarmEnabled) return;
             if (enabled) {
-                mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
-                        System.currentTimeMillis() + mScanIntervalMs,
-                        mScanIntervalMs,
-                        mScanIntent);
-
-                mAlarmEnabled = true;
+                if (mFrameworkScanIntervalMs > 0) {
+                    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
+                            System.currentTimeMillis() + mFrameworkScanIntervalMs,
+                            mFrameworkScanIntervalMs,
+                            mScanIntent);
+                    mAlarmEnabled = true;
+                }
             } else {
                 mAlarmManager.cancel(mScanIntent);
                 mAlarmEnabled = false;
@@ -2822,8 +2847,9 @@
             if (DBG) Log.d(TAG, getName() + "\n");
             EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
 
-            mScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
-                    Settings.Secure.WIFI_SCAN_INTERVAL_MS, DEFAULT_SCAN_INTERVAL_MS);
+            mFrameworkScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
+                    Settings.Secure.WIFI_FRAMEWORK_SCAN_INTERVAL_MS,
+                    mDefaultFrameworkScanIntervalMs);
             /*
              * We initiate background scanning if it is enabled, otherwise we
              * initiate an infrequent scan that wakes up the device to ensure
@@ -2837,7 +2863,7 @@
                  * cleared
                  */
                 if (!mScanResultIsPending) {
-                    WifiNative.enableBackgroundScan(true);
+                    WifiNative.enableBackgroundScanCommand(true);
                 }
             } else {
                 setScanAlarm(true);
@@ -2859,10 +2885,10 @@
                 case CMD_ENABLE_BACKGROUND_SCAN:
                     mEnableBackgroundScan = (message.arg1 == 1);
                     if (mEnableBackgroundScan) {
-                        WifiNative.enableBackgroundScan(true);
+                        WifiNative.enableBackgroundScanCommand(true);
                         setScanAlarm(false);
                     } else {
-                        WifiNative.enableBackgroundScan(false);
+                        WifiNative.enableBackgroundScanCommand(false);
                         setScanAlarm(true);
                     }
                     break;
@@ -2877,14 +2903,14 @@
                 case CMD_START_SCAN:
                     /* Disable background scan temporarily during a regular scan */
                     if (mEnableBackgroundScan) {
-                        WifiNative.enableBackgroundScan(false);
+                        WifiNative.enableBackgroundScanCommand(false);
                     }
                     /* Handled in parent state */
                     return NOT_HANDLED;
                 case SCAN_RESULTS_EVENT:
                     /* Re-enable background scan when a pending scan result is received */
                     if (mEnableBackgroundScan && mScanResultIsPending) {
-                        WifiNative.enableBackgroundScan(true);
+                        WifiNative.enableBackgroundScanCommand(true);
                     }
                     /* Handled in parent state */
                     return NOT_HANDLED;
@@ -2899,7 +2925,7 @@
         public void exit() {
             /* No need for a background scan upon exit from a disconnected state */
             if (mEnableBackgroundScan) {
-                WifiNative.enableBackgroundScan(false);
+                WifiNative.enableBackgroundScanCommand(false);
             }
             setScanAlarm(false);
         }