Merge "Add some network/phone type constants."
diff --git a/api/current.xml b/api/current.xml
index ff4942e..07f298e 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -14275,7 +14275,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973949"
+ value="16973951"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -14286,7 +14286,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973950"
+ value="16973952"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -14436,6 +14436,17 @@
  visibility="public"
 >
 </field>
+<field name="Theme_Holo_Dialog_Alert"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16973945"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="Theme_Holo_Extended"
  type="int"
  transient="false"
@@ -14469,6 +14480,17 @@
  visibility="public"
 >
 </field>
+<field name="Theme_Holo_Light_Dialog_Alert"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16973946"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="Theme_Holo_Light_Extended"
  type="int"
  transient="false"
@@ -14781,7 +14803,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973948"
+ value="16973950"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -14792,7 +14814,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973947"
+ value="16973949"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -14946,7 +14968,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973951"
+ value="16973953"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -15012,7 +15034,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973945"
+ value="16973947"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -15067,7 +15089,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="16973946"
+ value="16973948"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -19457,9 +19479,41 @@
 >
 <parameter name="tab" type="android.app.ActionBar.Tab">
 </parameter>
+<parameter name="setSelected" type="boolean">
+</parameter>
+</method>
+<method name="addTab"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="tab" type="android.app.ActionBar.Tab">
+</parameter>
 <parameter name="position" type="int">
 </parameter>
 </method>
+<method name="addTab"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="tab" type="android.app.ActionBar.Tab">
+</parameter>
+<parameter name="position" type="int">
+</parameter>
+<parameter name="setSelected" type="boolean">
+</parameter>
+</method>
 <method name="getCustomNavigationView"
  return="android.view.View"
  abstract="true"
@@ -50131,6 +50185,17 @@
  visibility="public"
 >
 </field>
+<field name="CATEGORY_HE_DESK_DOCK"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.intent.category.HE_DESK_DOCK&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="CATEGORY_HOME"
  type="java.lang.String"
  transient="false"
@@ -50164,6 +50229,17 @@
  visibility="public"
 >
 </field>
+<field name="CATEGORY_LE_DESK_DOCK"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.intent.category.LE_DESK_DOCK&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="CATEGORY_MONKEY"
  type="java.lang.String"
  transient="false"
@@ -50383,6 +50459,28 @@
  visibility="public"
 >
 </field>
+<field name="EXTRA_DOCK_STATE_HE_DESK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="4"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_DOCK_STATE_LE_DESK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="3"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="EXTRA_DOCK_STATE_UNDOCKED"
  type="int"
  transient="false"
@@ -63137,7 +63235,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </method>
@@ -68663,29 +68761,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="2012"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="TYPE_FINALIZE_FAILED"
- type="int"
- transient="false"
- volatile="false"
- value="2010"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="TYPE_INITIALIZE_FAILED"
- type="int"
- transient="false"
- volatile="false"
- value="2009"
+ value="2008"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -68725,7 +68801,7 @@
  visibility="public"
 >
 </field>
-<field name="TYPE_REGISTRATION_FAILED"
+<field name="TYPE_PROCESS_DRM_INFO_FAILED"
  type="int"
  transient="false"
  volatile="false"
@@ -68740,18 +68816,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="2011"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="TYPE_RIGHTS_ACQUISITION_FAILED"
- type="int"
- transient="false"
- volatile="false"
- value="2008"
+ value="2007"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -68780,17 +68845,6 @@
  visibility="public"
 >
 </field>
-<field name="TYPE_UNREGISTRATION_FAILED"
- type="int"
- transient="false"
- volatile="false"
- value="2007"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 </class>
 <class name="DrmEvent"
  extends="java.lang.Object"
@@ -68873,7 +68927,7 @@
  type="int"
  transient="false"
  volatile="false"
- value="1006"
+ value="1001"
  static="true"
  final="true"
  deprecated="not deprecated"
@@ -68884,28 +68938,6 @@
  type="int"
  transient="false"
  volatile="false"
- value="1007"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="TYPE_FINALIZED"
- type="int"
- transient="false"
- volatile="false"
- value="1001"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="TYPE_INITIALIZED"
- type="int"
- transient="false"
- volatile="false"
  value="1003"
  static="true"
  final="true"
@@ -68913,7 +68945,7 @@
  visibility="public"
 >
 </field>
-<field name="TYPE_REGISTERED"
+<field name="TYPE_DRM_INFO_PROCESSED"
  type="int"
  transient="false"
  volatile="false"
@@ -68924,28 +68956,6 @@
  visibility="public"
 >
 </field>
-<field name="TYPE_RIGHTS_ACQUIRED"
- type="int"
- transient="false"
- volatile="false"
- value="1005"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="TYPE_UNREGISTERED"
- type="int"
- transient="false"
- volatile="false"
- value="1004"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 </class>
 <class name="DrmInfo"
  extends="java.lang.Object"
@@ -69321,6 +69331,8 @@
 >
 <parameter name="_statusCode" type="int">
 </parameter>
+<parameter name="_infoType" type="int">
+</parameter>
 <parameter name="_data" type="android.drm.ProcessedData">
 </parameter>
 <parameter name="_mimeType" type="java.lang.String">
@@ -69358,6 +69370,16 @@
  visibility="public"
 >
 </field>
+<field name="infoType"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="mimeType"
  type="java.lang.String"
  transient="false"
@@ -69621,17 +69643,6 @@
 <parameter name="uri" type="android.net.Uri">
 </parameter>
 </method>
-<method name="loadPlugIns"
- return="int"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
 <method name="openConvertSession"
  return="int"
  abstract="false"
@@ -69753,17 +69764,6 @@
 <parameter name="infoListener" type="android.drm.DrmManagerClient.OnInfoListener">
 </parameter>
 </method>
-<method name="unloadPlugIns"
- return="int"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
 <field name="ERROR_NONE"
  type="int"
  transient="false"
@@ -196802,6 +196802,17 @@
  visibility="public"
 >
 </field>
+<field name="KEYCODE_VOLUME_MUTE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="164"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="KEYCODE_VOLUME_UP"
  type="int"
  transient="false"
@@ -237773,21 +237784,6 @@
 <parameter name="value" type="long">
 </parameter>
 </method>
-<method name="setOnClickExtras"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="viewId" type="int">
-</parameter>
-<parameter name="extras" type="android.os.Bundle">
-</parameter>
-</method>
 <method name="setOnClickFillInIntent"
  return="void"
  abstract="false"
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
index 37c8ad0..b5fddfa 100644
--- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
+++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
@@ -389,11 +389,13 @@
             if (err == 0) {
                 observer.waitForCompletion();
                 sets = observer.sets;
-                for (RestoreSet s : sets) {
-                    if (s.token == token) {
-                        System.out.println("Scheduling restore: " + s.name);
-                        didRestore = (mRestore.restoreAll(token, observer) == 0);
-                        break;
+                if (sets != null) {
+                    for (RestoreSet s : sets) {
+                        if (s.token == token) {
+                            System.out.println("Scheduling restore: " + s.name);
+                            didRestore = (mRestore.restoreAll(token, observer) == 0);
+                            break;
+                        }
                     }
                 }
             }
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index b359ce6..e185624 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -397,14 +397,24 @@
 
     /**
      * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
+     * If this is the first tab to be added it will become the selected tab.
      *
      * @param tab Tab to add
      */
     public abstract void addTab(Tab tab);
 
     /**
+     * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
+     *
+     * @param tab Tab to add
+     * @param setSelected True if the added tab should become the selected tab.
+     */
+    public abstract void addTab(Tab tab, boolean setSelected);
+
+    /**
      * Add a tab for use in tabbed navigation mode. The tab will be inserted at
-     * <code>position</code>.
+     * <code>position</code>. If this is the first tab to be added it will become
+     * the selected tab.
      *
      * @param tab The tab to add
      * @param position The new position of the tab
@@ -412,6 +422,16 @@
     public abstract void addTab(Tab tab, int position);
 
     /**
+     * Add a tab for use in tabbed navigation mode. The tab will be insterted at
+     * <code>position</code>.
+     *
+     * @param tab The tab to add
+     * @param position The new position of the tab
+     * @param setSelected True if the added tab should become the selected tab.
+     */
+    public abstract void addTab(Tab tab, int position, boolean setSelected);
+
+    /**
      * Remove a tab from the action bar. If the removed tab was selected it will be deselected
      * and another tab will be selected if present.
      *
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 1fae516..e3242c1 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -39,13 +39,17 @@
  * </ul>
  *
  * <p>
- * Each of the notify methods takes an int id parameter.  This id identifies
- * this notification from your app to the system, so that id should be unique
- * within your app.  If you call one of the notify methods with an id that is
- * currently active and a new set of notification parameters, it will be
- * updated.  For example, if you pass a new status bar icon, the old icon in
- * the status bar will be replaced with the new one.  This is also the same
- * id you pass to the {@link #cancel} method to clear this notification.
+ * Each of the notify methods takes an int id parameter and optionally a
+ * {@link String} tag parameter, which may be {@code null}.  These parameters
+ * are used to form a pair (tag, id), or ({@code null}, id) if tag is
+ * unspecified.  This pair identifies this notification from your app to the
+ * system, so that pair should be unique within your app.  If you call one
+ * of the notify methods with a (tag, id) pair that is currently active and
+ * a new set of notification parameters, it will be updated.  For example,
+ * if you pass a new status bar icon, the old icon in the status bar will
+ * be replaced with the new one.  This is also the same tag and id you pass
+ * to the {@link #cancel(int)} or {@link #cancel(String, int)} method to clear
+ * this notification.
  *
  * <p>
  * You do not instantiate this class directly; instead, retrieve it through
@@ -94,12 +98,11 @@
     /**
      * Persistent notification on the status bar,
      *
-     * @param tag An string identifier for this notification unique within your
-     *        application.
+     * @param tag A string identifier for this notification.  May be {@code null}.
+     * @param id An identifier for this notification.  The pair (tag, id) must be unique
+     *        within your application.
      * @param notification A {@link Notification} object describing how to
      *        notify the user, other than the view you're providing. Must not be null.
-     * @return the id of the notification that is associated with the string identifier that
-     * can be used to cancel the notification
      */
     public void notify(String tag, int id, Notification notification)
     {
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index c72be6b..c03b444 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -183,7 +183,7 @@
     public static final String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY  =
             "android.bluetooth.headset.intent.category.companyid";
 
-    /*
+    /**
      * Headset state when SCO audio is connected
      * This state can be one of
      * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
@@ -192,14 +192,22 @@
     public static final int STATE_AUDIO_CONNECTED = 10;
 
     /**
-     * Headset state when SCO audio is NOT connected
+     * Headset state when SCO audio is connecting
+     * This state can be one of
+     * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
+     * {@link #ACTION_AUDIO_STATE_CHANGED} intent.
+     * @hide
+     */
+    public static final int STATE_AUDIO_CONNECTING = 12;
+
+    /**
+     * Headset state when SCO audio is not connected
      * This state can be one of
      * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
      * {@link #ACTION_AUDIO_STATE_CHANGED} intent.
      */
     public static final int STATE_AUDIO_DISCONNECTED = 11;
 
-
     private Context mContext;
     private ServiceListener mServiceListener;
     private IBluetoothHeadset mService;
@@ -370,7 +378,8 @@
      *
      * <p> Users can listen to {@link #ACTION_AUDIO_STATE_CHANGED}.
      * {@link #EXTRA_STATE} will be set to {@link #STATE_AUDIO_CONNECTED}
-     * when the audio connection is established.
+     * when the audio connection is established,
+     * and to {@link #STATE_AUDIO_DISCONNECTED} in case of failure.
      *
      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
      *
@@ -593,6 +602,25 @@
         return false;
     }
 
+    /**
+     * Get the current audio state of the Headset.
+     * Note: This is an internal function and shouldn't be exposed
+     *
+     * @hide
+     */
+    public int getAudioState(BluetoothDevice device) {
+        if (DBG) log("getAudioState");
+        if (mService != null && isEnabled()) {
+            try {
+                return mService.getAudioState(device);
+            } catch (RemoteException e) {Log.e(TAG, e.toString());}
+        } else {
+            Log.w(TAG, "Proxy not attached to service");
+            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
+        }
+        return BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
+    }
+
     private ServiceConnection mConnection = new ServiceConnection() {
         public void onServiceConnected(ComponentName className, IBinder service) {
             if (DBG) Log.d(TAG, "Proxy object connected");
diff --git a/core/java/android/bluetooth/IBluetoothHeadset.aidl b/core/java/android/bluetooth/IBluetoothHeadset.aidl
index 3e4c7b4..ab07931 100644
--- a/core/java/android/bluetooth/IBluetoothHeadset.aidl
+++ b/core/java/android/bluetooth/IBluetoothHeadset.aidl
@@ -46,4 +46,5 @@
     boolean connectHeadsetInternal(in BluetoothDevice device);
     boolean disconnectHeadsetInternal(in BluetoothDevice device);
     boolean setAudioState(in BluetoothDevice device, int state);
+    int getAudioState(in BluetoothDevice device);
 }
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 8c36aa6..ac6b147 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -533,6 +533,8 @@
  *     <li> {@link #CATEGORY_TEST}
  *     <li> {@link #CATEGORY_CAR_DOCK}
  *     <li> {@link #CATEGORY_DESK_DOCK}
+ *     <li> {@link #CATEGORY_LE_DESK_DOCK}
+ *     <li> {@link #CATEGORY_HE_DESK_DOCK}
  *     <li> {@link #CATEGORY_CAR_MODE}
  *     <li> {@link #CATEGORY_APP_MARKET}
  * </ul>
@@ -549,6 +551,8 @@
  *     <li> {@link #EXTRA_CHANGED_COMPONENT_NAME}
  *     <li> {@link #EXTRA_DATA_REMOVED}
  *     <li> {@link #EXTRA_DOCK_STATE}
+ *     <li> {@link #EXTRA_DOCK_STATE_HE_DESK}
+ *     <li> {@link #EXTRA_DOCK_STATE_LE_DESK}
  *     <li> {@link #EXTRA_DOCK_STATE_CAR}
  *     <li> {@link #EXTRA_DOCK_STATE_DESK}
  *     <li> {@link #EXTRA_DOCK_STATE_UNDOCKED}
@@ -1822,6 +1826,51 @@
             "android.intent.action.HEADSET_PLUG";
 
     /**
+     * Broadcast Action: An analog audio speaker/headset plugged in or unplugged.
+     *
+     * <p>The intent will have the following extra values:
+     * <ul>
+     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
+     *   <li><em>name</em> - Headset type, human readable string </li>
+     * </ul>
+     * </ul>
+     * @hide
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_USB_ANLG_HEADSET_PLUG =
+            "android.intent.action.DOCK_HEADSET_PLUG";
+
+    /**
+     * Broadcast Action: An analog audio speaker/headset plugged in or unplugged.
+     *
+     * <p>The intent will have the following extra values:
+     * <ul>
+     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
+     *   <li><em>name</em> - Headset type, human readable string </li>
+     * </ul>
+     * </ul>
+     * @hide
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_USB_DGTL_HEADSET_PLUG =
+            "android.intent.action.HDMI_AUDIO_PLUG";
+
+    /**
+     * Broadcast Action: A HMDI cable was plugged or unplugged
+     *
+     * <p>The intent will have the following extra values:
+     * <ul>
+     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
+     *   <li><em>name</em> - HDMI cable, human readable string </li>
+     * </ul>
+     * </ul>
+     * @hide
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_HDMI_AUDIO_PLUG =
+            "android.intent.action.HDMI_AUDIO_PLUG";
+
+    /**
      * Broadcast Action: An outgoing call is about to be placed.
      *
      * <p>The Intent will have the following extra value:
@@ -2060,6 +2109,21 @@
      */
     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
     public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
+    /**
+     * An activity to run when device is inserted into a analog (low end) dock.
+     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
+     * information, see {@link android.app.UiModeManager}.
+     */
+    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
+    public static final String CATEGORY_LE_DESK_DOCK = "android.intent.category.LE_DESK_DOCK";
+
+    /**
+     * An activity to run when device is inserted into a digital (high end) dock.
+     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
+     * information, see {@link android.app.UiModeManager}.
+     */
+    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
+    public static final String CATEGORY_HE_DESK_DOCK = "android.intent.category.HE_DESK_DOCK";
 
     /**
      * Used to indicate that the activity can be used in a car environment.
@@ -2208,7 +2272,9 @@
      * intents to request the dock state.  Possible values are
      * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
      * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
-     * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
+     * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}, or
+     * {@link android.content.Intent#EXTRA_DOCK_STATE_LE_DESK}, or
+     * {@link android.content.Intent#EXTRA_DOCK_STATE_HE_DESK}.
      */
     public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
 
@@ -2231,6 +2297,18 @@
     public static final int EXTRA_DOCK_STATE_CAR = 2;
 
     /**
+     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
+     * to represent that the phone is in a analog (low end) dock.
+     */
+    public static final int EXTRA_DOCK_STATE_LE_DESK = 3;
+
+    /**
+     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
+     * to represent that the phone is in a digital (high end) dock.
+     */
+    public static final int EXTRA_DOCK_STATE_HE_DESK = 4;
+
+    /**
      * Boolean that can be supplied as meta-data with a dock activity, to
      * indicate that the dock should take over the home key when it is active.
      */
diff --git a/core/java/android/database/Cursor.java b/core/java/android/database/Cursor.java
index c03c586..a9a71cf 100644
--- a/core/java/android/database/Cursor.java
+++ b/core/java/android/database/Cursor.java
@@ -20,8 +20,6 @@
 import android.net.Uri;
 import android.os.Bundle;
 
-import java.util.Map;
-
 /**
  * This interface provides random read-write access to the result set returned
  * by a database query.
@@ -214,7 +212,9 @@
     /**
      * Returns the value of the requested column as a byte array.
      *
-     * <p>If the native content of that column is not blob exception may throw
+     * <p>The result and whether this method throws an exception when the
+     * column value is null or the column type is not a blob type is
+     * implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as a byte array.
@@ -224,8 +224,9 @@
     /**
      * Returns the value of the requested column as a String.
      *
-     * <p>If the native content of that column is not text the result will be
-     * the result of passing the column value to String.valueOf(x).
+     * <p>The result and whether this method throws an exception when the
+     * column value is null or the column type is not a string type is
+     * implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as a String.
@@ -245,8 +246,10 @@
     /**
      * Returns the value of the requested column as a short.
      *
-     * <p>If the native content of that column is not numeric the result will be
-     * the result of passing the column value to Short.valueOf(x).
+     * <p>The result and whether this method throws an exception when the
+     * column value is null, the column type is not an integral type, or the
+     * integer value is outside the range [<code>Short.MIN_VALUE</code>,
+     * <code>Short.MAX_VALUE</code>] is implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as a short.
@@ -256,8 +259,10 @@
     /**
      * Returns the value of the requested column as an int.
      *
-     * <p>If the native content of that column is not numeric the result will be
-     * the result of passing the column value to Integer.valueOf(x).
+     * <p>The result and whether this method throws an exception when the
+     * column value is null, the column type is not an integral type, or the
+     * integer value is outside the range [<code>Integer.MIN_VALUE</code>,
+     * <code>Integer.MAX_VALUE</code>] is implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as an int.
@@ -267,8 +272,10 @@
     /**
      * Returns the value of the requested column as a long.
      *
-     * <p>If the native content of that column is not numeric the result will be
-     * the result of passing the column value to Long.valueOf(x).
+     * <p>The result and whether this method throws an exception when the
+     * column value is null, the column type is not an integral type, or the
+     * integer value is outside the range [<code>Long.MIN_VALUE</code>,
+     * <code>Long.MAX_VALUE</code>] is implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as a long.
@@ -278,8 +285,10 @@
     /**
      * Returns the value of the requested column as a float.
      *
-     * <p>If the native content of that column is not numeric the result will be
-     * the result of passing the column value to Float.valueOf(x).
+     * <p>The result and whether this method throws an exception when the
+     * column value is null, the column type is not a floating-point type, or the
+     * floating-point value is not representable as a <code>float</code> value is
+     * implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as a float.
@@ -289,8 +298,10 @@
     /**
      * Returns the value of the requested column as a double.
      *
-     * <p>If the native content of that column is not numeric the result will be
-     * the result of passing the column value to Double.valueOf(x).
+     * <p>The result and whether this method throws an exception when the
+     * column value is null, the column type is not a floating-point type, or the
+     * floating-point value is not representable as a <code>double</code> value is
+     * implementation-defined.
      *
      * @param columnIndex the zero-based index of the target column.
      * @return the value of that column as a double.
@@ -344,7 +355,10 @@
      *
      * @return true if the requery succeeded, false if not, in which case the
      *         cursor becomes invalid.
+     * @deprecated Don't use this. Just request a new cursor, so you can do this
+     * asynchronously and update your list view once the new cursor comes back.
      */
+    @Deprecated
     boolean requery();
 
     /**
@@ -419,7 +433,8 @@
      * that are required to fetch data for the cursor.
      *
      * <p>These values may only change when requery is called.
-     * @return cursor-defined values, or Bundle.EMTPY if there are no values. Never null.
+     * @return cursor-defined values, or {@link android.os.Bundle#EMPTY Bundle.EMPTY} if there
+     *         are no values. Never <code>null</code>.
      */
     Bundle getExtras();
 
@@ -429,8 +444,10 @@
      *
      * <p>One use of this is to tell a cursor that it should retry its network request after it
      * reported an error.
-     * @param extras extra values, or Bundle.EMTPY. Never null.
-     * @return extra values, or Bundle.EMTPY. Never null.
+     * @param extras extra values, or {@link android.os.Bundle#EMPTY Bundle.EMPTY}.
+     *         Never <code>null</code>.
+     * @return extra values, or {@link android.os.Bundle#EMPTY Bundle.EMPTY}.
+     *         Never <code>null</code>.
      */
     Bundle respond(Bundle extras);
 }
diff --git a/core/java/android/database/CursorWindow.java b/core/java/android/database/CursorWindow.java
index 599431f..a026eca 100644
--- a/core/java/android/database/CursorWindow.java
+++ b/core/java/android/database/CursorWindow.java
@@ -240,6 +240,15 @@
         }
     }
 
+    /**
+     * Returns the value at (<code>row</code>, <code>col</code>) as a <code>byte</code> array.
+     *
+     * <p>If the value is null, then <code>null</code> is returned. If the
+     * type of column <code>col</code> is a string type, then the result
+     * is the array of bytes that make up the internal representation of the
+     * string value. If the type of column <code>col</code> is integral or floating-point,
+     * then an {@link SQLiteException} is thrown.
+     */
     private native byte[] getBlob_native(int row, int col);
 
     /**
@@ -340,6 +349,19 @@
         }
     }
     
+    /**
+     * Returns the value at (<code>row</code>, <code>col</code>) as a <code>String</code>.
+     *
+     * <p>If the value is null, then <code>null</code> is returned. If the
+     * type of column <code>col</code> is integral, then the result is the string
+     * that is obtained by formatting the integer value with the <code>printf</code>
+     * family of functions using format specifier <code>%lld</code>. If the
+     * type of column <code>col</code> is floating-point, then the result is the string
+     * that is obtained by formatting the floating-point value with the
+     * <code>printf</code> family of functions using format specifier <code>%g</code>.
+     * If the type of column <code>col</code> is a blob type, then an
+     * {@link SQLiteException} is thrown.
+     */
     private native String getString_native(int row, int col);
 
     /**
@@ -391,6 +413,17 @@
         }
     }
     
+    /**
+     * Returns the value at (<code>row</code>, <code>col</code>) as a <code>long</code>.
+     *
+     * <p>If the value is null, then <code>0L</code> is returned. If the
+     * type of column <code>col</code> is a string type, then the result
+     * is the <code>long</code> that is obtained by parsing the string value with
+     * <code>strtoll</code>. If the type of column <code>col</code> is
+     * floating-point, then the result is the floating-point value casted to a <code>long</code>.
+     * If the type of column <code>col</code> is a blob type, then an
+     * {@link SQLiteException} is thrown.
+     */
     private native long getLong_native(int row, int col);
 
     /**
@@ -410,6 +443,17 @@
         }
     }
     
+    /**
+     * Returns the value at (<code>row</code>, <code>col</code>) as a <code>double</code>.
+     *
+     * <p>If the value is null, then <code>0.0</code> is returned. If the
+     * type of column <code>col</code> is a string type, then the result
+     * is the <code>double</code> that is obtained by parsing the string value with
+     * <code>strtod</code>. If the type of column <code>col</code> is
+     * integral, then the result is the integer value casted to a <code>double</code>.
+     * If the type of column <code>col</code> is a blob type, then an
+     * {@link SQLiteException} is thrown.
+     */
     private native double getDouble_native(int row, int col);
 
     /**
diff --git a/core/java/android/database/RequeryOnUiThreadException.java b/core/java/android/database/RequeryOnUiThreadException.java
deleted file mode 100644
index 97a50d8..0000000
--- a/core/java/android/database/RequeryOnUiThreadException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2006 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.
- */
-
-package android.database;
-
-/**
- * An exception that indicates invoking {@link Cursor#requery()} on Main thread could cause ANR.
- * This exception should encourage apps to invoke {@link Cursor#requery()} in a background thread. 
- * @hide
- */
-public class RequeryOnUiThreadException extends RuntimeException {
-    public RequeryOnUiThreadException(String packageName) {
-        super("In " + packageName + " Requery is executing on main (UI) thread. could cause ANR. " +
-                "do it in background thread.");
-    }
-}
diff --git a/core/java/android/database/sqlite/SQLiteCursor.java b/core/java/android/database/sqlite/SQLiteCursor.java
index 225eaab..fc30da2 100644
--- a/core/java/android/database/sqlite/SQLiteCursor.java
+++ b/core/java/android/database/sqlite/SQLiteCursor.java
@@ -16,13 +16,10 @@
 
 package android.database.sqlite;
 
-import android.app.ActivityThread;
 import android.database.AbstractWindowedCursor;
 import android.database.CursorWindow;
 import android.database.DataSetObserver;
-import android.database.RequeryOnUiThreadException;
 import android.os.Handler;
-import android.os.Looper;
 import android.os.Message;
 import android.os.Process;
 import android.os.StrictMode;
@@ -76,11 +73,6 @@
     private boolean mPendingData = false;
 
     /**
-     * Used by {@link #requery()} to remember for which database we've already shown the warning.
-     */
-    private static final HashMap<String, Boolean> sAlreadyWarned = new HashMap<String, Boolean>();
-    
-    /**
      *  support for a cursor variant that doesn't always read all results
      *  initialRead is the initial number of items that cursor window reads 
      *  if query contains more than this number of items, a thread will be
@@ -401,35 +393,11 @@
         }
     }
 
-    /**
-     * Show a warning against the use of requery() if called on the main thread.
-     * This warning is shown per database per process.
-     */
-    private void warnIfUiThread() {
-        if (Looper.getMainLooper() == Looper.myLooper()) {
-            String databasePath = getQuery().mDatabase.getPath();
-            // We show the warning once per database in order not to spam logcat.
-            if (!sAlreadyWarned.containsKey(databasePath)) {
-                sAlreadyWarned.put(databasePath, true);
-                String packageName = ActivityThread.currentPackageName();
-                Throwable t = null;
-                // BEGIN STOPSHIP remove the following line
-                t = new RequeryOnUiThreadException(packageName);
-                // END STOPSHIP
-                String s = packageName == null ? "'unknown'" : packageName;
-                Log.w(TAG, "should not attempt requery on main (UI) thread: app = " + s +
-                        " (database: " + mQuery.mDatabase.getPath() +
-                        ", query: " + mQuery.mSql + ")", t);
-            }
-        }
-    }
-
     @Override
     public boolean requery() {
         if (isClosed()) {
             return false;
         }
-        warnIfUiThread();
         long timeStart = 0;
         if (Config.LOGV) {
             timeStart = System.currentTimeMillis();
diff --git a/core/java/android/nfc/ILlcpServiceSocket.aidl b/core/java/android/nfc/ILlcpServiceSocket.aidl
index c3108dc..581c21d 100644
--- a/core/java/android/nfc/ILlcpServiceSocket.aidl
+++ b/core/java/android/nfc/ILlcpServiceSocket.aidl
@@ -23,6 +23,4 @@
 {
     int accept(int nativeHandle);
     void close(int nativeHandle);
-    int getAcceptTimeout(int nativeHandle);
-    void setAcceptTimeout(int nativeHandle, int timeout);
 }
diff --git a/core/java/android/nfc/ILlcpSocket.aidl b/core/java/android/nfc/ILlcpSocket.aidl
index dda5628..3166e72 100644
--- a/core/java/android/nfc/ILlcpSocket.aidl
+++ b/core/java/android/nfc/ILlcpSocket.aidl
@@ -24,7 +24,6 @@
     int close(int nativeHandle);
     int connect(int nativeHandle, int sap);
     int connectByName(int nativeHandle, String sn);
-    int getConnectTimeout(int nativeHandle);
     int getLocalSap(int nativeHandle);
     int getLocalSocketMiu(int nativeHandle);
     int getLocalSocketRw(int nativeHandle);
@@ -32,5 +31,4 @@
     int getRemoteSocketRw(int nativeHandle);
     int receive(int nativeHandle, out byte[] receiveBuffer);
     int send(int nativeHandle, in byte[] data);
-    void setConnectTimeout(int nativeHandle, int timeout);
 }
\ No newline at end of file
diff --git a/core/java/android/nfc/NdefMessage.java b/core/java/android/nfc/NdefMessage.java
index d107b54..c79fabf 100644
--- a/core/java/android/nfc/NdefMessage.java
+++ b/core/java/android/nfc/NdefMessage.java
@@ -16,7 +16,6 @@
 
 package android.nfc;
 
-import android.nfc.NdefRecord;
 import android.os.Parcel;
 import android.os.Parcelable;
 
@@ -69,11 +68,10 @@
      * Returns a byte array representation of this entire NDEF message.
      */
     public byte[] toByteArray() {
-        //TODO: do not return null
         //TODO: allocate the byte array once, copy each record once
         //TODO: process MB and ME flags outside loop
         if ((mRecords == null) || (mRecords.length == 0))
-            return null;
+            return new byte[0];
 
         byte[] msg = {};
 
@@ -104,10 +102,12 @@
         return msg;
     }
 
+    @Override
     public int describeContents() {
         return 0;
     }
 
+    @Override
     public void writeToParcel(Parcel dest, int flags) {
         dest.writeInt(mRecords.length);
         dest.writeTypedArray(mRecords, flags);
@@ -115,12 +115,14 @@
 
     public static final Parcelable.Creator<NdefMessage> CREATOR =
             new Parcelable.Creator<NdefMessage>() {
+        @Override
         public NdefMessage createFromParcel(Parcel in) {
             int recordsLength = in.readInt();
             NdefRecord[] records = new NdefRecord[recordsLength];
             in.readTypedArray(records, NdefRecord.CREATOR);
             return new NdefMessage(records);
         }
+        @Override
         public NdefMessage[] newArray(int size) {
             return new NdefMessage[size];
         }
diff --git a/core/java/android/preference/VolumePreference.java b/core/java/android/preference/VolumePreference.java
index 970d520..66c9ba1 100644
--- a/core/java/android/preference/VolumePreference.java
+++ b/core/java/android/preference/VolumePreference.java
@@ -92,6 +92,11 @@
                     mSeekBarVolumizer.changeVolumeBy(1);
                 }
                 return true;
+            case KeyEvent.KEYCODE_VOLUME_MUTE:
+                if (isdown) {
+                    mSeekBarVolumizer.muteVolume();
+                }
+                return true;
             default:
                 return false;
         }
@@ -225,6 +230,7 @@
     
         private int mLastProgress = -1;
         private SeekBar mSeekBar;
+        private int mVolumeBeforeMute = -1;
         
         private ContentObserver mVolumeObserver = new ContentObserver(mHandler) {
             @Override
@@ -336,6 +342,21 @@
                 sample();
             }
             postSetVolume(mSeekBar.getProgress());
+            mVolumeBeforeMute = -1;
+        }
+
+        public void muteVolume() {
+            if (mVolumeBeforeMute != -1) {
+                mSeekBar.setProgress(mVolumeBeforeMute);
+                sample();
+                postSetVolume(mVolumeBeforeMute);
+                mVolumeBeforeMute = -1;
+            } else {
+                mVolumeBeforeMute = mSeekBar.getProgress();
+                mSeekBar.setProgress(0);
+                stopSample();
+                postSetVolume(0);
+            }
         }
 
         public void onSaveInstanceState(VolumeStore volumeStore) {
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 9e6434a..f0aa878 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -5245,7 +5245,7 @@
                         return com.android.internal.R.string.eventTypeAnniversary;
                     case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
                     case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
-                    default: return com.android.internal.R.string.eventTypeOther;
+                    default: return com.android.internal.R.string.eventTypeCustom;
                 }
             }
         }
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index ee53828..2229964 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1199,12 +1199,6 @@
          */
         public static final String WIFI_STATIC_DNS2 = "wifi_static_dns2";
 
-        /**
-         * The number of radio channels that are allowed in the local
-         * 802.11 regulatory domain.
-         * @hide
-         */
-        public static final String WIFI_NUM_ALLOWED_CHANNELS = "wifi_num_allowed_channels";
 
         /**
          * Determines whether remote devices may discover and/or connect to
@@ -2701,11 +2695,11 @@
                 "wifi_networks_available_repeat_delay";
 
         /**
-         * The number of radio channels that are allowed in the local
-         * 802.11 regulatory domain.
+         * 802.11 country code in ISO 3166 format
          * @hide
          */
-        public static final String WIFI_NUM_ALLOWED_CHANNELS = "wifi_num_allowed_channels";
+        public static final String WIFI_COUNTRY_CODE = "wifi_country_code";
+
 
         /**
          * When the number of open networks exceeds this number, the
@@ -3638,7 +3632,7 @@
             TTS_ENABLED_PLUGINS,
             WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
             WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
-            WIFI_NUM_ALLOWED_CHANNELS,
+            WIFI_COUNTRY_CODE,
             WIFI_NUM_OPEN_NETWORKS_KEPT,
             MOUNT_PLAY_NOTIFICATION_SND,
             MOUNT_UMS_AUTOSTART,
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 0e75682..04c331f 100755
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -125,9 +125,11 @@
     /** Key code constant: Directional Pad Center key.
      * May also be synthesized from trackball motions. */
     public static final int KEYCODE_DPAD_CENTER     = 23;
-    /** Key code constant: Volume Up key. */
+    /** Key code constant: Volume Up key.
+     * Adjusts the speaker volume up. */
     public static final int KEYCODE_VOLUME_UP       = 24;
-    /** Key code constant: Volume Down key. */
+    /** Key code constant: Volume Down key.
+     * Adjusts the speaker volume down. */
     public static final int KEYCODE_VOLUME_DOWN     = 25;
     /** Key code constant: Power key. */
     public static final int KEYCODE_POWER           = 26;
@@ -269,7 +271,8 @@
     public static final int KEYCODE_MEDIA_REWIND    = 89;
     /** Key code constant: Fast Forward media key. */
     public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;
-    /** Key code constant: Mute key. */
+    /** Key code constant: Mute key.
+     * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */
     public static final int KEYCODE_MUTE            = 91;
     /** Key code constant: Page Up key. */
     public static final int KEYCODE_PAGE_UP         = 92;
@@ -455,8 +458,13 @@
     public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162;
     /** Key code constant: Numeric keypad ')' key. */
     public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163;
+    /** Key code constant: Volume Mute key.
+     * Mutes the speaker, unlike {@link #KEYCODE_MUTE}.
+     * This key should normally be implemented as a toggle such that the first press
+     * mutes the speaker and the second press restores the original volume. */
+    public static final int KEYCODE_VOLUME_MUTE     = 164;
 
-    private static final int LAST_KEYCODE           = KEYCODE_NUMPAD_RIGHT_PAREN;
+    private static final int LAST_KEYCODE           = KEYCODE_VOLUME_MUTE;
 
     // NOTE: If you add a new keycode here you must also add it to:
     //  isSystem()
@@ -640,6 +648,7 @@
         "KEYCODE_NUMPAD_EQUALS",
         "KEYCODE_NUMPAD_LEFT_PAREN",
         "KEYCODE_NUMPAD_RIGHT_PAREN",
+        "KEYCODE_VOLUME_MUTE",
     };
 
     // Symbolic names of all metakeys in bit order from least significant to most significant.
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ab97569..a9f0780 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -6298,7 +6298,7 @@
             }
             final AttachInfo ai = mAttachInfo;
             final ViewParent p = mParent;
-            if (ai != null && ai.mHardwareAccelerated) {
+            if (p != null && ai != null && ai.mHardwareAccelerated) {
                 // fast-track for GL-enabled applications; just invalidate the whole hierarchy
                 // with a null dirty rect, which tells the ViewRoot to redraw everything
                 p.invalidateChild(this, null);
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index aef13ad..ad343a3 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -870,7 +870,7 @@
         switch (event.mAction) {
         case DragEvent.ACTION_DRAG_STARTED: {
             // clear state to recalculate which views we drag over
-            root.setDragFocus(event, null);
+            mCurrentDragView = null;
 
             // Now dispatch down to our children, caching the responses
             mChildAcceptsDrag = false;
@@ -915,11 +915,28 @@
             final View target = findFrontmostDroppableChildAt(event.mX, event.mY, mLocalPoint);
 
             // If we've changed apparent drag target, tell the view root which view
-            // we're over now.  This will in turn send out DRAG_ENTERED / DRAG_EXITED
-            // notifications as appropriate.
+            // we're over now [for purposes of the eventual drag-recipient-changed
+            // notifications to the framework] and tell the new target that the drag
+            // has entered its bounds.  The root will see setDragFocus() calls all
+            // the way down to the final leaf view that is handling the LOCATION event
+            // before reporting the new potential recipient to the framework.
             if (mCurrentDragView != target) {
-                root.setDragFocus(event, target);
+                root.setDragFocus(target);
+
+                final int action = event.mAction;
+                // If we've dragged off of a child view, send it the EXITED message
+                if (mCurrentDragView != null) {
+                    event.mAction = DragEvent.ACTION_DRAG_EXITED;
+                    mCurrentDragView.dispatchDragEvent(event);
+                }
                 mCurrentDragView = target;
+
+                // If we've dragged over a new child view, send it the ENTERED message
+                if (target != null) {
+                    event.mAction = DragEvent.ACTION_DRAG_ENTERED;
+                    target.dispatchDragEvent(event);
+                }
+                event.mAction = action;  // restore the event's original state
             }
 
             // Dispatch the actual drag location notice, localized into its coordinates
@@ -934,6 +951,25 @@
             }
         } break;
 
+        /* Entered / exited dispatch
+         *
+         * DRAG_ENTERED is not dispatched downwards from ViewGroup.  The reason for this is
+         * that we're about to get the corresponding LOCATION event, which we will use to
+         * determine which of our children is the new target; at that point we will
+         * push a DRAG_ENTERED down to the new target child [which may itself be a ViewGroup].
+         *
+         * DRAG_EXITED *is* dispatched all the way down immediately: once we know the
+         * drag has left this ViewGroup, we know by definition that every contained subview
+         * is also no longer under the drag point.
+         */
+
+        case DragEvent.ACTION_DRAG_EXITED: {
+            if (mCurrentDragView != null) {
+                mCurrentDragView.dispatchDragEvent(event);
+                mCurrentDragView = null;
+            }
+        } break;
+
         case DragEvent.ACTION_DROP: {
             if (ViewDebug.DEBUG_DRAG) Log.d(View.VIEW_LOG_TAG, "Drop event: " + event);
             View target = findFrontmostDroppableChildAt(event.mX, event.mY, mLocalPoint);
@@ -1298,8 +1334,9 @@
      * Returns true if a child view contains the specified point when transformed
      * into its coordinate space.
      * Child must not be null.
+     * @hide
      */
-    private boolean isTransformedTouchPointInView(float x, float y, View child,
+    protected boolean isTransformedTouchPointInView(float x, float y, View child,
             PointF outLocalPoint) {
         float localX = x + mScrollX - child.mLeft;
         float localY = y + mScrollY - child.mTop;
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 22a7773..c7c2071 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -2493,11 +2493,12 @@
                 // a window boundary, so the current drag target within this one must have
                 // just been exited.  Send it the usual notifications and then we're done
                 // for now.
-                setDragFocus(event, null);
+                mView.dispatchDragEvent(event);
             } else {
                 // Cache the drag description when the operation starts, then fill it in
                 // on subsequent calls as a convenience
                 if (what == DragEvent.ACTION_DRAG_STARTED) {
+                    mCurrentDragView = null;    // Start the current-recipient tracking
                     mDragDescription = event.mClipDescription;
                 } else {
                     event.mClipDescription = mDragDescription;
@@ -2557,22 +2558,10 @@
         outLocation.y = (int) mLastTouchPoint.y;
     }
 
-    public void setDragFocus(DragEvent event, View newDragTarget) {
-        final int action = event.mAction;
-        // If we've dragged off of a view, send it the EXITED message
+    public void setDragFocus(View newDragTarget) {
         if (mCurrentDragView != newDragTarget) {
-            if (mCurrentDragView != null) {
-                event.mAction = DragEvent.ACTION_DRAG_EXITED;
-                mCurrentDragView.dispatchDragEvent(event);
-            }
             mCurrentDragView = newDragTarget;
         }
-        // If we've dragged over a new view, send it the ENTERED message
-        if (newDragTarget != null) {
-            event.mAction = DragEvent.ACTION_DRAG_ENTERED;
-            newDragTarget.dispatchDragEvent(event);
-        }
-        event.mAction = action;  // restore the event's original state
     }
 
     private AudioManager getAudioManager() {
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 9a873b6..9edb267 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -472,6 +472,11 @@
      */
     private native int nativeRecordContent(Region invalRegion, Point wh);
 
+    /**
+     * Update the layers' content
+     */
+    private native int nativeUpdateLayers();
+
     private native boolean nativeFocusBoundsChanged();
 
     /**
@@ -798,6 +803,7 @@
             "FREE_MEMORY",  // = 145
             "VALID_NODE_BOUNDS", // = 146
             "SAVE_WEBARCHIVE", // = 147
+            "WEBKIT_DRAW_LAYERS", // = 148;
         };
 
     class EventHub {
@@ -868,6 +874,9 @@
         // Load and save web archives
         static final int SAVE_WEBARCHIVE = 147;
 
+        // Update layers
+        static final int WEBKIT_DRAW_LAYERS = 148;
+
         // Network-based messaging
         static final int CLEAR_SSL_PREF_TABLE = 150;
 
@@ -953,6 +962,10 @@
                             webkitDraw();
                             break;
 
+                        case WEBKIT_DRAW_LAYERS:
+                            webkitDrawLayers();
+                            break;
+
                         case DESTROY:
                             // Time to take down the world. Cancel all pending
                             // loads and destroy the native view and frame.
@@ -1800,6 +1813,7 @@
 
     // Used to avoid posting more than one draw message.
     private boolean mDrawIsScheduled;
+    private boolean mDrawLayersIsScheduled;
 
     // Used to avoid posting more than one split picture message.
     private boolean mSplitPictureIsScheduled;
@@ -1839,6 +1853,20 @@
         boolean mFocusSizeChanged;
     }
 
+    // Only update the layers' content, not the base surface
+    // PictureSet.
+    private void webkitDrawLayers() {
+        mDrawLayersIsScheduled = false;
+        if (mDrawIsScheduled) {
+            removeMessages(EventHub.WEBKIT_DRAW);
+            webkitDraw();
+            return;
+        }
+        DrawData draw = new DrawData();
+        draw.mBaseLayer = nativeUpdateLayers();
+        webkitDraw(draw);
+    }
+
     private void webkitDraw() {
         mDrawIsScheduled = false;
         DrawData draw = new DrawData();
@@ -1848,6 +1876,10 @@
             if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort");
             return;
         }
+        webkitDraw(draw);
+    }
+
+    private void webkitDraw(DrawData draw) {
         if (mWebView != null) {
             draw.mFocusSizeChanged = nativeFocusBoundsChanged();
             draw.mViewSize = new Point(mCurrentViewWidth, mCurrentViewHeight);
@@ -1957,6 +1989,15 @@
         }
     }
 
+    // called from JNI
+    void layersDraw() {
+        synchronized (this) {
+            if (mDrawLayersIsScheduled) return;
+            mDrawLayersIsScheduled = true;
+            mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW_LAYERS));
+        }
+    }
+
     // called by JNI
     private void contentScrollBy(int dx, int dy, boolean animate) {
         if (!mBrowserFrame.firstLayoutDone()) {
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index dd812d4..2235f0f 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -572,7 +572,11 @@
     }
 
     private void setZoomOverviewWidth(int width) {
-        mZoomOverviewWidth = width;
+        if (width == 0) {
+            mZoomOverviewWidth = WebView.DEFAULT_VIEWPORT_WIDTH;
+        } else {
+            mZoomOverviewWidth = width;
+        }
         mInvZoomOverviewWidth = 1.0f / width;
     }
 
@@ -807,7 +811,7 @@
                     Math.max((int) (viewWidth * mInvDefaultScale),
                             Math.max(drawData.mMinPrefWidth, drawData.mViewSize.x))));
             } else {
-                final int contentWidth = drawData.mContentSize.x;
+                final int contentWidth = Math.max(drawData.mContentSize.x, drawData.mViewSize.x);
                 setZoomOverviewWidth(Math.min(WebView.sMaxViewportWidth, contentWidth));
             }
         }
@@ -843,7 +847,7 @@
         updateZoomRange(viewState, viewSize.x, drawData.mMinPrefWidth);
         if (mWebView.getSettings().getUseWideViewPort() &&
             mWebView.getSettings().getUseFixedViewport()) {
-            final int contentWidth = drawData.mContentSize.x;
+            final int contentWidth = Math.max(drawData.mContentSize.x, drawData.mMinPrefWidth);
             setZoomOverviewWidth(Math.min(WebView.sMaxViewportWidth, contentWidth));
         }
 
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 728c2a7..4e90ecd 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -2501,7 +2501,7 @@
 
                     deltaY -= mMotionCorrection;
                     int incrementalDeltaY = mLastY != Integer.MIN_VALUE ? y - mLastY : deltaY;
-                    
+
                     // No need to do all this work if we're not going to move anyway
                     boolean atEdge = false;
                     if (incrementalDeltaY != 0) {
diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java
index 5ac047c..1f98c88 100644
--- a/core/java/android/widget/AdapterViewAnimator.java
+++ b/core/java/android/widget/AdapterViewAnimator.java
@@ -24,16 +24,16 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.TypedArray;
+import android.graphics.Rect;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.AttributeSet;
+import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewConfiguration;
 import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
 
 /**
  * Base class for a {@link AdapterView} that will perform animations
@@ -141,6 +141,20 @@
     ObjectAnimator mInAnimation;
     ObjectAnimator mOutAnimation;
 
+    /**
+     * Current touch state.
+     */
+    private int mTouchMode = TOUCH_MODE_NONE;
+
+    /**
+     * Private touch states.
+     */
+    static final int TOUCH_MODE_NONE = 0;
+    static final int TOUCH_MODE_DOWN_IN_CURRENT_VIEW = 1;
+    static final int TOUCH_MODE_HANDLED = 2;
+
+    private Runnable mPendingCheckForTap;
+
     private static final int DEFAULT_ANIMATION_DURATION = 200;
 
     public AdapterViewAnimator(Context context) {
@@ -528,7 +542,6 @@
             // above the layout will end up being ignored since we are currently laying out, so
             // we post a delayed requestLayout and invalidate
             mMainQueue.post(new Runnable() {
-                @Override
                 public void run() {
                     requestLayout();
                     invalidate();
@@ -551,6 +564,89 @@
         }
     }
 
+    void showTapFeedback(View v) {
+        v.setPressed(true);
+    }
+
+    void hideTapFeedback(View v) {
+        v.setPressed(false);
+    }
+
+    void cancelHandleClick() {
+        View v = getCurrentView();
+        if (v != null) {
+            hideTapFeedback(v);
+        }
+        mTouchMode = TOUCH_MODE_NONE;
+    }
+
+    final class CheckForTap implements Runnable {
+        public void run() {
+            if (mTouchMode == TOUCH_MODE_DOWN_IN_CURRENT_VIEW) {
+                View v = getCurrentView();
+                showTapFeedback(v);
+            }
+        }
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        int action = ev.getAction();
+        boolean handled = false;
+        switch (action) {
+            case MotionEvent.ACTION_DOWN: {
+                View v = getCurrentView();
+                if (v != null) {
+                    if (isTransformedTouchPointInView(ev.getX(), ev.getY(), v, null)) {
+                        if (mPendingCheckForTap == null) {
+                            mPendingCheckForTap = new CheckForTap();
+                        }
+                        mTouchMode = TOUCH_MODE_DOWN_IN_CURRENT_VIEW;
+                        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
+                    }
+                }
+                break;
+            }
+            case MotionEvent.ACTION_MOVE: break;
+            case MotionEvent.ACTION_POINTER_UP: break;
+            case MotionEvent.ACTION_UP: {
+                if (mTouchMode == TOUCH_MODE_DOWN_IN_CURRENT_VIEW) {
+                    final View v = getCurrentView();
+                    if (v != null) {
+                        if (isTransformedTouchPointInView(ev.getX(), ev.getY(), v, null)) {
+                            final Handler handler = getHandler();
+                            if (handler != null) {
+                                handler.removeCallbacks(mPendingCheckForTap);
+                            }
+                            showTapFeedback(v);
+                            postDelayed(new Runnable() {
+                                public void run() {
+                                    hideTapFeedback(v);
+                                    post(new Runnable() {
+                                        public void run() {
+                                            performItemClick(v, 0, 0);
+                                        }
+                                    });
+                                }
+                            }, ViewConfiguration.getPressedStateDuration());
+                            handled = true;
+                        }
+                    }
+                }
+                mTouchMode = TOUCH_MODE_NONE;
+                break;
+            }
+            case MotionEvent.ACTION_CANCEL: {
+                View v = getCurrentView();
+                if (v != null) {
+                    hideTapFeedback(v);
+                }
+                mTouchMode = TOUCH_MODE_NONE;
+            }
+        }
+        return handled;
+    }
+
     private void measureChildren() {
         final int count = getChildCount();
         final int childWidth = mMeasuredWidth - mPaddingLeft - mPaddingRight;
diff --git a/core/java/android/widget/MediaController.java b/core/java/android/widget/MediaController.java
index be1234d..27a6ad3 100644
--- a/core/java/android/widget/MediaController.java
+++ b/core/java/android/widget/MediaController.java
@@ -442,7 +442,8 @@
             }
             return true;
         } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
-                || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
+                || keyCode == KeyEvent.KEYCODE_VOLUME_UP
+                || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
             // don't show the controls for volume adjustment
             return super.dispatchKeyEvent(event);
         } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 6ba7b44..24165aa 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -45,6 +45,7 @@
 import android.view.ViewGroup;
 import android.view.LayoutInflater.Filter;
 import android.view.View.OnClickListener;
+import android.widget.AdapterView.OnItemClickListener;
 
 
 /**
@@ -110,7 +111,7 @@
             super(message);
         }
     }
-    
+
     /**
      * Base class for all actions that can be performed on an 
      * inflated view.
@@ -216,8 +217,9 @@
                         "only from RemoteViewsFactory (ie. on collection items).");
                 return;
             }
-
-            if (target != null && fillInIntent != null) {
+            if (target == root) {
+                target.setTagInternal(com.android.internal.R.id.fillInIntent, fillInIntent);
+            } else if (target != null && fillInIntent != null) {
                 OnClickListener listener = new OnClickListener() {
                     public void onClick(View v) {
                         // Insure that this view is a child of an AdapterView
@@ -237,14 +239,14 @@
                         // Insure that a template pending intent has been set on an ancestor
                         if (!(parent.getTag() instanceof PendingIntent)) {
                             Log.e("RemoteViews", "Attempting setOnClickFillInIntent without" +
-					" calling setPendingIntentTemplate on parent.");
+                                    " calling setPendingIntentTemplate on parent.");
                             return;
                         }
 
                         PendingIntent pendingIntent = (PendingIntent) parent.getTag();
 
                         final float appScale = v.getContext().getResources()
-                        .getCompatibilityInfo().applicationScale;
+                                .getCompatibilityInfo().applicationScale;
                         final int[] pos = new int[2];
                         v.getLocationOnScreen(pos);
 
@@ -269,88 +271,6 @@
         public final static int TAG = 9;
     }
 
-    private class SetOnClickExtras extends Action {
-        public SetOnClickExtras(int id, Bundle extras) {
-            this.viewId = id;
-            this.extras = extras;
-        }
-
-        public SetOnClickExtras(Parcel parcel) {
-            viewId = parcel.readInt();
-            extras = Bundle.CREATOR.createFromParcel(parcel);
-        }
-
-        public void writeToParcel(Parcel dest, int flags) {
-            dest.writeInt(TAG);
-            dest.writeInt(viewId);
-            extras.writeToParcel(dest, 0 /* no flags */);
-        }
-
-        @Override
-        public void apply(View root) {
-            final View target = root.findViewById(viewId);
-            if (target == null) return;
-
-            if (!mIsWidgetCollectionChild) {
-                Log.e("RemoteViews", "The method setOnClickExtras is available " +
-                        "only from RemoteViewsFactory (ie. on collection items).");
-                return;
-            }
-
-            if (target != null && extras != null) {
-                OnClickListener listener = new OnClickListener() {
-                    public void onClick(View v) {
-                        // Insure that this view is a child of an AdapterView
-                        View parent = (View) v.getParent();
-                        while (!(parent instanceof AdapterView<?>)
-                                && !(parent instanceof AppWidgetHostView)) {
-                            parent = (View) parent.getParent();
-                        }
-
-                        if (parent instanceof AppWidgetHostView) {
-                            // Somehow they've managed to get this far without having
-                            // and AdapterView as a parent.
-                            Log.e("RemoteViews", "Collection item doesn't have AdapterView parent");
-                            return;
-                        }
-
-                        // Insure that a template pending intent has been set on an ancestor
-                        if (!(parent.getTag() instanceof PendingIntent)) {
-                            Log.e("RemoteViews", "Attempting setOnClickExtras without calling " +
-                                "setPendingIntentTemplate on parent.");
-                            return;
-                        }
-
-                        PendingIntent pendingIntent = (PendingIntent) parent.getTag();
-
-                        final float appScale = v.getContext().getResources()
-                        .getCompatibilityInfo().applicationScale;
-                        final int[] pos = new int[2];
-                        v.getLocationOnScreen(pos);
-
-                        final Rect rect = new Rect();
-                        rect.left = (int) (pos[0] * appScale + 0.5f);
-                        rect.top = (int) (pos[1] * appScale + 0.5f);
-                        rect.right = (int) ((pos[0] + v.getWidth()) * appScale + 0.5f);
-                        rect.bottom = (int) ((pos[1] + v.getHeight()) * appScale + 0.5f);
-
-                        final Intent intent = new Intent();
-                        intent.setSourceBounds(rect);
-                        intent.putExtras(extras);
-                        startIntentSafely(v.getContext(), pendingIntent, intent);
-                    }
-
-                };
-                target.setOnClickListener(listener);
-            }
-        }
-
-        int viewId;
-        Bundle extras;
-
-        public final static int TAG = 7;
-    }
-
     private class SetPendingIntentTemplate extends Action {
         public SetPendingIntentTemplate(int id, PendingIntent pendingIntentTemplate) {
             this.viewId = id;
@@ -375,8 +295,52 @@
 
             // If the view isn't an AdapterView, setting a PendingIntent template doesn't make sense
             if (target instanceof AdapterView<?>) {
+                AdapterView<?> av = (AdapterView<?>) target;
                 // The PendingIntent template is stored in the view's tag.
-                target.setTag(pendingIntentTemplate);
+                OnItemClickListener listener = new OnItemClickListener() {
+                    public void onItemClick(AdapterView<?> parent, View view,
+                            int position, long id) {
+                        // The view should be a frame layout
+                        if (view instanceof ViewGroup) {
+                            ViewGroup vg = (ViewGroup) view;
+
+                            // AdapterViews contain their children in a frame
+                            // so we need to go one layer deeper here.
+                            if (parent instanceof AdapterViewAnimator) {
+                                vg = (ViewGroup) vg.getChildAt(0);
+                            }
+                            if (vg == null) return;
+
+                            Intent fillInIntent = null;
+                            int childCount = vg.getChildCount();
+                            for (int i = 0; i < childCount; i++) {
+                                Object tag = vg.getChildAt(i).getTag(com.android.internal.R.id.fillInIntent);
+                                if (tag instanceof Intent) {
+                                    fillInIntent = (Intent) tag;
+                                    break;
+                                }
+                            }
+                            if (fillInIntent == null) return;
+
+                            final float appScale = view.getContext().getResources()
+                                    .getCompatibilityInfo().applicationScale;
+                            final int[] pos = new int[2];
+                            view.getLocationOnScreen(pos);
+
+                            final Rect rect = new Rect();
+                            rect.left = (int) (pos[0] * appScale + 0.5f);
+                            rect.top = (int) (pos[1] * appScale + 0.5f);
+                            rect.right = (int) ((pos[0] + view.getWidth()) * appScale + 0.5f);
+                            rect.bottom = (int) ((pos[1] + view.getHeight()) * appScale + 0.5f);
+
+                            final Intent intent = new Intent();
+                            intent.setSourceBounds(rect);
+                            startIntentSafely(view.getContext(), pendingIntentTemplate, fillInIntent);
+                        }
+                    }
+                };
+                av.setOnItemClickListener(listener);
+                av.setTag(pendingIntentTemplate);
             } else {
                 Log.e("RemoteViews", "Cannot setPendingIntentTemplate on a view which is not" +
                         "an AdapterView (id: " + viewId + ")");
@@ -973,9 +937,6 @@
                 case SetEmptyView.TAG:
                     mActions.add(new SetEmptyView(parcel));
                     break;
-                case SetOnClickExtras.TAG:
-                    mActions.add(new SetOnClickExtras(parcel));
-                    break;
                 case SetPendingIntentTemplate.TAG:
                     mActions.add(new SetPendingIntentTemplate(parcel));
                     break;
@@ -1239,16 +1200,6 @@
     }
 
     /**
-     * Being deprecated. See {@link RemoteViews#setOnClickFillInIntent(int, Intent)}.
-     *
-     * @param viewId
-     * @param extras
-     */
-    public void setOnClickExtras(int viewId, Bundle extras) {
-        addAction(new SetOnClickExtras(viewId, extras));
-    }
-
-    /**
      * When using collections (eg. {@link ListView}, {@link StackView} etc.) in widgets, it is very
      * costly to set PendingIntents on the individual items, and is hence not permitted. Instead
      * a single PendingIntent template can be set on the collection, see {@link
diff --git a/core/java/android/widget/RemoteViewsAdapter.java b/core/java/android/widget/RemoteViewsAdapter.java
index 5c3561f..26eb57c 100644
--- a/core/java/android/widget/RemoteViewsAdapter.java
+++ b/core/java/android/widget/RemoteViewsAdapter.java
@@ -319,7 +319,7 @@
                 if (mUserLoadingView != null) {
                     // A user-specified loading view
                     View loadingView = mUserLoadingView.apply(parent.getContext(), parent);
-                    loadingView.setTag(new Integer(0));
+                    loadingView.setTagInternal(com.android.internal.R.id.rowTypeId, new Integer(0));
                     layout.addView(loadingView);
                 } else {
                     // A default loading view
@@ -741,8 +741,11 @@
      */
     private int getConvertViewTypeId(View convertView) {
         int typeId = -1;
-        if (convertView != null && convertView.getTag() != null) {
-            typeId = (Integer) convertView.getTag();
+        if (convertView != null) {
+            Object tag = convertView.getTag(com.android.internal.R.id.rowTypeId);
+            if (tag != null) {
+                typeId = (Integer) tag;
+            }
         }
         return typeId;
     }
@@ -781,7 +784,7 @@
 
                     // Otherwise, create a new view to be returned
                     View newView = rv.apply(context, parent);
-                    newView.setTag(new Integer(typeId));
+                    newView.setTagInternal(com.android.internal.R.id.rowTypeId, new Integer(typeId));
                     if (convertView != null) {
                         layout.removeAllViews();
                     } else {
diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java
index e6d5984..a27e1cc 100644
--- a/core/java/android/widget/StackView.java
+++ b/core/java/android/widget/StackView.java
@@ -429,11 +429,14 @@
 
             // We only register this gesture if we've made it this far without a problem
             mSwipeGestureType = swipeGestureType;
+            cancelHandleClick();
         }
     }
 
     @Override
     public boolean onTouchEvent(MotionEvent ev) {
+        super.onTouchEvent(ev);
+
         int action = ev.getAction();
         int pointerIndex = ev.findPointerIndex(mActivePointerId);
         if (pointerIndex == INVALID_POINTER) {
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 2fcae1c..81c2f65 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6901,7 +6901,7 @@
                 // Tapping outside stops selection mode, if any
                 stopSelectionActionMode();
 
-                if (mInsertionPointCursorController != null && mText.length() > 0) {
+                if (mInsertionPointCursorController != null) {
                     mInsertionPointCursorController.show();
                 }
             }
diff --git a/core/java/android/widget/VideoView.java b/core/java/android/widget/VideoView.java
index 2be7bca..ec31dd4 100644
--- a/core/java/android/widget/VideoView.java
+++ b/core/java/android/widget/VideoView.java
@@ -515,6 +515,7 @@
         boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK &&
                                      keyCode != KeyEvent.KEYCODE_VOLUME_UP &&
                                      keyCode != KeyEvent.KEYCODE_VOLUME_DOWN &&
+                                     keyCode != KeyEvent.KEYCODE_VOLUME_MUTE &&
                                      keyCode != KeyEvent.KEYCODE_MENU &&
                                      keyCode != KeyEvent.KEYCODE_CALL &&
                                      keyCode != KeyEvent.KEYCODE_ENDCALL;
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index f4a041c..1d612e2 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -255,7 +255,6 @@
 
     private void configureTab(Tab tab, int position) {
         final TabImpl tabi = (TabImpl) tab;
-        final boolean isFirstTab = mTabs.isEmpty();
         final ActionBar.TabListener callback = tabi.getCallback();
 
         if (callback == null) {
@@ -265,26 +264,38 @@
         tabi.setPosition(position);
         mTabs.add(position, tabi);
 
-        if (isFirstTab) {
-            final FragmentTransaction trans = mActivity.getFragmentManager().openTransaction();
-            mSelectedTab = tabi;
-            callback.onTabSelected(tab, trans);
-            if (!trans.isEmpty()) {
-                trans.commit();
-            }
+        final int count = mTabs.size();
+        for (int i = position + 1; i < count; i++) {
+            mTabs.get(i).setPosition(i);
         }
     }
 
     @Override
     public void addTab(Tab tab) {
-        mActionView.addTab(tab);
-        configureTab(tab, mTabs.size());
+        addTab(tab, mTabs.isEmpty());
     }
 
     @Override
     public void addTab(Tab tab, int position) {
-        mActionView.addTab(tab, position);
+        addTab(tab, position, mTabs.isEmpty());
+    }
+
+    @Override
+    public void addTab(Tab tab, boolean setSelected) {
+        mActionView.addTab(tab, setSelected);
+        configureTab(tab, mTabs.size());
+        if (setSelected) {
+            selectTab(tab);
+        }
+    }
+
+    @Override
+    public void addTab(Tab tab, int position, boolean setSelected) {
+        mActionView.addTab(tab, position, setSelected);
         configureTab(tab, position);
+        if (setSelected) {
+            selectTab(tab);
+        }
     }
 
     @Override
diff --git a/core/java/com/android/internal/nfc/LlcpServiceSocket.java b/core/java/com/android/internal/nfc/LlcpServiceSocket.java
index 318982b..d616860 100644
--- a/core/java/com/android/internal/nfc/LlcpServiceSocket.java
+++ b/core/java/com/android/internal/nfc/LlcpServiceSocket.java
@@ -122,34 +122,6 @@
 	}
 
 	/**
-	 * Set the timeout for the accept request
-	 *
-	 * @param timeout
-	 *            value of the timeout for the accept request
-	 */
-	public void setAcceptTimeout(int timeout) {
-		try {
-			mService.setAcceptTimeout(mHandle, timeout);
-		} catch (RemoteException e) {
-			Log.e(TAG, "RemoteException in setAcceptTimeout(): ", e);
-		}
-	}
-
-	/**
-	 * Get the timeout value of the accept request
-	 *
-	 * @return mTimeout
-	 */
-	public int getAcceptTimeout() {
-		try {
-			return mService.getAcceptTimeout(mHandle);
-		} catch (RemoteException e) {
-			Log.e(TAG, "RemoteException in getAcceptTimeout(): ", e);
-			return 0;
-		}
-	}
-
-	/**
 	 * Close the created Llcp Service socket
 	 */
 	public void close() {
diff --git a/core/java/com/android/internal/nfc/LlcpSocket.java b/core/java/com/android/internal/nfc/LlcpSocket.java
index b1b1320..73c09259 100644
--- a/core/java/com/android/internal/nfc/LlcpSocket.java
+++ b/core/java/com/android/internal/nfc/LlcpSocket.java
@@ -140,34 +140,6 @@
 	}
 
 	/**
-	 * Set the timeout for the connect request
-	 *
-	 * @param timeout
-	 *            timeout value for the connect request
-	 */
-	public void setConnectTimeout(int timeout) {
-		try {
-			mService.setConnectTimeout(mHandle, timeout);
-		} catch (RemoteException e) {
-			Log.e(TAG, "RemoteException in setConnectTimeout(): ", e);
-		}
-	}
-
-	/**
-	 * Get the timeout value of the connect request
-	 *
-	 * @return mTimeout
-	 */
-	public int getConnectTimeout() {
-		try {
-			return mService.getConnectTimeout(mHandle);
-		} catch (RemoteException e) {
-			Log.e(TAG, "RemoteException in getConnectTimeout(): ", e);
-			return 0;
-		}
-	}
-
-	/**
 	 * Disconnect request to the connected LLCP socket and close the created
 	 * socket.
 	 *
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index be96e48..95d6dd3 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -123,8 +123,6 @@
         }
     };
 
-    private OnClickListener mHomeClickListener = null;
-
     private OnClickListener mTabClickListener = null;
 
     public ActionBarView(Context context, AttributeSet attrs) {
@@ -169,9 +167,6 @@
 
         mHomeLayout = new LinearLayout(context, null,
                 com.android.internal.R.attr.actionButtonStyle);
-        mHomeLayout.setClickable(true);
-        mHomeLayout.setFocusable(true);
-        mHomeLayout.setOnClickListener(mHomeClickListener);
         mHomeLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                 LayoutParams.MATCH_PARENT));
 
@@ -207,18 +202,18 @@
 
         a.recycle();
         
-        if (mLogo != null || mIcon != null || mTitle != null) {
-            mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
-            mHomeClickListener = new OnClickListener() {
-                public void onClick(View v) {
-                    Context context = getContext();
-                    if (context instanceof Activity) {
-                        Activity activity = (Activity) context;
-                        activity.onOptionsItemSelected(mLogoNavItem);
-                    }
-                }
-            };
-        }
+        mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
+        mHomeLayout.setOnClickListener(new OnClickListener() {
+          public void onClick(View v) {
+            Context context = getContext();
+            if (context instanceof Activity) {
+              Activity activity = (Activity) context;
+              activity.onOptionsItemSelected(mLogoNavItem);
+            }
+          }
+        });
+        mHomeLayout.setClickable(true);
+        mHomeLayout.setFocusable(true);
     }
 
     @Override
@@ -468,22 +463,20 @@
         return tabView;
     }
 
-    public void addTab(ActionBar.Tab tab) {
+    public void addTab(ActionBar.Tab tab, boolean setSelected) {
         ensureTabsExist();
-        final boolean isFirst = mTabLayout.getChildCount() == 0;
         View tabView = createTabView(tab);
         mTabLayout.addView(tabView);
-        if (isFirst) {
+        if (setSelected) {
             tabView.setSelected(true);
         }
     }
 
-    public void addTab(ActionBar.Tab tab, int position) {
+    public void addTab(ActionBar.Tab tab, int position, boolean setSelected) {
         ensureTabsExist();
-        final boolean isFirst = mTabLayout.getChildCount() == 0;
         final TabView tabView = createTabView(tab);
         mTabLayout.addView(tabView, position);
-        if (isFirst) {
+        if (setSelected) {
             tabView.setSelected(true);
         }
     }
diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java
index 007e7b9..f80fbd8 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -129,6 +129,7 @@
     private long[] mVibePattern;
 
     private int mAspect;
+    private final Matrix mArrowMatrix = new Matrix();
 
     /**
      * Represents a cell in the 3 X 3 matrix of the unlock pattern view.
@@ -923,7 +924,6 @@
         // This assumes that the arrow image is drawn at 12:00 with it's top edge
         // coincident with the circle bitmap's top edge.
         Bitmap arrow = green ? mBitmapArrowGreenUp : mBitmapArrowRedUp;
-        Matrix matrix = new Matrix();
         final int cellWidth = mBitmapCircleDefault.getWidth();
         final int cellHeight = mBitmapCircleDefault.getHeight();
 
@@ -933,10 +933,10 @@
         final float angle = (float) Math.toDegrees(theta) + 90.0f;
 
         // compose matrix
-        matrix.setTranslate(leftX + offsetX, topY + offsetY); // transform to cell position
-        matrix.preRotate(angle, cellWidth / 2.0f, cellHeight / 2.0f);  // rotate about cell center
-        matrix.preTranslate((cellWidth - arrow.getWidth()) / 2.0f, 0.0f); // translate to 12:00 pos
-        canvas.drawBitmap(arrow, matrix, mPaint);
+        mArrowMatrix.setTranslate(leftX + offsetX, topY + offsetY); // transform to cell position
+        mArrowMatrix.preRotate(angle, cellWidth / 2.0f, cellHeight / 2.0f);  // rotate about cell center
+        mArrowMatrix.preTranslate((cellWidth - arrow.getWidth()) / 2.0f, 0.0f); // translate to 12:00 pos
+        canvas.drawBitmap(arrow, mArrowMatrix, mPaint);
     }
 
     /**
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 90a0243..3b2406c 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -146,6 +146,11 @@
             env->GetBooleanField(options, gOptions_shareableFieldID);
 }
 
+static bool optionsJustBounds(JNIEnv* env, jobject options) {
+    return options != NULL &&
+            env->GetBooleanField(options, gOptions_justBoundsFieldID);
+}
+
 static bool optionsReportSizeToVM(JNIEnv* env, jobject options) {
     return NULL == options ||
             !env->GetBooleanField(options, gOptions_nativeAllocFieldID);
@@ -183,7 +188,7 @@
     
     if (NULL != options) {
         sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
-        if (env->GetBooleanField(options, gOptions_justBoundsFieldID)) {
+        if (optionsJustBounds(env, options)) {
             mode = SkImageDecoder::kDecodeBounds_Mode;
         }
         // initialize these, in case we fail later on
@@ -415,13 +420,14 @@
     /*  If optionsShareable() we could decide to just wrap the java array and
         share it, but that means adding a globalref to the java array object
         and managing its lifetime. For now we just always copy the array's data
-        if optionsPurgeable().
+        if optionsPurgeable(), unless we're just decoding bounds.
      */
+    bool purgeable = optionsPurgeable(env, options)
+            && !optionsJustBounds(env, options);
     AutoJavaByteArray ar(env, byteArray);
-    SkStream* stream = new SkMemoryStream(ar.ptr() + offset, length,
-                                          optionsPurgeable(env, options));
+    SkStream* stream = new SkMemoryStream(ar.ptr() + offset, length, purgeable);
     SkAutoUnref aur(stream);
-    return doDecode(env, stream, NULL, options, true);
+    return doDecode(env, stream, NULL, options, purgeable);
 }
 
 static void nativeRequestCancel(JNIEnv*, jobject joptions) {
diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp
index a024420..0663e98 100644
--- a/core/jni/android_net_wifi_Wifi.cpp
+++ b/core/jni/android_net_wifi_Wifi.cpp
@@ -198,11 +198,25 @@
     env->ReleaseStringUTFChars(bssid, bssidStr);
 
     if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) {
-        return false;
+        return -1;
     }
     return doIntCommand(cmdstr);
 }
 
+static jboolean android_net_wifi_setCountryCodeCommand(JNIEnv* env, jobject clazz, jstring country)
+{
+    char cmdstr[BUF_SIZE];
+    jboolean isCopy;
+
+    const char *countryStr = env->GetStringUTFChars(country, &isCopy);
+    int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER COUNTRY %s", countryStr);
+    env->ReleaseStringUTFChars(country, countryStr);
+
+    if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) {
+        return false;
+    }
+    return doBooleanCommand(cmdstr, "OK");
+}
 
 static jboolean android_net_wifi_setNetworkVariableCommand(JNIEnv* env,
                                                            jobject clazz,
@@ -484,32 +498,6 @@
     return (jint)band;
 }
 
-static jboolean android_net_wifi_setNumAllowedChannelsCommand(JNIEnv* env, jobject clazz, jint numChannels)
-{
-    char cmdstr[BUF_SIZE];
-
-    int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER SCAN-CHANNELS %u", numChannels);
-    int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
-
-    return (jboolean)!cmdTooLong && doBooleanCommand(cmdstr, "OK");
-}
-
-static jint android_net_wifi_getNumAllowedChannelsCommand(JNIEnv* env, jobject clazz)
-{
-    char reply[BUF_SIZE];
-    int numChannels;
-
-    if (doCommand("DRIVER SCAN-CHANNELS", reply, sizeof(reply)) != 0) {
-        return -1;
-    }
-    // reply comes back in the form "Scan-Channels = X" where X is the
-    // number of channels
-    if (sscanf(reply, "%*s = %u", &numChannels) == 1)
-        return numChannels;
-    else
-        return -1;
-}
-
 static jboolean android_net_wifi_setBluetoothCoexistenceModeCommand(JNIEnv* env, jobject clazz, jint mode)
 {
     char cmdstr[BUF_SIZE];
@@ -645,8 +633,6 @@
     { "getPowerModeCommand", "()I", (void*) android_net_wifi_getPowerModeCommand },
     { "setBandCommand", "(I)Z", (void*) android_net_wifi_setBandCommand},
     { "getBandCommand", "()I", (void*) android_net_wifi_getBandCommand},
-    { "setNumAllowedChannelsCommand", "(I)Z", (void*) android_net_wifi_setNumAllowedChannelsCommand },
-    { "getNumAllowedChannelsCommand", "()I", (void*) android_net_wifi_getNumAllowedChannelsCommand },
     { "setBluetoothCoexistenceModeCommand", "(I)Z",
     		(void*) android_net_wifi_setBluetoothCoexistenceModeCommand },
     { "setBluetoothCoexistenceScanModeCommand", "(Z)Z",
@@ -668,6 +654,8 @@
         (void*) android_net_wifi_wpsPinFromDeviceCommand },
     { "setSuspendOptimizationsCommand", "(Z)Z",
         (void*) android_net_wifi_setSuspendOptimizationsCommand},
+    { "setCountryCodeCommand", "(Ljava/lang/String;)Z",
+        (void*) android_net_wifi_setCountryCodeCommand},
     { "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest },
     { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError },
 };
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 3635fab..3331e1b 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1315,7 +1315,7 @@
                 android:excludeFromRecents="true">
         </activity>
         <activity android:name="com.android.internal.app.RingtonePickerActivity"
-                android:theme="@style/Theme.Dialog.Alert"
+                android:theme="@style/Theme.Holo.Dialog.Alert"
                 android:excludeFromRecents="true"
                 android:multiprocess="true">
             <intent-filter>
diff --git a/core/res/res/drawable-mdpi/text_edit_paste_window.9.png b/core/res/res/drawable-mdpi/text_edit_paste_window.9.png
index 2738b62..6b98c13 100644
--- a/core/res/res/drawable-mdpi/text_edit_paste_window.9.png
+++ b/core/res/res/drawable-mdpi/text_edit_paste_window.9.png
Binary files differ
diff --git a/core/res/res/layout/text_edit_no_paste_window.xml b/core/res/res/layout/text_edit_no_paste_window.xml
index f288e6f6..d409d97 100644
--- a/core/res/res/layout/text_edit_no_paste_window.xml
+++ b/core/res/res/layout/text_edit_no_paste_window.xml
@@ -22,6 +22,10 @@
     <ImageView android:id="@+id/paste_icon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:paddingLeft="16dip"
+        android:paddingRight="8dip"
+        android:paddingTop="8dip"
+        android:paddingBottom="8dip"
         android:layout_centerVertical="true"
         android:background="@android:drawable/ic_menu_paste_dark"
     />
@@ -29,9 +33,14 @@
     <TextView android:id="@+id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:paddingLeft="0dip"
+        android:paddingRight="16dip"
+        android:paddingTop="8dip"
+        android:paddingBottom="8dip"
         android:layout_centerVertical="true"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:text="@android:string/pasteDisabled"
+        android:textColor="@android:color/dim_foreground_dark_inverse_disabled"
         android:layout_toRightOf="@id/paste_icon"
     />
 
diff --git a/core/res/res/layout/text_edit_paste_window.xml b/core/res/res/layout/text_edit_paste_window.xml
index ee2c4d2..d153365 100644
--- a/core/res/res/layout/text_edit_paste_window.xml
+++ b/core/res/res/layout/text_edit_paste_window.xml
@@ -22,6 +22,10 @@
     <ImageView android:id="@+id/paste_icon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:paddingLeft="16dip"
+        android:paddingRight="8dip"
+        android:paddingTop="8dip"
+        android:paddingBottom="8dip"
         android:layout_centerVertical="true"
         android:background="@android:drawable/ic_menu_paste_light"
     />
@@ -29,9 +33,14 @@
     <TextView android:id="@+id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:paddingLeft="0dip"
+        android:paddingRight="16dip"
+        android:paddingTop="8dip"
+        android:paddingBottom="8dip"
         android:layout_centerVertical="true"
         android:textAppearance="?android:attr/textAppearanceMediumInverse"
         android:text="@android:string/paste"
+        android:textColor="@android:color/black"
         android:layout_toRightOf="@id/paste_icon"
     />
 
diff --git a/core/res/res/raw/loaderror.html b/core/res/res/raw/loaderror.html
index fd3d766..565e8e9 100644
--- a/core/res/res/raw/loaderror.html
+++ b/core/res/res/raw/loaderror.html
@@ -1,7 +1,7 @@
 <html>
     <head>
         <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
-        <title>Web page not available</title>
+        <title>Webpage not available</title>
         <style type="text/css">
             body { margin-top: 0px; padding-top: 0px; }
             h2   { margin-top: 5px; padding-top: 0px; }
@@ -10,8 +10,8 @@
         <body>
 
             <img src="file:///android_asset/webkit/android-weberror.png" align="top" />
-            <h2>Web page not available</h2>
-            <p>The Web page at <a href="%s">%s</a> could not be loaded as:</p>
+            <h2>Webpage not available</h2>
+            <p>The webpage at <a href="%s">%s</a> could not be loaded because:</p>
             <!-- The %e is replaced by a localized error string -->
             <p>%e</p>
         </body>
diff --git a/core/res/res/raw/nodomain.html b/core/res/res/raw/nodomain.html
index a71dbcd..d757483 100644
--- a/core/res/res/raw/nodomain.html
+++ b/core/res/res/raw/nodomain.html
@@ -1,7 +1,7 @@
 <html>
     <head>
         <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
-        <title>Web page not available</title>
+        <title>Webpage not available</title>
         <style type="text/css">
             body { margin-top: 0px; padding-top: 0px; }
             h2   { margin-top: 5px; padding-top: 0px; }
@@ -10,18 +10,16 @@
         <body>
 
             <img src="file:///android_asset/webkit/android-weberror.png" align="top" />
-            <h2>Web page not available</h2>
-            <p>The Web page at <a href="%s">%s</a> might be
+            <h2>Webpage not available</h2>
+            <p>The webpage at <a href="%s">%s</a> might be
             temporarily down or it may have moved permanently to a new web
             address.</p>
 
-            <p><b>Here are some suggestions:</b></p>
+            <p><b>Suggestions:</b></p>
             <ul>
-                <li>Check to make sure your device has a signal and data
-                connection</li>
-                <li>Reload this web page later.</li>
-                <li>View a cached copy of the web page from Google</li>
-
+                <li>Make sure you have a data connection</li>
+                <li>Reload this webpage later</li>
+                <li>Check the address you entered</li>
             </ul>
         </body>
     </head>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 79131ba..a2fa1a3 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -1145,27 +1145,28 @@
         <enum name="KEYCODE_F10" value="140" />
         <enum name="KEYCODE_F11" value="141" />
         <enum name="KEYCODE_F12" value="142" />
-        <enum name="NUM_LOCK" value="143" />
-        <enum name="NUMPAD_0" value="144" />
-        <enum name="NUMPAD_1" value="145" />
-        <enum name="NUMPAD_2" value="146" />
-        <enum name="NUMPAD_3" value="147" />
-        <enum name="NUMPAD_4" value="148" />
-        <enum name="NUMPAD_5" value="149" />
-        <enum name="NUMPAD_6" value="150" />
-        <enum name="NUMPAD_7" value="151" />
-        <enum name="NUMPAD_8" value="152" />
-        <enum name="NUMPAD_9" value="153" />
-        <enum name="NUMPAD_DIVIDE" value="154" />
-        <enum name="NUMPAD_MULTIPLY" value="155" />
-        <enum name="NUMPAD_SUBTRACT" value="156" />
-        <enum name="NUMPAD_ADD" value="157" />
-        <enum name="NUMPAD_DOT" value="158" />
-        <enum name="NUMPAD_COMMA" value="159" />
-        <enum name="NUMPAD_ENTER" value="160" />
-        <enum name="NUMPAD_EQUALS" value="161" />
-        <enum name="NUMPAD_LEFT_PAREN" value="162" />
-        <enum name="NUMPAD_RIGHT_PAREN" value="163" />
+        <enum name="KEYCODE_NUM_LOCK" value="143" />
+        <enum name="KEYCODE_NUMPAD_0" value="144" />
+        <enum name="KEYCODE_NUMPAD_1" value="145" />
+        <enum name="KEYCODE_NUMPAD_2" value="146" />
+        <enum name="KEYCODE_NUMPAD_3" value="147" />
+        <enum name="KEYCODE_NUMPAD_4" value="148" />
+        <enum name="KEYCODE_NUMPAD_5" value="149" />
+        <enum name="KEYCODE_NUMPAD_6" value="150" />
+        <enum name="KEYCODE_NUMPAD_7" value="151" />
+        <enum name="KEYCODE_NUMPAD_8" value="152" />
+        <enum name="KEYCODE_NUMPAD_9" value="153" />
+        <enum name="KEYCODE_NUMPAD_DIVIDE" value="154" />
+        <enum name="KEYCODE_NUMPAD_MULTIPLY" value="155" />
+        <enum name="KEYCODE_NUMPAD_SUBTRACT" value="156" />
+        <enum name="KEYCODE_NUMPAD_ADD" value="157" />
+        <enum name="KEYCODE_NUMPAD_DOT" value="158" />
+        <enum name="KEYCODE_NUMPAD_COMMA" value="159" />
+        <enum name="KEYCODE_NUMPAD_ENTER" value="160" />
+        <enum name="KEYCODE_NUMPAD_EQUALS" value="161" />
+        <enum name="KEYCODE_NUMPAD_LEFT_PAREN" value="162" />
+        <enum name="KEYCODE_NUMPAD_RIGHT_PAREN" value="163" />
+        <enum name="KEYCODE_VOLUME_MUTE" value="164" />
     </attr>
 
     <!-- ***************************************************************** -->
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 065c10d..1ee8271 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -1445,7 +1445,8 @@
          <code>screen</code> tag, a child of <code>compatible-screens</code>,
          which is itseld a child of the root
          {@link #AndroidManifest manifest} tag. -->
-    <declare-styleable name="AndroidManifestCompatibleScreensScreen">
+    <declare-styleable name="AndroidManifestCompatibleScreensScreen"
+                       parent="AndroidManifest.AndroidManifestCompatibleScreens">
         <!-- Specifies a compatible screen size, as per the device
              configuration screen size bins. -->
         <attr name="screenSize">
diff --git a/core/res/res/values/ids.xml b/core/res/res/values/ids.xml
index 33cd100..b7f177f 100644
--- a/core/res/res/values/ids.xml
+++ b/core/res/res/values/ids.xml
@@ -70,4 +70,6 @@
   <item type="id" name="smallIcon" />
   <item type="id" name="custom" />
   <item type="id" name="home" />
+  <item type="id" name="fillInIntent" />
+  <item type="id" name="rowTypeId" />
 </resources>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index f905725..fd7e984 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1404,6 +1404,8 @@
   <public type="style" name="Theme.Holo.Light.Dialog" />
   <public type="style" name="Theme.Holo.Extended" />
   <public type="style" name="Theme.Holo.Light.Extended" />
+  <public type="style" name="Theme.Holo.Dialog.Alert" />
+  <public type="style" name="Theme.Holo.Light.Dialog.Alert" />
 
   <public type="style" name="Widget.ListPopupWindow" />
   <public type="style" name="Widget.PopupMenu" />
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index f8c7b69..1fd5146 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -257,7 +257,9 @@
     <string name="contentServiceTooManyDeletesNotificationDesc">Too many <xliff:g id="content_type">%s</xliff:g> deletes.</string>
 
     <!-- If MMS discovers there isn't much space left on the device, it will show a toast with this message. -->
-    <string name="low_memory">Phone storage is full! Delete some files to free space.</string>
+    <string name="low_memory" product="tablet">Tablet storage is full! Delete some files to free space.</string>
+    <!-- If MMS discovers there isn't much space left on the device, it will show a toast with this message. -->
+    <string name="low_memory" product="default">Phone storage is full! Delete some files to free space.</string>
 
 
     <!-- Display name for any time a piece of data refers to the owner of the phone. For example, this could be used in place of the phone's phone number. -->
@@ -265,7 +267,9 @@
 
     <!-- Power Dialog --> <skip />
     <!-- Title for the Phone Options dialog to lock the screen, turn off the phone etc. -->
-    <string name="power_dialog">Phone options</string>
+    <string name="power_dialog" product="tablet">Tablet options</string>
+    <!-- Title for the Phone Options dialog to lock the screen, turn off the phone etc. -->
+    <string name="power_dialog" product="default">Phone options</string>
     <!-- Button to turn on silent mode, within the Phone Options dialog -->
     <string name="silent_mode">Silent mode</string>
     <!-- Button to turn on the radio, within the Phone Options dialog -->
@@ -282,7 +286,10 @@
 
     <!-- Shutdown Confirmation Dialog.  When the user chooses to power off the phone, there will
          be a confirmation dialog.  This is the message. -->
-    <string name="shutdown_confirm">Your phone will shut down.</string>
+    <string name="shutdown_confirm" product="tablet">Your tablet will shut down.</string>
+    <!-- Shutdown Confirmation Dialog.  When the user chooses to power off the phone, there will
+         be a confirmation dialog.  This is the message. -->
+    <string name="shutdown_confirm" product="default">Your phone will shut down.</string>
 
     <!-- Shutdown Confirmation Dialog.  When the user chooses to power off the phone, it asks
          the user if they'd like to shut down.  This is the message.  This is used instead of
@@ -302,7 +309,9 @@
     <string name="no_recent_tasks">No recent applications.</string>
 
     <!-- Title of the Global Actions Dialog -->
-    <string name="global_actions">Phone options</string>
+    <string name="global_actions" product="tablet">Tablet options</string>
+    <!-- Title of the Global Actions Dialog -->
+    <string name="global_actions" product="default">Phone options</string>
 
     <!-- label for item that locks the phone in the phone options dialog -->
     <string name="global_action_lock">Screen lock</string>
@@ -349,7 +358,10 @@
     <!-- Title of a category of application permissions, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permgrouplab_personalInfo">Your personal information</string>
     <!-- Description of a category of application permissions, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permgroupdesc_personalInfo">Direct access to your contacts
+    <string name="permgroupdesc_personalInfo" product="tablet">Direct access to your contacts
+        and calendar stored on the tablet.</string>
+    <!-- Description of a category of application permissions, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permgroupdesc_personalInfo" product="default">Direct access to your contacts
         and calendar stored on the phone.</string>
 
     <!-- Title of a category of application permissions, listed so the user can choose whether they want to allow the application to do this. -->
@@ -449,14 +461,22 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_readSms">read SMS or MMS</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_readSms">Allows application to read
+    <string name="permdesc_readSms" product="tablet">Allows application to read
+      SMS messages stored on your tablet or SIM card. Malicious applications
+      may read your confidential messages.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_readSms" product="default">Allows application to read
       SMS messages stored on your phone or SIM card. Malicious applications
       may read your confidential messages.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_writeSms">edit SMS or MMS</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_writeSms">Allows application to write
+    <string name="permdesc_writeSms" product="tablet">Allows application to write
+      to SMS messages stored on your tablet or SIM card. Malicious applications
+      may delete your messages.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_writeSms" product="default">Allows application to write
       to SMS messages stored on your phone or SIM card. Malicious applications
       may delete your messages.</string>
 
@@ -548,7 +568,7 @@
         monitor and control how the system launches activities.
         Malicious applications may completely compromise the system. This
         permission is only needed for development, never for normal
-        phone usage.</string>
+        use.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_broadcastPackageRemoved">send package removed broadcast</string>
@@ -610,7 +630,7 @@
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_systemAlertWindow">Allows an application to
         show system alert windows. Malicious applications can take over the
-        entire screen of the phone.</string>
+        entire screen.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_setAnimationScale">modify global animation speed</string>
@@ -628,7 +648,11 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_injectEvents">press keys and control buttons</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_injectEvents">Allows an application to deliver
+    <string name="permdesc_injectEvents" product="tablet">Allows an application to deliver
+        its own input events (key presses, etc.) to other applications. Malicious
+        applications can use this to take over the tablet.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_injectEvents" product="default">Allows an application to deliver
         its own input events (key presses, etc.) to other applications. Malicious
         applications can use this to take over the phone.</string>
 
@@ -709,7 +733,11 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_clearAppCache">delete all application cache data</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_clearAppCache">Allows an application to free phone storage
+    <string name="permdesc_clearAppCache" product="tablet">Allows an application to free tablet storage
+        by deleting files in application cache directory. Access is very
+        restricted usually to system process.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_clearAppCache" product="default">Allows an application to free phone storage
         by deleting files in application cache directory. Access is very
         restricted usually to system process.</string>
 
@@ -721,7 +749,12 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_readLogs">read sensitive log data</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_readLogs">Allows an application to read from the
+    <string name="permdesc_readLogs" product="tablet">Allows an application to read from the
+        system\'s various log files.  This allows it to discover general
+        information about what you are doing with the tablet, potentially
+        including personal or private information.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_readLogs" product="default">Allows an application to read from the
         system\'s various log files.  This allows it to discover general
         information about what you are doing with the phone, potentially
         including personal or private information.</string>
@@ -737,9 +770,15 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_changeComponentState">enable or disable application components</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_changeComponentState">Allows an application to change whether a
+    <string name="permdesc_changeComponentState" product="tablet">Allows an application to change whether a
         component of another application is enabled or not. Malicious applications can use this
-        to disable important phone capabilities. Care must be used with permission, as it is
+        to disable important tablet capabilities. Care must be used with this permission, as it is
+        possible to get application components into an unusable, inconsistent, or unstable state.
+    </string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_changeComponentState" product="default">Allows an application to change whether a
+        component of another application is enabled or not. Malicious applications can use this
+        to disable important phone capabilities. Care must be used with this permission, as it is
         possible to get application components into an unusable, inconsistent, or unstable state.
     </string>
 
@@ -771,7 +810,12 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_receiveBootCompleted">automatically start at boot</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_receiveBootCompleted">Allows an application to
+    <string name="permdesc_receiveBootCompleted" product="tablet">Allows an application to
+        have itself started as soon as the system has finished booting.
+        This can make it take longer to start the tablet and allow the
+        application to slow down the overall tablet by always running.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_receiveBootCompleted" product="default">Allows an application to
         have itself started as soon as the system has finished booting.
         This can make it take longer to start the phone and allow the
         application to slow down the overall phone by always running.</string>
@@ -779,7 +823,12 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_broadcastSticky">send sticky broadcast</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_broadcastSticky">Allows an application to send
+    <string name="permdesc_broadcastSticky" product="tablet">Allows an application to send
+        sticky broadcasts, which remain after the broadcast ends.
+        Malicious applications can make the tablet slow or unstable by causing it
+        to use too much memory.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_broadcastSticky" product="default">Allows an application to send
         sticky broadcasts, which remain after the broadcast ends.
         Malicious applications can make the phone slow or unstable by causing it
         to use too much memory.</string>
@@ -787,21 +836,33 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_readContacts">read contact data</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_readContacts">Allows an application to read all
+    <string name="permdesc_readContacts" product="tablet">Allows an application to read all
+        of the contact (address) data stored on your tablet. Malicious applications
+        can use this to send your data to other people.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_readContacts" product="default">Allows an application to read all
         of the contact (address) data stored on your phone. Malicious applications
         can use this to send your data to other people.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_writeContacts">write contact data</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_writeContacts">Allows an application to modify the
+    <string name="permdesc_writeContacts" product="tablet">Allows an application to modify the
+        contact (address) data stored on your tablet. Malicious
+        applications can use this to erase or modify your contact data.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_writeContacts" product="default">Allows an application to modify the
         contact (address) data stored on your phone. Malicious
         applications can use this to erase or modify your contact data.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_readCalendar">read calendar events</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_readCalendar">Allows an application to read all
+    <string name="permdesc_readCalendar" product="tablet">Allows an application to read all
+        of the calendar events stored on your tablet. Malicious applications
+        can use this to send your calendar events to other people.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_readCalendar" product="default">Allows an application to read all
         of the calendar events stored on your phone. Malicious applications
         can use this to send your calendar events to other people.</string>
 
@@ -836,7 +897,12 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_accessFineLocation">fine (GPS) location</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_accessFineLocation">Access fine location sources such as the
+    <string name="permdesc_accessFineLocation" product="tablet">Access fine location sources such as the
+        Global Positioning System on the tablet, where available.
+        Malicious applications can use this to determine where you are, and may
+        consume additional battery power.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_accessFineLocation" product="default">Access fine location sources such as the
         Global Positioning System on the phone, where available.
         Malicious applications can use this to determine where you are, and may
         consume additional battery power.</string>
@@ -844,7 +910,11 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_accessCoarseLocation">coarse (network-based) location</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_accessCoarseLocation">Access coarse location sources such as the cellular
+    <string name="permdesc_accessCoarseLocation" product="tablet">Access coarse location sources such as the cellular
+        network database to determine an approximate tablet location, where available. Malicious
+        applications can use this to determine approximately where you are.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_accessCoarseLocation" product="default">Access coarse location sources such as the cellular
         network database to determine an approximate phone location, where available. Malicious
         applications can use this to determine approximately where you are.</string>
 
@@ -880,15 +950,25 @@
         images the camera is seeing.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_brick">permanently disable phone</string>
+    <string name="permlab_brick" product="tablet">permanently disable tablet</string>
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_brick" product="default">permanently disable phone</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_brick">Allows the application to
+    <string name="permdesc_brick" product="tablet">Allows the application to
+        disable the entire tablet permanently. This is very dangerous.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_brick" product="default">Allows the application to
         disable the entire phone permanently. This is very dangerous.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_reboot">force phone reboot</string>
+    <string name="permlab_reboot" product="tablet">force tablet reboot</string>
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_reboot" product="default">force phone reboot</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_reboot">Allows the application to
+    <string name="permdesc_reboot" product="tablet">Allows the application to
+        force the tablet to reboot.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_reboot" product="default">Allows the application to
         force the phone to reboot.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
@@ -967,7 +1047,9 @@
         services.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_performCdmaProvisioning">directly start CDMA phone setup</string>
+    <string name="permlab_performCdmaProvisioning" product="tablet">directly start CDMA tablet setup</string>
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_performCdmaProvisioning" product="default">directly start CDMA phone setup</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_performCdmaProvisioning">Allows the application to start CDMA provisioning.
         Malicious applications may unnecessarily start CDMA provisioning</string>
@@ -1010,21 +1092,35 @@
         is connected to and the like.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_wakeLock">prevent phone from sleeping</string>
+    <string name="permlab_wakeLock" product="tablet">prevent tablet from sleeping</string>
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_wakeLock" product="default">prevent phone from sleeping</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_wakeLock">Allows an application to prevent
+    <string name="permdesc_wakeLock" product="tablet">Allows an application to prevent
+        the tablet from going to sleep.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_wakeLock" product="default">Allows an application to prevent
         the phone from going to sleep.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_devicePower">power phone on or off</string>
+    <string name="permlab_devicePower" product="tablet">power tablet on or off</string>
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_devicePower" product="default">power phone on or off</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_devicePower">Allows the application to turn the
+    <string name="permdesc_devicePower" product="tablet">Allows the application to turn the
+        tablet on or off.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_devicePower" product="default">Allows the application to turn the
         phone on or off.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_factoryTest">run in factory test mode</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_factoryTest">Run as a low-level manufacturer test,
+    <string name="permdesc_factoryTest" product="tablet">Run as a low-level manufacturer test,
+        allowing complete access to the tablet hardware. Only available
+        when a tablet is running in manufacturer test mode.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_factoryTest" product="default">Run as a low-level manufacturer test,
         allowing complete access to the phone hardware. Only available
         when a phone is running in manufacturer test mode.</string>
 
@@ -1050,13 +1146,19 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_setTime">set time</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_setTime">Allows an application to change
+    <string name="permdesc_setTime" product="tablet">Allows an application to change
+        the tablet\'s clock time.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_setTime" product="default">Allows an application to change
         the phone\'s clock time.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_setTimeZone">set time zone</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_setTimeZone">Allows an application to change
+    <string name="permdesc_setTimeZone" product="tablet">Allows an application to change
+        the tablet\'s time zone.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_setTimeZone" product="default">Allows an application to change
         the phone\'s time zone.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
@@ -1068,7 +1170,10 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_getAccounts">discover known accounts</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_getAccounts">Allows an application to get
+    <string name="permdesc_getAccounts" product="tablet">Allows an application to get
+      the list of accounts known by the tablet.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_getAccounts" product="default">Allows an application to get
       the list of accounts known by the phone.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
@@ -1154,14 +1259,22 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_bluetoothAdmin">bluetooth administration</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_bluetoothAdmin">Allows an application to configure
+    <string name="permdesc_bluetoothAdmin" product="tablet">Allows an application to configure
+      the local Bluetooth tablet, and to discover and pair with remote
+      devices.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_bluetoothAdmin" product="default">Allows an application to configure
       the local Bluetooth phone, and to discover and pair with remote
       devices.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_bluetooth">create Bluetooth connections</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_bluetooth">Allows an application to view
+    <string name="permdesc_bluetooth" product="tablet">Allows an application to view
+      configuration of the local Bluetooth tablet, and to make and accept
+      connections with paired devices.</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_bluetooth" product="default">Allows an application to view
       configuration of the local Bluetooth phone, and to make and accept
       connections with paired devices.</string>
 
@@ -1172,7 +1285,6 @@
       with Near Field Communication (NFC) tags, cards, and readers.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_disableKeyguard">disable keylock</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_disableKeyguard">Allows an application to disable
       the keylock and any associated password security. A legitimate example of
@@ -1255,7 +1367,11 @@
     <!-- Title of policy access to watch user login attempts -->
     <string name="policylab_watchLogin">Monitor screen-unlock attempts</string>
     <!-- Description of policy access to watch user login attempts -->
-    <string name="policydesc_watchLogin">Monitor the number of incorrect passwords 
+    <string name="policydesc_watchLogin" product="tablet">Monitor the number of incorrect passwords 
+    entered when unlocking the screen, and lock the tablet or erase all the tablet\'s 
+    data if too many incorrect passwords are entered</string>
+    <!-- Description of policy access to watch user login attempts -->
+    <string name="policydesc_watchLogin" product="default">Monitor the number of incorrect passwords 
     entered when unlocking the screen, and lock the phone or erase all the phone\'s 
     data if too many incorrect passwords are entered</string>
     <!-- Title of policy access to reset user's password -->
@@ -1269,7 +1385,10 @@
     <!-- Title of policy access to wipe the user's data -->
     <string name="policylab_wipeData">Erase all data</string>
     <!-- Description of policy access to wipe the user's data -->
-    <string name="policydesc_wipeData">Erase the phone\'s data without warning, 
+    <string name="policydesc_wipeData" product="tablet">Erase the tablet\'s data without warning, 
+    by performing a factory data reset</string>
+    <!-- Description of policy access to wipe the user's data -->
+    <string name="policydesc_wipeData" product="default">Erase the phone\'s data without warning, 
     by performing a factory data reset</string>
     <string name="policylab_setGlobalProxy">Set the device global proxy</string>
     <!-- Description of policy access to wipe the user's data -->
@@ -1381,12 +1500,14 @@
     <!-- MMS phone number type -->
     <string name="phoneTypeMms">MMS</string>
 
-    <!-- Label for a birthday event -->
+    <!-- Label for custom events  [CHAR LIMIT=20] -->
+    <string name="eventTypeCustom">Custom</string>
+    <!-- Label for a birthday event  [CHAR LIMIT=20] -->
     <string name="eventTypeBirthday">Birthday</string>
-    <!-- Label for an anniversary event -->
+    <!-- Label for an anniversary event  [CHAR LIMIT=20] -->
     <string name="eventTypeAnniversary">Anniversary</string>
-    <!-- Label for other events -->
-    <string name="eventTypeOther">Event</string>
+    <!-- Label for other events  [CHAR LIMIT=20] -->
+    <string name="eventTypeOther">Other</string>
 
     <!-- Custom email type -->
     <string name="emailTypeCustom">Custom</string>
@@ -1552,7 +1673,9 @@
     <!-- Shown in the lock screen when there is no SIM card. -->
     <string name="lockscreen_missing_sim_message_short">No SIM card.</string>
     <!-- Shown in the lock screen when there is no SIM card. -->
-    <string name="lockscreen_missing_sim_message">No SIM card in phone.</string>
+    <string name="lockscreen_missing_sim_message" product="tablet">No SIM card in tablet.</string>
+    <!-- Shown in the lock screen when there is no SIM card. -->
+    <string name="lockscreen_missing_sim_message" product="default">No SIM card in phone.</string>
     <!-- Shown in the lock screen to ask the user to insert a SIM card. -->
     <string name="lockscreen_missing_sim_instructions">Please insert a SIM card.</string>
 
@@ -1601,7 +1724,15 @@
 
     <!-- For the unlock screen, Information message shown in dialog when user is almost at the limit
          where they will be locked out and may have to enter an alternate username/password to unlock the phone -->
-    <string name="lockscreen_failed_attempts_almost_glogin">
+    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet">
+        You have incorrectly drawn your unlock pattern <xliff:g id="number">%d</xliff:g> times.
+       After <xliff:g id="number">%d</xliff:g> more unsuccessful attempts,
+       you will be asked to unlock your tablet using your Google sign-in.\n\n
+       Please try again in <xliff:g id="number">%d</xliff:g> seconds.
+    </string>
+    <!-- For the unlock screen, Information message shown in dialog when user is almost at the limit
+         where they will be locked out and may have to enter an alternate username/password to unlock the phone -->
+    <string name="lockscreen_failed_attempts_almost_glogin" product="default">
         You have incorrectly drawn your unlock pattern <xliff:g id="number">%d</xliff:g> times.
        After <xliff:g id="number">%d</xliff:g> more unsuccessful attempts,
        you will be asked to unlock your phone using your Google sign-in.\n\n
@@ -1716,7 +1847,12 @@
     <string name="permlab_writeHistoryBookmarks">write Browser\'s history and bookmarks</string>
     <!-- Description of an application permission, listed so the user can choose whether
         they want to allow the application to do this. -->
-    <string name="permdesc_writeHistoryBookmarks">Allows an application to modify the
+    <string name="permdesc_writeHistoryBookmarks" product="tablet">Allows an application to modify the
+        Browser\'s history or bookmarks stored on your tablet. Malicious applications
+        can use this to erase or modify your Browser\'s data.</string>
+    <!-- Description of an application permission, listed so the user can choose whether
+        they want to allow the application to do this. -->
+    <string name="permdesc_writeHistoryBookmarks" product="default">Allows an application to modify the
         Browser\'s history or bookmarks stored on your phone. Malicious applications
         can use this to erase or modify your Browser\'s data.</string>
 
@@ -1990,7 +2126,9 @@
     <!-- If the device is getting low on internal storage, a notification is shown to the user.  This is the title of that notification. -->
     <string name="low_internal_storage_view_title">Low on space</string>
     <!-- If the device is getting low on internal storage, a notification is shown to the user.  This is the message of that notification. -->
-    <string name="low_internal_storage_view_text">Phone storage space is getting low.</string>
+    <string name="low_internal_storage_view_text" product="tablet">Tablet storage space is getting low.</string>
+    <!-- If the device is getting low on internal storage, a notification is shown to the user.  This is the message of that notification. -->
+    <string name="low_internal_storage_view_text" product="default">Phone storage space is getting low.</string>
 
     <!-- Preference framework strings. -->
     <string name="ok">OK</string>
@@ -2167,9 +2305,11 @@
     <!-- See USB_STORAGE.  USB_STORAGE_DIALOG:  After the user selects the notification, a dialog is shown asking if he wants to mount.  This is the title. -->
     <string name="usb_storage_title">USB connected</string>
     <!-- See USB_STORAGE.    This is the message. [CHAR LIMIT=NONE] -->
-    <string name="usb_storage_message" product="nosdcard">You have connected your phone to your computer via USB. Select the button below if you want to copy files between your computer and your Android\u2018s USB storage.</string>
+    <string name="usb_storage_message" product="tablet">You have connected your tablet to your computer via USB. Touch the button below if you want to copy files between your computer and your Android\u2018s USB storage.</string>
+    <!-- See USB_STORAGE.    This is the message. [CHAR LIMIT=NONE] -->
+    <string name="usb_storage_message" product="nosdcard">You have connected your phone to your computer via USB. Touch the button below if you want to copy files between your computer and your Android\u2018s USB storage.</string>
     <!-- See USB_STORAGE.    This is the message. -->
-    <string name="usb_storage_message" product="default">You have connected your phone to your computer via USB. Select the button below if you want to copy files between your computer and your Android\u2018s SD card.</string>
+    <string name="usb_storage_message" product="default">You have connected your phone to your computer via USB. Touch the button below if you want to copy files between your computer and your Android\u2018s SD card.</string>
     <!-- See USB_STORAGE.    This is the button text to mount the phone on the computer. -->
     <string name="usb_storage_button_mount">Turn on USB storage</string>
     <!-- See USB_STORAGE_DIALOG.  If there was an error mounting, this is the text. [CHAR LIMIT=NONE] -->
@@ -2343,10 +2483,9 @@
     <!-- This string appears (on two lines) when you type a number into contacts search, to let you create a contact whose phone number is the number you typed.  The first line will be in bigger type than the second. -->
     <string name="create_contact_using">Create contact\nusing <xliff:g id="number" example="555">%s</xliff:g></string>
 
-    <!-- This string array should be overridden by the manufacture to present a list of carrier-id,locale,wifi-channel sets.  This is used at startup to set system defaults by checking the system property ro.carrier for the carrier-id and searching through this array -->
+    <!-- This string array should be overridden by the manufacture to present a list of carrier-id,locale. The wifi regulatory domain is extracted from the locale information. This is used at startup to set system defaults by checking the system property ro.carrier for the carrier-id and searching through this array -->
     <!-- An Array of [[Carrier-ID]                     -->
-    <!--              [default-locale]                 -->
-    <!--              [default-wifi-allowed-channels]] -->
+    <!--              [default-locale]]                -->
     <string-array translatable="false" name="carrier_properties">
     </string-array>
 
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
index 6adfc74..3a78f26 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
@@ -20,6 +20,7 @@
 import android.test.InstrumentationTestRunner;
 import android.test.InstrumentationTestSuite;
 import android.util.Log;
+import com.android.connectivitymanagertest.unit.WifiClientTest;
 import com.android.connectivitymanagertest.unit.WifiSoftAPTest;
 
 import junit.framework.TestSuite;
@@ -35,6 +36,7 @@
     @Override
     public TestSuite getAllTests() {
         TestSuite suite = new InstrumentationTestSuite(this);
+        suite.addTestSuite(WifiClientTest.class);
         suite.addTestSuite(WifiSoftAPTest.class);
         return suite;
     }
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
new file mode 100644
index 0000000..6717bda
--- /dev/null
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.android.connectivitymanagertest.unit;
+
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.content.Context;
+import android.app.Instrumentation;
+import android.os.Handler;
+import android.os.Message;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiConfiguration.KeyMgmt;
+import android.net.wifi.WifiConfiguration.Status;
+
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.util.Log;
+
+/**
+ * Test wifi client
+ */
+public class WifiClientTest extends AndroidTestCase {
+
+    private WifiManager mWifiManager;
+    private final String TAG = "WifiClientTest";
+
+    //10s delay for turning on wifi
+    private static final int DELAY = 10000;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+        mWifiManager.setWifiEnabled(true);
+        assertNotNull(mWifiManager);
+    }
+
+    private void sleepAfterWifiEnable() {
+        try {
+            Thread.sleep(DELAY);
+        } catch (Exception e) {
+            fail("Sleep timeout " + e);
+        }
+    }
+
+    // Test case 1: add/remove a open network
+    @LargeTest
+    public void testAddRemoveNetwork() {
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = "\"TestSSID1\"";
+        config.allowedKeyManagement.set(KeyMgmt.NONE);
+
+        //add
+        int netId = mWifiManager.addNetwork(config);
+        assertTrue(netId != -1);
+
+        //check config list
+        List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
+        boolean found = false;
+        for (WifiConfiguration c : configList) {
+            if (c.networkId == netId) {
+                found = true;
+            }
+        }
+        assertTrue(found);
+
+        //remove
+        boolean ret = mWifiManager.removeNetwork(netId);
+        assertTrue(ret);
+
+        //check config list
+        configList = mWifiManager.getConfiguredNetworks();
+        found = false;
+        for (WifiConfiguration c : configList) {
+            if (c.networkId == netId) {
+                found = true;
+            }
+        }
+
+        assertFalse(found);
+    }
+
+    // Test case 2: enable/disable a open network
+    @LargeTest
+    public void testEnableDisableNetwork() {
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = "\"TestSSID2\"";
+        config.allowedKeyManagement.set(KeyMgmt.NONE);
+
+        //add
+        int netId = mWifiManager.addNetwork(config);
+        assertTrue(netId != -1);
+
+        //enable network and disable others
+        boolean ret = mWifiManager.enableNetwork(netId, true);
+        assertTrue(ret);
+
+        //check config list
+        List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
+        for (WifiConfiguration c : configList) {
+            if (c.networkId == netId) {
+                assertTrue(c.status == Status.ENABLED);
+            } else {
+                assertFalse(c.status == Status.ENABLED);
+            }
+        }
+
+        //disable network
+        ret = mWifiManager.disableNetwork(netId);
+        assertTrue(ret);
+
+        //check config list
+        configList = mWifiManager.getConfiguredNetworks();
+        for (WifiConfiguration c : configList) {
+            if (c.networkId == netId) {
+                assertTrue(c.status == Status.DISABLED);
+            }
+        }
+    }
+
+    // Test case 3: ping supplicant
+    @LargeTest
+    public void testPingSupplicant() {
+        assertTrue(mWifiManager.pingSupplicant());
+        mWifiManager.setWifiEnabled(false);
+        sleepAfterWifiEnable();
+
+        assertFalse(mWifiManager.pingSupplicant());
+        mWifiManager.setWifiEnabled(true);
+        sleepAfterWifiEnable();
+    }
+
+    // Test case 4: save config
+    @LargeTest
+    public void testSaveConfig() {
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = "\"TestSSID3\"";
+        config.allowedKeyManagement.set(KeyMgmt.NONE);
+
+        //add
+        int netId = mWifiManager.addNetwork(config);
+        assertTrue(netId != -1);
+
+        mWifiManager.saveConfiguration();
+
+        //restart wifi
+        mWifiManager.setWifiEnabled(false);
+        mWifiManager.setWifiEnabled(true);
+
+        sleepAfterWifiEnable();
+
+        //check config list
+        List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
+        boolean found = false;
+        for (WifiConfiguration c : configList) {
+            if (c.SSID.equals("TestSSID3")) {
+                found = true;
+            }
+        }
+        assertTrue(found);
+
+        //restore config
+        boolean ret = mWifiManager.removeNetwork(netId);
+        assertTrue(ret);
+        mWifiManager.saveConfiguration();
+    }
+}
diff --git a/core/tests/coretests/res/raw/obb_enc_file100_orig1.obb b/core/tests/coretests/res/raw/obb_enc_file100_orig1.obb
new file mode 100644
index 0000000..373b8e4
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_enc_file100_orig1.obb
Binary files differ
diff --git a/core/tests/coretests/res/raw/obb_enc_file100_orig3.obb b/core/tests/coretests/res/raw/obb_enc_file100_orig3.obb
new file mode 100644
index 0000000..aa531d8
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_enc_file100_orig3.obb
Binary files differ
diff --git a/core/tests/coretests/res/raw/obb_file1.obb b/core/tests/coretests/res/raw/obb_file1.obb
new file mode 100644
index 0000000..e71a680
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_file1.obb
Binary files differ
diff --git a/core/tests/coretests/res/raw/obb_file2.obb b/core/tests/coretests/res/raw/obb_file2.obb
new file mode 100644
index 0000000..1c397df
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_file2.obb
Binary files differ
diff --git a/core/tests/coretests/res/raw/obb_file2_nosign.obb b/core/tests/coretests/res/raw/obb_file2_nosign.obb
new file mode 100644
index 0000000..8292361
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_file2_nosign.obb
Binary files differ
diff --git a/core/tests/coretests/res/raw/obb_file3.obb b/core/tests/coretests/res/raw/obb_file3.obb
new file mode 100644
index 0000000..7f97a88
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_file3.obb
Binary files differ
diff --git a/core/tests/coretests/res/raw/obb_file3_bad_packagename.obb b/core/tests/coretests/res/raw/obb_file3_bad_packagename.obb
new file mode 100644
index 0000000..baa714a
--- /dev/null
+++ b/core/tests/coretests/res/raw/obb_file3_bad_packagename.obb
Binary files differ
diff --git a/core/tests/coretests/src/android/app/DownloadManagerBaseTest.java b/core/tests/coretests/src/android/app/DownloadManagerBaseTest.java
index 340137c..8df37ad 100644
--- a/core/tests/coretests/src/android/app/DownloadManagerBaseTest.java
+++ b/core/tests/coretests/src/android/app/DownloadManagerBaseTest.java
@@ -83,6 +83,7 @@
 
     protected static final int WAIT_FOR_DOWNLOAD_POLL_TIME = 1 * 1000;  // 1 second
     protected static final int MAX_WAIT_FOR_DOWNLOAD_TIME = 5 * 60 * 1000; // 5 minutes
+    protected static final int MAX_WAIT_FOR_LARGE_DOWNLOAD_TIME = 15 * 60 * 1000; // 15 minutes
 
     // Just a few popular file types used to return from a download
     protected enum DownloadFileType {
@@ -180,7 +181,7 @@
          * @return A Set<Long> with the ids of the completed downloads.
          */
         public Set<Long> getDownloadIds() {
-            synchronized(downloadIds) {
+            synchronized(this) {
                 Set<Long> returnIds = new HashSet<Long>(downloadIds);
                 return returnIds;
             }
@@ -224,6 +225,7 @@
             ConnectivityManager connManager = (ConnectivityManager)mContext.getSystemService(
                     Context.CONNECTIVITY_SERVICE);
             NetworkInfo info = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+            Log.i(LOG_TAG, "WiFi Connection state is currently: " + info.isConnected());
             return info.isConnected();
         }
     }
@@ -511,6 +513,7 @@
      * @param enable true if it should be enabled, false if it should be disabled
      */
     protected void setWiFiStateOn(boolean enable) throws Exception {
+        Log.i(LOG_TAG, "Setting WiFi State to: " + enable);
         WifiManager manager = (WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
 
         manager.setWifiEnabled(enable);
@@ -528,7 +531,7 @@
 
             while (receiver.getWiFiIsOn() != enable && !timedOut) {
                 try {
-                    receiver.wait(DEFAULT_MAX_WAIT_TIME);
+                    receiver.wait(DEFAULT_WAIT_POLL_TIME);
 
                     if (SystemClock.elapsedRealtime() > timeoutTime) {
                         timedOut = true;
diff --git a/core/tests/coretests/src/android/app/DownloadManagerStressTest.java b/core/tests/coretests/src/android/app/DownloadManagerStressTest.java
index ddf138f..e0b28d0 100644
--- a/core/tests/coretests/src/android/app/DownloadManagerStressTest.java
+++ b/core/tests/coretests/src/android/app/DownloadManagerStressTest.java
@@ -24,7 +24,6 @@
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.ParcelFileDescriptor;
-import android.test.suitebuilder.annotation.LargeTest;
 import android.util.Log;
 
 
@@ -38,6 +37,7 @@
     public void setUp() throws Exception {
         super.setUp();
         mServer.play(0);
+        setWiFiStateOn(true);
         removeAllCurrentDownloads();
     }
 
@@ -71,7 +71,8 @@
             }
 
             // wait for the download to complete or timeout
-            waitForDownloadsOrTimeout(WAIT_FOR_DOWNLOAD_POLL_TIME, MAX_WAIT_FOR_DOWNLOAD_TIME);
+            waitForDownloadsOrTimeout(WAIT_FOR_DOWNLOAD_POLL_TIME,
+                    MAX_WAIT_FOR_LARGE_DOWNLOAD_TIME);
             cursor = mDownloadManager.query(new Query());
             assertEquals(NUM_FILES, cursor.getCount());
             Log.i(LOG_TAG, "Verified number of downloads in download manager is what we expect.");
@@ -130,10 +131,11 @@
     }
 
     /**
-     * Tests trying to download a large file (~300M bytes) when there's not enough space in cache
+     * Tests trying to download a large file (~600M bytes) when there's not enough space in cache
      */
     public void testInsufficientSpace() throws Exception {
-        long fileSize = 300000000L;
+        // @TODO: Rework this to fill up cache partition with a dynamically calculated size
+        long fileSize = 600000000L;
         File largeFile = createFileOnSD(null, fileSize, DataType.TEXT, null);
 
         Cursor cursor = null;
diff --git a/core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java b/core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java
new file mode 100644
index 0000000..90cb9a5
--- /dev/null
+++ b/core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java
@@ -0,0 +1,644 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.os.storage;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
+import android.os.Environment;
+import android.os.SystemClock;
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+import android.os.Environment;
+import android.os.FileUtils;
+import android.os.storage.OnObbStateChangeListener;
+import android.os.storage.StorageManager;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.StringReader;
+
+public class StorageManagerBaseTest extends InstrumentationTestCase {
+
+    protected Context mContext = null;
+    protected StorageManager mSm = null;
+    private static String LOG_TAG = "StorageManagerBaseTest";
+    protected static final long MAX_WAIT_TIME = 120*1000;
+    protected static final long WAIT_TIME_INCR = 5*1000;
+    protected static String OBB_FILE_1 = "obb_file1.obb";
+    protected static String OBB_FILE_1_CONTENTS_1 = "OneToOneThousandInts.bin";
+    protected static String OBB_FILE_2 = "obb_file2.obb";
+    protected static String OBB_FILE_3 = "obb_file3.obb";
+    protected static String OBB_FILE_1_PASSWORD = "password1";
+    protected static String OBB_FILE_1_ENCRYPTED = "obb_enc_file100_orig1.obb";
+    protected static String OBB_FILE_2_UNSIGNED = "obb_file2_nosign.obb";
+    protected static String OBB_FILE_3_PASSWORD = "password3";
+    protected static String OBB_FILE_3_ENCRYPTED = "obb_enc_file100_orig3.obb";
+    protected static String OBB_FILE_3_BAD_PACKAGENAME = "obb_file3_bad_packagename.obb";
+
+    protected static boolean FORCE = true;
+    protected static boolean DONT_FORCE = false;
+
+    private static final String SAMPLE1_TEXT = "This is sample text.\n\nTesting 1 2 3.";
+
+    private static final String SAMPLE2_TEXT =
+        "We the people of the United States, in order to form a more perfect union,\n"
+        + "establish justice, insure domestic tranquility, provide for the common\n"
+        + "defense, promote the general welfare, and secure the blessings of liberty\n"
+        + "to ourselves and our posterity, do ordain and establish this Constitution\n"
+        + "for the United States of America.\n\n";
+
+    class MountingObbThread extends Thread {
+        boolean mStop = false;
+        volatile boolean mFileOpenOnObb = false;
+        private String mObbFilePath = null;
+        private String mPathToContentsFile = null;
+        private String mOfficialObbFilePath = null;
+
+        /**
+         * Constructor
+         *
+         * @param obbFilePath path to the OBB image file
+         * @param pathToContentsFile path to a file on the mounted OBB volume to open after the OBB
+         *      has been mounted
+         */
+        public MountingObbThread (String obbFilePath, String pathToContentsFile) {
+            assertTrue("obbFilePath cannot be null!", obbFilePath != null);
+            mObbFilePath = obbFilePath;
+            assertTrue("path to contents file cannot be null!", pathToContentsFile != null);
+            mPathToContentsFile = pathToContentsFile;
+        }
+
+        /**
+         * Runs the thread
+         *
+         * Mounts OBB_FILE_1, and tries to open a file on the mounted OBB (specified in the
+         * constructor). Once it's open, it waits until someone calls its doStop(), after which it
+         * closes the opened file.
+         */
+        public void run() {
+            // the official OBB file path and the mount-request file path should be the same, but
+            // let's distinguish the two as they may make for some interesting tests later
+            mOfficialObbFilePath = mountObb(mObbFilePath);
+            assertEquals("Expected and actual OBB file paths differ!", mObbFilePath,
+                    mOfficialObbFilePath);
+
+            // open a file on OBB 1...
+            DataInputStream inputFile = openFileOnMountedObb(mOfficialObbFilePath,
+                    mPathToContentsFile);
+            assertTrue("Failed to open file!", inputFile != null);
+
+            synchronized (this) {
+                mFileOpenOnObb = true;
+                notifyAll();
+            }
+
+            while (!mStop) {
+                try {
+                    Thread.sleep(WAIT_TIME_INCR);
+                } catch (InterruptedException e) {
+                    // nothing special to be done for interruptions
+                }
+            }
+            try {
+                inputFile.close();
+            } catch (IOException e) {
+                fail("Failed to close file on OBB due to error: " + e.toString());
+            }
+        }
+
+        /**
+         * Tells whether a file has yet been successfully opened on the OBB or not
+         *
+         * @return true if the specified file on the OBB was opened; false otherwise
+         */
+        public boolean isFileOpenOnObb() {
+            return mFileOpenOnObb;
+        }
+
+        /**
+         * Returns the official path of the OBB file that was mounted
+         *
+         * This is not the mount path, but the normalized path to the actual OBB file
+         *
+         * @return a {@link String} representation of the path to the OBB file that was mounted
+         */
+        public String officialObbFilePath() {
+            return mOfficialObbFilePath;
+        }
+
+        /**
+         * Requests the thread to stop running
+         *
+         * Closes the opened file and returns
+         */
+        public void doStop() {
+            mStop = true;
+        }
+    }
+
+    public class ObbListener extends OnObbStateChangeListener {
+        private String LOG_TAG = "StorageManagerBaseTest.ObbListener";
+
+        String mOfficialPath = null;
+        boolean mDone = false;
+        int mState = -1;
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public void onObbStateChange(String path, int state) {
+            Log.i(LOG_TAG, "Storage state changing to: " + state);
+
+            synchronized (this) {
+                Log.i(LOG_TAG, "OfficialPath is now: " + path);
+                mState = state;
+                mOfficialPath = path;
+                mDone = true;
+                notifyAll();
+            }
+        }
+
+        /**
+         * Tells whether we are done or not (system told us the OBB has changed state)
+         *
+         * @return true if the system has told us this OBB's state has changed, false otherwise
+         */
+        public boolean isDone() {
+            return mDone;
+        }
+
+        /**
+         * The last state of the OBB, according to the system
+         *
+         * @return A {@link String} representation of the state of the OBB
+         */
+        public int state() {
+            return mState;
+        }
+
+        /**
+         * The normalized, official path to the OBB file (according to the system)
+         *
+         * @return A {@link String} representation of the official path to the OBB file
+         */
+        public String officialPath() {
+            return mOfficialPath;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        mContext = getInstrumentation().getContext();
+        mSm = (StorageManager)mContext.getSystemService(android.content.Context.STORAGE_SERVICE);
+
+    }
+
+    /**
+     * Helper to copy a raw resource file to an actual specified file
+     *
+     * @param rawResId The raw resource ID of the OBB resource file
+     * @param outFile A File representing the file we want to copy the OBB to
+     * @throws NotFoundException If the resource file could not be found
+     */
+    private void copyRawToFile(int rawResId, File outFile) throws NotFoundException {
+        Resources res = mContext.getResources();
+        InputStream is = null;
+        try {
+            is = res.openRawResource(rawResId);
+        } catch (NotFoundException e) {
+            Log.i(LOG_TAG, "Failed to load resource with id: " + rawResId);
+            throw e;
+        }
+        FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG
+                | FileUtils.S_IRWXO, -1, -1);
+        assertTrue(FileUtils.copyToFile(is, outFile));
+        FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG
+                | FileUtils.S_IRWXO, -1, -1);
+    }
+
+    /**
+     * Creates an OBB file (with the given name), into the app's standard files directory
+     *
+     * @param name The name of the OBB file we want to create/write to
+     * @param rawResId The raw resource ID of the OBB file in the package
+     * @return A {@link File} representing the file to write to
+     */
+    protected File createObbFile(String name, int rawResId) {
+        File outFile = null;
+        try {
+            final File filesDir = mContext.getFilesDir();
+            outFile = new File(filesDir, name);
+            copyRawToFile(rawResId, outFile);
+        } catch (NotFoundException e) {
+            if (outFile != null) {
+                outFile.delete();
+            }
+        }
+        return outFile;
+    }
+
+    /**
+     * Mounts an OBB file and opens a file located on it
+     *
+     * @param obbPath Path to OBB image
+     * @param fileName The full name and path to the file on the OBB to open once the OBB is mounted
+     * @return The {@link DataInputStream} representing the opened file, if successful in opening
+     *      the file, or null of unsuccessful.
+     */
+    protected DataInputStream openFileOnMountedObb(String obbPath, String fileName) {
+
+        // get mSm obb mount path
+        assertTrue("Cannot open file when OBB is not mounted!", mSm.isObbMounted(obbPath));
+
+        String path = mSm.getMountedObbPath(obbPath);
+        assertTrue("Path should not be null!", path != null);
+
+        File inFile = new File(path, fileName);
+        DataInputStream inStream = null;
+        try {
+            inStream = new DataInputStream(new FileInputStream(inFile));
+            Log.i(LOG_TAG, "Opened file: " + fileName + " for read at path: " + path);
+        } catch (FileNotFoundException e) {
+            Log.e(LOG_TAG, e.toString());
+            return null;
+        } catch (SecurityException e) {
+            Log.e(LOG_TAG, e.toString());
+            return null;
+        }
+        return inStream;
+    }
+
+    /**
+     * Mounts an OBB file
+     *
+     * @param obbFilePath The full path to the OBB file to mount
+     * @param key (optional) The key to use to unencrypt the OBB; pass null for no encryption
+     * @param expectedState The expected state resulting from trying to mount the OBB
+     * @return A {@link String} representing the normalized path to OBB file that was mounted
+     */
+    protected String mountObb(String obbFilePath, String key, int expectedState) {
+        return doMountObb(obbFilePath, key, expectedState);
+    }
+
+    /**
+     * Mounts an OBB file with default options (no encryption, mounting succeeds)
+     *
+     * @param obbFilePath The full path to the OBB file to mount
+     * @return A {@link String} representing the normalized path to OBB file that was mounted
+     */
+    protected String mountObb(String obbFilePath) {
+        return doMountObb(obbFilePath, null, OnObbStateChangeListener.MOUNTED);
+    }
+
+    /**
+     * Synchronously waits for an OBB listener to be signaled of a state change, but does not throw
+     *
+     * @param obbListener The listener for the OBB file
+     * @return true if the listener was signaled of a state change by the system, else returns
+     *      false if we time out.
+     */
+    protected boolean doWaitForObbStateChange(ObbListener obbListener) {
+        synchronized(obbListener) {
+            long waitTimeMillis = 0;
+            while (!obbListener.isDone()) {
+                try {
+                    Log.i(LOG_TAG, "Waiting for listener...");
+                    obbListener.wait(WAIT_TIME_INCR);
+                    Log.i(LOG_TAG, "Awoke from waiting for listener...");
+                    waitTimeMillis += WAIT_TIME_INCR;
+                    if (waitTimeMillis > MAX_WAIT_TIME) {
+                        fail("Timed out waiting for OBB state to change!");
+                    }
+                } catch (InterruptedException e) {
+                    Log.i(LOG_TAG, e.toString());
+                }
+            }
+            return obbListener.isDone();
+            }
+    }
+
+    /**
+     * Synchronously waits for an OBB listener to be signaled of a state change
+     *
+     * @param obbListener The listener for the OBB file
+     * @return true if the listener was signaled of a state change by the system; else a fail()
+     *      is triggered if we timed out
+     */
+    protected String doMountObb_noThrow(String obbFilePath, String key, int expectedState) {
+        Log.i(LOG_TAG, "doMountObb() on " + obbFilePath + " using key: " + key);
+        assertTrue ("Null path was passed in for OBB file!", obbFilePath != null);
+        assertTrue ("Null path was passed in for OBB file!", obbFilePath != null);
+
+        ObbListener obbListener = new ObbListener();
+        boolean success = mSm.mountObb(obbFilePath, key, obbListener);
+        success &= obbFilePath.equals(doWaitForObbStateChange(obbListener));
+        success &= (expectedState == obbListener.state());
+
+        if (OnObbStateChangeListener.MOUNTED == expectedState) {
+            success &= obbFilePath.equals(obbListener.officialPath());
+            success &= mSm.isObbMounted(obbListener.officialPath());
+        } else {
+            success &= !mSm.isObbMounted(obbListener.officialPath());
+        }
+
+        if (success) {
+            return obbListener.officialPath();
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Mounts an OBB file without throwing and synchronously waits for it to finish mounting
+     *
+     * @param obbFilePath The full path to the OBB file to mount
+     * @param key (optional) The key to use to unencrypt the OBB; pass null for no encryption
+     * @param expectedState The expected state resulting from trying to mount the OBB
+     * @return A {@link String} representing the actual normalized path to OBB file that was
+     *      mounted, or null if the mounting failed
+     */
+    protected String doMountObb(String obbFilePath, String key, int expectedState) {
+        Log.i(LOG_TAG, "doMountObb() on " + obbFilePath + " using key: " + key);
+        assertTrue ("Null path was passed in for OBB file!", obbFilePath != null);
+
+        ObbListener obbListener = new ObbListener();
+        assertTrue("mountObb call failed", mSm.mountObb(obbFilePath, key, obbListener));
+        assertTrue("Failed to get OBB mount status change for file: " + obbFilePath,
+                doWaitForObbStateChange(obbListener));
+        assertEquals("OBB mount state not what was expected!", expectedState, obbListener.state());
+
+        if (OnObbStateChangeListener.MOUNTED == expectedState) {
+            assertEquals(obbFilePath, obbListener.officialPath());
+            assertTrue("Obb should be mounted, but SM reports it is not!",
+                    mSm.isObbMounted(obbListener.officialPath()));
+        } else if (OnObbStateChangeListener.UNMOUNTED == expectedState) {
+            assertFalse("Obb should not be mounted, but SM reports it is!",
+                    mSm.isObbMounted(obbListener.officialPath()));
+        }
+
+        assertEquals("Mount state is not what was expected!", expectedState, obbListener.state());
+        return obbListener.officialPath();
+    }
+
+    /**
+     * Unmounts an OBB file without throwing, and synchronously waits for it to finish unmounting
+     *
+     * @param obbFilePath The full path to the OBB file to mount
+     * @param force true if we shuold force the unmount, false otherwise
+     * @return true if the unmount was successful, false otherwise
+     */
+    protected boolean unmountObb_noThrow(String obbFilePath, boolean force) {
+        Log.i(LOG_TAG, "doUnmountObb_noThrow() on " + obbFilePath);
+        assertTrue ("Null path was passed in for OBB file!", obbFilePath != null);
+        boolean success = true;
+
+        ObbListener obbListener = new ObbListener();
+        assertTrue("unmountObb call failed", mSm.unmountObb(obbFilePath, force, obbListener));
+
+        boolean stateChanged = doWaitForObbStateChange(obbListener);
+        if (force) {
+            success &= stateChanged;
+            success &= (OnObbStateChangeListener.UNMOUNTED == obbListener.state());
+            success &= !mSm.isObbMounted(obbFilePath);
+        }
+        return success;
+    }
+
+    /**
+     * Unmounts an OBB file and synchronously waits for it to finish unmounting
+     *
+     * @param obbFilePath The full path to the OBB file to mount
+     * @param force true if we shuold force the unmount, false otherwise
+     */
+    protected void unmountObb(String obbFilePath, boolean force) {
+        Log.i(LOG_TAG, "doUnmountObb() on " + obbFilePath);
+        assertTrue ("Null path was passed in for OBB file!", obbFilePath != null);
+
+        ObbListener obbListener = new ObbListener();
+        assertTrue("unmountObb call failed", mSm.unmountObb(obbFilePath, force, obbListener));
+
+        boolean stateChanged = doWaitForObbStateChange(obbListener);
+        if (force) {
+            assertTrue("Timed out waiting to unmount OBB file " + obbFilePath, stateChanged);
+            assertEquals("OBB failed to unmount", OnObbStateChangeListener.UNMOUNTED,
+                    obbListener.state());
+            assertFalse("Obb should NOT be mounted, but SM reports it is!", mSm.isObbMounted(
+                    obbFilePath));
+        }
+    }
+
+    /**
+     * Helper to validate the contents of an "int" file in an OBB.
+     *
+     * The format of the files are sequential int's, in the range of: [start..end)
+     *
+     * @param path The full path to the file (path to OBB)
+     * @param filename The filename containing the ints to validate
+     * @param start The first int expected to be found in the file
+     * @param end The last int + 1 expected to be found in the file
+     */
+    protected void doValidateIntContents(String path, String filename, int start, int end) {
+        File inFile = new File(path, filename);
+        DataInputStream inStream = null;
+        Log.i(LOG_TAG, "Validating file " + filename + " at " + path);
+        try {
+            inStream = new DataInputStream(new FileInputStream(inFile));
+
+            for (int i = start; i < end; ++i) {
+                if (inStream.readInt() != i) {
+                    fail("Unexpected value read in OBB file");
+                }
+            }
+            if (inStream != null) {
+                inStream.close();
+            }
+            Log.i(LOG_TAG, "Successfully validated file " + filename);
+        } catch (FileNotFoundException e) {
+            fail("File " + inFile + " not found: " + e.toString());
+        } catch (IOException e) {
+            fail("IOError with file " + inFile + ":" + e.toString());
+        }
+    }
+
+    /**
+     * Helper to validate the contents of a text file in an OBB
+     *
+     * @param path The full path to the file (path to OBB)
+     * @param filename The filename containing the ints to validate
+     * @param contents A {@link String} containing the expected contents of the file
+     */
+    protected void doValidateTextContents(String path, String filename, String contents) {
+        File inFile = new File(path, filename);
+        BufferedReader fileReader = null;
+        BufferedReader textReader = null;
+        Log.i(LOG_TAG, "Validating file " + filename + " at " + path);
+        try {
+            fileReader = new BufferedReader(new FileReader(inFile));
+            textReader = new BufferedReader(new StringReader(contents));
+            String actual = null;
+            String expected = null;
+            while ((actual = fileReader.readLine()) != null) {
+                expected = textReader.readLine();
+                if (!actual.equals(expected)) {
+                    fail("File " + filename + " in OBB " + path + " does not match expected value");
+                }
+            }
+            fileReader.close();
+            textReader.close();
+            Log.i(LOG_TAG, "File " + filename + " successfully verified.");
+        } catch (IOException e) {
+            fail("IOError with file " + inFile + ":" + e.toString());
+        }
+    }
+
+    /**
+     * Helper to validate the contents of a "long" file on our OBBs
+     *
+     * The format of the files are sequential 0's of type long
+     *
+     * @param path The full path to the file (path to OBB)
+     * @param filename The filename containing the ints to validate
+     * @param size The number of zero's expected in the file
+     * @param checkContents If true, the contents of the file are actually verified; if false,
+     *      we simply verify that the file can be opened
+     */
+    protected void doValidateZeroLongFile(String path, String filename, long size,
+            boolean checkContents) {
+        File inFile = new File(path, filename);
+        DataInputStream inStream = null;
+        Log.i(LOG_TAG, "Validating file " + filename + " at " + path);
+        try {
+            inStream = new DataInputStream(new FileInputStream(inFile));
+
+            if (checkContents) {
+                for (long i = 0; i < size; ++i) {
+                    if (inStream.readLong() != 0) {
+                        fail("Unexpected value read in OBB file" + filename);
+                    }
+                }
+            }
+
+            if (inStream != null) {
+                inStream.close();
+            }
+            Log.i(LOG_TAG, "File " + filename + " successfully verified for " + size + " zeros");
+        } catch (IOException e) {
+            fail("IOError with file " + inFile + ":" + e.toString());
+        }
+    }
+
+    /**
+     * Helper to synchronously wait until we can get a path for a given OBB file
+     *
+     * @param filePath The full normalized path to the OBB file
+     * @return The mounted path of the OBB, used to access contents in it
+     */
+    protected String doWaitForPath(String filePath) {
+        String path = null;
+
+        long waitTimeMillis = 0;
+        assertTrue("OBB " + filePath + " is not currently mounted!", mSm.isObbMounted(filePath));
+        while (path == null) {
+            try {
+                Thread.sleep(WAIT_TIME_INCR);
+                waitTimeMillis += WAIT_TIME_INCR;
+                if (waitTimeMillis > MAX_WAIT_TIME) {
+                    fail("Timed out waiting to get path of OBB file " + filePath);
+                }
+            } catch (InterruptedException e) {
+                // do nothing
+            }
+            path = mSm.getMountedObbPath(filePath);
+        }
+        Log.i(LOG_TAG, "Got OBB path: " + path);
+        return path;
+    }
+
+    /**
+     * Verifies the pre-defined contents of our first OBB (OBB_FILE_1)
+     *
+     * The OBB contains 4 files and no subdirectories
+     *
+     * @param filePath The normalized path to the already-mounted OBB file
+     */
+    protected void verifyObb1Contents(String filePath) {
+        String path = null;
+        path = doWaitForPath(filePath);
+
+        // Validate contents of 2 files in this obb
+        doValidateIntContents(path, "OneToOneThousandInts.bin", 0, 1000);
+        doValidateIntContents(path, "SevenHundredInts.bin", 0, 700);
+        doValidateZeroLongFile(path, "FiveLongs.bin", 5, true);
+    }
+
+    /**
+     * Verifies the pre-defined contents of our second OBB (OBB_FILE_2)
+     *
+     * The OBB contains 2 files and no subdirectories
+     *
+     * @param filePath The normalized path to the already-mounted OBB file
+     */
+    protected void verifyObb2Contents(String filename) {
+        String path = null;
+        path = doWaitForPath(filename);
+
+        // Validate contents of file
+        doValidateTextContents(path, "sample.txt", SAMPLE1_TEXT);
+        doValidateTextContents(path, "sample2.txt", SAMPLE2_TEXT);
+    }
+
+    /**
+     * Verifies the pre-defined contents of our third OBB (OBB_FILE_3)
+     *
+     * The OBB contains nested files and subdirectories
+     *
+     * @param filePath The normalized path to the already-mounted OBB file
+     */
+    protected void verifyObb3Contents(String filename) {
+        String path = null;
+        path = doWaitForPath(filename);
+
+        // Validate contents of file
+        doValidateIntContents(path, "OneToOneThousandInts.bin", 0, 1000);
+        doValidateZeroLongFile(path, "TwoHundredLongs", 200, true);
+
+        // validate subdirectory 1
+        doValidateZeroLongFile(path + File.separator + "subdir1", "FiftyLongs", 50, true);
+
+        // validate subdirectory subdir2/
+        doValidateIntContents(path + File.separator + "subdir2", "OneToOneThousandInts", 0, 1000);
+
+        // validate subdirectory subdir2/subdir2a/
+        doValidateZeroLongFile(path + File.separator + "subdir2" + File.separator + "subdir2a",
+                "TwoHundredLongs", 200, true);
+
+        // validate subdirectory subdir2/subdir2a/subdir2a1/
+        doValidateIntContents(path + File.separator + "subdir2" + File.separator + "subdir2a"
+                + File.separator + "subdir2a1", "OneToOneThousandInts", 0, 1000);
+    }
+}
\ No newline at end of file
diff --git a/core/tests/coretests/src/android/os/storage/StorageManagerIntegrationTest.java b/core/tests/coretests/src/android/os/storage/StorageManagerIntegrationTest.java
new file mode 100644
index 0000000..71772d9
--- /dev/null
+++ b/core/tests/coretests/src/android/os/storage/StorageManagerIntegrationTest.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.os.storage;
+
+import android.content.Context;
+import android.os.Environment;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+
+import com.android.frameworks.coretests.R;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+
+import junit.framework.AssertionFailedError;
+
+public class StorageManagerIntegrationTest extends StorageManagerBaseTest {
+
+    private static String LOG_TAG = "StorageManagerBaseTest.StorageManagerIntegrationTest";
+    protected File mFile = null;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mContext = getInstrumentation().getContext();
+        mFile = null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void tearDown() throws Exception {
+        if (mFile != null) {
+            mFile.delete();
+            mFile = null;
+        }
+        super.tearDown();
+    }
+
+    /**
+     * Tests mounting a single OBB file and verifies its contents.
+     */
+    @LargeTest
+    public void testMountSingleObb() {
+        mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1);
+        String filePath = mFile.getAbsolutePath();
+        mountObb(filePath);
+        verifyObb1Contents(filePath);
+        unmountObb(filePath, DONT_FORCE);
+    }
+
+    /**
+     * Tests mounting several OBB files and verifies its contents.
+     */
+    @LargeTest
+    public void testMountMultipleObb() {
+        File file1 = null;
+        File file2 = null;
+        File file3 = null;
+        try {
+            file1 = createObbFile(OBB_FILE_1, R.raw.obb_file1);
+            String filePath1 = file1.getAbsolutePath();
+            mountObb(filePath1);
+            verifyObb1Contents(filePath1);
+
+            file2 = createObbFile(OBB_FILE_2, R.raw.obb_file2);
+            String filePath2 = file2.getAbsolutePath();
+            mountObb(filePath2);
+            verifyObb2Contents(filePath2);
+
+            file3 = createObbFile(OBB_FILE_3, R.raw.obb_file3);
+            String filePath3 = file3.getAbsolutePath();
+            mountObb(filePath3);
+            verifyObb3Contents(filePath3);
+
+            unmountObb(filePath1, DONT_FORCE);
+            unmountObb(filePath2, DONT_FORCE);
+            unmountObb(filePath3, DONT_FORCE);
+        } finally {
+            if (file1 != null) {
+                file1.delete();
+            }
+            if (file2 != null) {
+                file2.delete();
+            }
+            if (file3 != null) {
+                file3.delete();
+            }
+        }
+    }
+
+    /**
+     * Tests mounting a single encrypted OBB file and verifies its contents.
+     */
+    @LargeTest
+    public void testMountSingleEncryptedObb() {
+        mFile = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3);
+        String filePath = mFile.getAbsolutePath();
+        mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED);
+        verifyObb3Contents(filePath);
+        unmountObb(filePath, DONT_FORCE);
+    }
+
+    /**
+     * Tests mounting a single encrypted OBB file using an invalid password.
+     */
+    @LargeTest
+    public void testMountSingleEncryptedObbInvalidPassword() {
+        mFile = createObbFile("bad password@$%#@^*(!&)", R.raw.obb_enc_file100_orig3);
+        String filePath = mFile.getAbsolutePath();
+        mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT);
+        unmountObb(filePath, DONT_FORCE);
+    }
+
+    /**
+     * Tests simultaneously mounting 2 encrypted OBBs with different keys and verifies contents.
+     */
+    @LargeTest
+    public void testMountTwoEncryptedObb() {
+        File file3 = null;
+        File file1 = null;
+        try {
+            file3 = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3);
+            String filePath3 = file3.getAbsolutePath();
+            mountObb(filePath3, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED);
+            verifyObb3Contents(filePath3);
+
+            file1 = createObbFile(OBB_FILE_1_ENCRYPTED, R.raw.obb_enc_file100_orig1);
+            String filePath1 = file1.getAbsolutePath();
+            mountObb(filePath1, OBB_FILE_1_PASSWORD, OnObbStateChangeListener.MOUNTED);
+            verifyObb1Contents(filePath1);
+
+            unmountObb(filePath3, DONT_FORCE);
+            unmountObb(filePath1, DONT_FORCE);
+        } finally {
+            if (file3 != null) {
+                file3.delete();
+            }
+            if (file1 != null) {
+                file1.delete();
+            }
+        }
+    }
+
+    /**
+     * Tests that we can not force unmount when a file is currently open on the OBB.
+     */
+    @LargeTest
+    public void testUnmount_DontForce() {
+        mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1);
+        String obbFilePath = mFile.getAbsolutePath();
+
+        MountingObbThread mountingThread = new MountingObbThread(obbFilePath,
+                OBB_FILE_1_CONTENTS_1);
+
+        try {
+            mountingThread.start();
+
+            long waitTime = 0;
+            while (!mountingThread.isFileOpenOnObb()) {
+                synchronized (mountingThread) {
+                    Log.i(LOG_TAG, "Waiting for file to be opened on OBB...");
+                    mountingThread.wait(WAIT_TIME_INCR);
+                    waitTime += WAIT_TIME_INCR;
+                    if (waitTime > MAX_WAIT_TIME) {
+                        fail("Timed out waiting for file file to be opened on OBB!");
+                    }
+                }
+            }
+
+            unmountObb(obbFilePath, DONT_FORCE);
+
+            // verify still mounted
+            assertTrue("mounted path should not be null!", obbFilePath != null);
+            assertTrue("mounted path should still be mounted!", mSm.isObbMounted(obbFilePath));
+
+            // close the opened file
+            mountingThread.doStop();
+
+            // try unmounting again (should succeed this time)
+            unmountObb(obbFilePath, DONT_FORCE);
+            assertFalse("mounted path should no longer be mounted!",
+                    mSm.isObbMounted(obbFilePath));
+        } catch (InterruptedException e) {
+            fail("Timed out waiting for file on OBB to be opened...");
+        }
+    }
+
+    /**
+     * Tests mounting a single OBB that isn't signed.
+     */
+    @LargeTest
+    public void testMountUnsignedObb() {
+        mFile = createObbFile(OBB_FILE_2_UNSIGNED, R.raw.obb_file2_nosign);
+        String filePath = mFile.getAbsolutePath();
+        mountObb(filePath, OBB_FILE_2_UNSIGNED, OnObbStateChangeListener.ERROR_INTERNAL);
+    }
+
+    /**
+     * Tests mounting a single OBB that is signed with a different package.
+     */
+    @LargeTest
+    public void testMountBadPackageNameObb() {
+        mFile = createObbFile(OBB_FILE_3_BAD_PACKAGENAME, R.raw.obb_file3_bad_packagename);
+        String filePath = mFile.getAbsolutePath();
+        mountObb(filePath, OBB_FILE_3_BAD_PACKAGENAME,
+                OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
+    }
+
+    /**
+     * Tests remounting a single OBB that has already been mounted.
+     */
+    @LargeTest
+    public void testRemountObb() {
+        mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1);
+        String filePath = mFile.getAbsolutePath();
+        mountObb(filePath);
+        verifyObb1Contents(filePath);
+        mountObb(filePath, null, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED);
+        verifyObb1Contents(filePath);
+        unmountObb(filePath, DONT_FORCE);
+    }
+}
\ No newline at end of file
diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
index 818397b..e98000d 100644
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -132,7 +132,7 @@
 key 110   INSERT
 key 111   FORWARD_DEL
 # key 112 "KEY_MACRO"
-key 113   MUTE
+key 113   VOLUME_MUTE
 key 114   VOLUME_DOWN
 key 115   VOLUME_UP
 key 116   POWER             WAKE
diff --git a/data/keyboards/Motorola_Bluetooth_Wireless_Keyboard.kl b/data/keyboards/Motorola_Bluetooth_Wireless_Keyboard.kl
index 1298d53..eab78a0 100644
--- a/data/keyboards/Motorola_Bluetooth_Wireless_Keyboard.kl
+++ b/data/keyboards/Motorola_Bluetooth_Wireless_Keyboard.kl
@@ -83,9 +83,10 @@
 key 105   DPAD_LEFT
 key 106   DPAD_RIGHT
 key 107   MOVE_END
+key 108   DPAD_DOWN
 key 110   INSERT
 key 111   FORWARD_DEL
-key 113   MUTE
+key 113   VOLUME_MUTE
 key 114   VOLUME_DOWN
 key 115   VOLUME_UP
 key 125   MENU
diff --git a/docs/html/guide/appendix/market-filters.jd b/docs/html/guide/appendix/market-filters.jd
index e74cefb..6ca8acc 100644
--- a/docs/html/guide/appendix/market-filters.jd
+++ b/docs/html/guide/appendix/market-filters.jd
@@ -1,322 +1,353 @@
-page.title=Market Filters

-@jd:body

-

-<div id="qv-wrapper">

-<div id="qv">

-

-<h2>Quickview</h2>

-<ul> <li>Android Market applies filters to that let you control whether your app is shown to a

-user who is browing or searching for apps.</li> 

-<li>Filtering is determined by elements in an app's manifest file,

-aspects of the device being used, and other factors.</li> </ul>

-

-<h2>In this document</h2>

-

-<ol> <li><a href="#how-filters-work">How Filters Work in Android Market</a></li>

-<li><a href="#manifest-filters">Filtering based on Manifest File Elements</a></li>

-<li><a href="#other-filters">Other Filters</a></li> 

-</ol>

-

-<h2>See also</h2>

- <ol> 

-<li><a

-href="{@docRoot}guide/practices/compatibility.html">Compatibility</a></li>

-<li style="margin-top:2px;"><code><a

-href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code></li>

-<li><code><a

-href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></code></li>

-<li><code><a

-href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></code></li>

-<li><code><a

-href="{@docRoot}guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></code></li>

-<li><code><a

-href="{@docRoot}guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></code></li>

-<li><code><a

-href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</code></a></li>

-</ol>

-

-<div id="qv-extra"> <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png">

-<div id="qv-sub-rule"> <img src="{@docRoot}assets/images/icon_market.jpg"

-style="float:left;margin:0;padding:0;"> <p style="color:#669999;">Interested in

-publishing your app on Android Market?</p> <a id="publish-link"

-href="http://market.android.com/publish">Go to Android Market &raquo;</a> </div>

-</div>

-

-</div> </div>

-

-<p>When a user searches or browses in Android Market, the results are filtered, and

-some applications might not be visible. For example, if an application requires a

-trackball (as specified in the manifest file), then Android Market will not show

-the app on any device that does not have a trackball.</p> <p>The manifest file and

-the device's hardware and features are only part of how applications are filtered

-&#8212; filtering also depends on the country and carrier, the presence or absence

-of a SIM card, and other factors. </p>

-

-<p>Changes to the Android Market filters are independent of changes 

-to the Android platform itself. This document will be updated periodically to reflect 

-any changes that occur. </p>

-

-<h2 id="how-filters-work">How Filters Work in Android Market</h2>

-

-<p>Android Market uses the filter restrictions described below to determine

-whether to show your application to a user who is browsing or searching for

-applications on a given device. When determining whether to display your app,

-Market checks the device's hardware and software capabilities, as well as it's

-carrier, location, and other characteristics. It then compares those against the

-restrictions and dependencies expressed by the application itself, in its

-manifest, <code>.apk</code>, and publishing details. If the application is

-compatible with the device according to the filter rules, Market displays the

-application to the user. Otherwise, Market hides your application from search

-results and category browsing. </p>

-

-<p> You can use the filters described below to control whether Market shows or

-hides your application to users. You can request any combination of the

-available filters for your app &#8212; for example, you could set a

-<code>minSdkVersion</code> requirement of <code>"4"</code> and set

-<code>smallScreens="false"</code> in the app, then when uploading the app to

-Market you could target European countries (carriers) only. Android Market's

-filters would prevent the application from being visible on any device that did

-not match all three of these requirements. </p>

-

- <p>A filtered app is not visible within Market, even if a user specifically requests 

-the app by clicking a deep link that points directly to the app's ID within Market. 

-All filtering restrictions are associated with an application's version and can

-change between versions. For example:</p> 

-

-<ul> 

-<li>If you publish a new version of your app with stricter restrictions, the app

-will not be visible to users for whom it is filtered, even if those users were

-able see the previous version.</li>

-<li>If a user has installed your application and you publish an upgrade that

-makes the app invisible to the user, the user will not see that an upgrade is

-available. </li>

-</ul>

-

-<h2 id="manifest-filters">Filtering based on Manifest Elements</h2>

-

-<p>Most Market filters are triggered by elements within an application's

-manifest file, <a

-href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>,

-although not everything in the manifest file can trigger filtering. The

-table below lists the manifest elements that you can use to trigger Android

-Market filtering, and explains how the filtering works.</p>

-

-<p class="table-caption"><strong>Table 1.</strong> Manifest elements that

-trigger filtering on Market.</p>

-<table>

-  <tr>

-    <th>Manifest Element</th>

-    <th>Filter Name</th>

-    <th>How It Works</th>

-  </tr>

-  <tr>

-    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code>

-      <!-- ##api level 4## --></td>

-    <td valign="top">Screen Size</td>

-    <td valign="top">

-

-<p>An application indicates the screen sizes that it is capable of supporting by

-setting attributes of the <code>&lt;supports-screens&gt;</code> element. When

-the application is published, Market uses those attributes to determine whether

-to show the application to users, based on the screen sizes of their

-devices. </p>

-

-<p>As a general rule, Market assumes that the platform on the device can adapt

-smaller layouts to larger screens, but cannot adapt larger layouts to smaller

-screens. Thus, if an application declares support for "normal" screen size only,

-Market makes the application available to both normal- and large-screen devices,

-but filters the application so that it is not available to small-screen

-devices.</p>

-

-<p>If an application does not declare attributes for

-<code>&lt;supports-screens&gt;</code>, Market uses the default values for those

-attributes, which vary by API Level. Specifically: </p>

-

-<ul>

-<li><p>In API level 3, the <code>&lt;supports-screens&gt;</code> element itself

-is undefined and no attributes are available. In this case, Market assumes that

-the application is designed for normal-size screens and shows the application to

-devices that have normal or large screens. </p>

-

-<p>This behavior is especially significant for applications that set their

-<code><a

-href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">android:

-minSdkVersion</a></code> to 3 or lower, since Market will filter them from

-small-screen devices by default. Such applications can enable support for

-small-screen devices by adding a <code>android:targetSdkVersion="4"</code>

-attribute to the <code>&lt;uses-sdk&gt;</code> element in their manifest

-files. For more information, see <a

-href="{@docRoot}guide/practices/screens_support.html#strategies">Strategies for

-Legacy Applications</a>.</p></li>

-

-<li>In API Level 4, the defaults for all of the attributes is

-<code>"true"</code>. If an application does not declare a

-<code>&lt;supports-screens&gt;</code> element, Market assumes that the

-application is designed for all screen sizes and does not filter it from any

-devices. If the application does not declare one of the attributes, Market uses

-the default value of <code>"true"</code> and does not filter the app for devices

-of corresponding screen size.</li>

-</ul>

-

-    <p><strong>Example 1</strong><br />

-    The manifest declares <code>&lt;uses-sdk android:minSdkVersion="3"&gt;</code>

-    and does not does not include a <code>&lt;supports-screens&gt;</code> element.

-    <strong>Result</strong>: Android Market will not show the app to a user of a

-    small-screen device, but will show it to users of normal and large-screen

-    devices,  users, unless  other filters apply. </p>

-    <p><strong>Example 2<br />

-    </strong>The manifest declares <code>&lt;uses-sdk android:minSdkVersion="3"

-    android:targetSdkVersion="4"&gt;</code> and does not include a

-    <code>&lt;supports-screens&gt;</code> element.

-    <strong>Result</strong>: Android Market will show the app to users on all 

-    devices, unless other filters apply. </p>

-    <p><strong>Example 3<br />

-    </strong>The manifest declares <code>&lt;uses-sdk android:minSdkVersion="4"&gt;</code>

-    and does not include a <code>&lt;supports-screens&gt;</code> element.

-    <strong>Result</strong>: Android Market will show the app to all users,

-    unless  other filters apply. </p>

-    <p>For more information on how to declare support for screen sizes in your

-    application, see <code><a

-    href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code>

-    and <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple

-    Screens</a>.</p>

-</td>

-  </tr>

-  <tr>

-    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></code>

-      <!-- ##api level 3## --></td>

-    <td valign="top">Device

-    Configuration: <br />

-    keyboard, navigation, touch screen</td>

-    <td valign="top"><p>An application can

-    request certain hardware features, and Android Market will  show the app only on devices that have the required hardware.</p>

-      <p><strong>Example 1<br />

-      </strong>The manifest includes <code>&lt;uses-configuration android:reqFiveWayNav=&quot;true&quot; /&gt;</code>, and a user is searching for apps on a device that does not have a five-way navigational control. <strong>Result</strong>: Android Market will not show the app to the user. </p>

-      <p><strong>Example 2<br />

-      </strong>The manifest does not include a <code>&lt;uses-configuration&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>

-<p>For more details, see  <a

-href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><code>&lt;uses-configuration&gt;</code></a>.</p></td>

-  </tr>

-  <tr>

-    <td rowspan="2" valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></code>

-      <!-- ##api level 4## --></td>

-    <td valign="top">Device Features<br />

-      (<code>name</code>)</td>

-    <td valign="top"><p>An

-      application can require certain device features to be present on the device. This functionality

-      was introduced in Android 2.0 (API Level 5).</p>

-      <p><strong>Example 1<br />

-      </strong>The manifest includes <code>&lt;uses-feature android:name=&quot;android.hardware.sensor.light&quot; /&gt;</code>, and a user is searching for apps on a device that does not have a light sensor. <strong>Result</strong>: Android Market will not show the app to the user. </p>

-      <p><strong>Example 2<br />

-      </strong>The manifest does not include a <code>&lt;uses-feature&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>

-      <p>For more details, see <code><a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></code>.</p>

-<p><em>A note about camera:</em> If an

-        application requests the CAMERA permission using the <a

-href="{@docRoot}guide/topics/manifest/uses-permission-element.html"> <code>&lt;uses-permission&gt;</code></a> element, Market assumes that the

-        application requires the camera and all camera features (such as autofocus). For applications that require the camera and are designed to run on Android 1.5 (API Level 3), declaring the CAMERA permission is an effective way of ensuring that Market filters your app properly, since <code>uses-feature</code> filtering is not available to applications compiled against the Android 1.5 platform. For more details about requiring or requesting a camera, see the <a href="{@docRoot}guide/topics/manifest/uses-library-element.html#required"> <code>required</code></a> attribute of <code>&lt;uses-feature&gt;</code>. </p></td>

-  </tr>

-  <tr>

-    <td valign="top">OpenGL-ES

-    Version<br />

-(<code>openGlEsVersion</code>)</td>

-    <td valign="top"><p>An application can require that the device support a specific

-      OpenGL-ES version using the <code>&lt;uses-feature

-        android:openGlEsVersion=&quot;int&quot;&gt;</code> attribute.</p>

-      <p><strong>Example 1<br />

-      </strong>An app

-        requests multiple OpenGL-ES versions by specifying <code>openGlEsVersion</code> multiple times in the

-        manifest.  <strong>Result</strong>: Market assumes that the app requires the highest of the indicated versions.</p>

-<p><strong>Example 2<br />

-</strong>An app

-        requests OpenGL-ES version 1.1, and a user is searching for apps on a device that supports OpenGL-ES version 2.0. <strong>Result</strong>: Android Market will show the app to the user, unless other filters apply. If a

-  device reports that it supports OpenGL-ES version <em>X</em>,  Market assumes that it

-  also supports any version earlier than <em>X</em>.

-</p>

-<p><strong>Example 3<br />

-</strong>A user is searching for apps on a device that does not

-        report an OpenGL-ES version (for example, a device running Android 1.5 or earlier). <strong>Result</strong>: Android Market assumes that the device

-  supports only OpenGL-ES 1.0. Market will only show the user apps that do not specify <code>openGlEsVersion</code>, or apps that do not specify an OpenGL-ES version higher than 1.0. </p>

-      <p><strong>Example 4<br />

-      </strong>The manifest does not specify <code>openGlEsVersion</code>. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply. </p>

-<p>For more details, see <a

-href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><code>&lt;uses-feature&gt;</code></a>.</p></td>

-  </tr>

-  <tr>

-    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></code></td>

-    <td valign="top">Software Libraries</td>

-    <td valign="top"><p>An application can require specific

-    shared libraries to be present on the device. </p>

-      <p><strong>Example 1<br />

-      </strong>An app requires the <code>com.google.android.maps</code> library, and a user is searching for apps on a device that does not have the <code>com.google.android.maps</code> library. <strong>Result</strong>: Android Market will not show the app to the user. </p>

-      <p><strong>Example 2</strong><br />

-        The manifest does not include a <code>&lt;uses-library&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>

-<p>For more details, see <a

-href="{@docRoot}guide/topics/manifest/uses-library-element.html"><code>&lt;uses-library&gt;</code></a>.</p></td>

-  </tr>

-  <tr>

-    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></code></td>

-    <td valign="top">&nbsp;</td>

-    <td valign="top"><em>(See the note in the description of <code>&lt;uses-feature&gt;</code>, above.)</em></td>

-  </tr>

-  <tr>

-    <td rowspan="2" valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a></code></td>

-    <td valign="top">Minimum Framework Version (<code>minSdkVersion</code>)</td>

-    <td valign="top"><p>An application can require a minimum API level.  </p>

-      <p><strong>Example 1</strong><br />

-        The manifest includes <code>&lt;uses-sdk

-      android:minSdkVersion=&quot;3&quot;&gt;</code>, and the app uses APIs that were introduced in API Level 3. A user is searching for apps on a device that has API Level 2. <strong>Result</strong>: Android Market will not show the app to the user. </p>

-      <p><strong>Example 2</strong><br />

-      The manifest does not include <code>minSdkVersion</code>, and the app uses APIs that were introduced in API Level 3. A user is searching for apps on a device that has API Level 2. <strong>Result</strong>: Android Market assumes that <code>minSdkVersion</code> is &quot;1&quot; and that the app is compatible with all versions of Android. Market  shows the app to the user and allows the user to download the app. The app crashes at runtime. </p>

-    <p>Because you want to avoid this second scenario, we recommend that you always declare a <code>minSdkVersion</code>. For details, see <a

-href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min"><code>android:minSdkVersion</code></a>.</p></td>

-  </tr>

-  <tr>

-    <td valign="top">Maximum Framework Version (<code>maxSdkVersion</code>)</td>

-    <td valign="top"><p><em>Deprecated.</em> Android

-    2.1 and later do not check or enforce the <code>maxSdkVersion</code> attribute, and

-    the SDK will not compile if <code>maxSdkVersion</code> is set in an app's manifest. For devices already

-    compiled with <code>maxSdkVersion</code>, Market will respect it and use it for

-    filtering.</p>

-<p> Declaring <code>maxSdkVersion</code> is <em>not</em> recommended. For details, see <a

-href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#max"><code>android:maxSdkVersion</code></a>.</p></td>

-  </tr>

-</table>

-

-<h2 id="other-filters">Other Filters</h2>

-<p>Android Market uses other application characteristics to determine whether to show or hide an application for a particular user on a given device, as described in the table below. </p>

-

-<p class="table-caption"><strong>Table 2.</strong> Application and publishing characteristics that affect filtering on Market.</p>

-<table> <tr>

-    <th>Filter Name</th> <th>How It Works</th> </tr>

-

-  <tr>

-    <td valign="top">Publishing Status</td> <td valign="top"><p>Only published applications will appear in

-      searches and browsing within Android Market.</p> <p>Even if an app is unpublished, it can

-        be installed if users can see it in their Downloads area among their purchased,

-        installed, or recently uninstalled apps.</p> <p>If an application has been

-  suspended, users will not be able to reinstall or update it, even if it appears in their Downloads.</p> </td></tr>

-  <tr>

-  <td valign="top">Priced

-    Status</td> <td valign="top"><p>Not all users can see paid apps. To show paid apps, a device

-must have a SIM card and be running Android 1.1 or later, and it must be in a

-country (as determined by SIM carrier) in which paid apps are available.</p></td>

-</tr> <tr>

-  <td valign="top">Country / Carrier Targeting</td> <td valign="top"> <p>When you upload your app to

-    the Android Market, you can select specific countries to target. The app will only

-    be visible to the countries (carriers) that you select, as follows:</p>

-    <ul><li><p>A device's country is determined based on the carrier, if a carrier is

-      available. If no carrier can be determined, the Market application tries to

-      determine the country based on IP.</p></li> <li><p>Carrier is determined based on

-      the device's SIM (for GSM devices), not the current roaming carrier.</p></li></ul>

-</td> </tr> <tr>

-  <td valign="top">Native Platform</td> <td valign="top"><p>An application that includes native

-    libraries that target a specific platform (ARM EABI v7, for example) will only be

-    visible on devices that support that platform. For details about the NDK and using

-    native libraries, see <a href="{@docRoot}sdk/ndk/index.html#overview">What is the

-      Android NDK?</a></p> </tr> <tr>

-        <td valign="top">Forward-Locked Applications</td> <td valign="top"><p>To

-          forward lock an application, set copy protection to "On" when you upload the

-          application to Market. Market will not show copy-protected applications on

-developer devices or unreleased devices.</p></td> </tr> </table>

-

-

+page.title=Market Filters
+@jd:body
+
+<div id="qv-wrapper">
+<div id="qv">
+
+<h2>Quickview</h2>
+<ul> <li>Android Market applies filters to that let you control whether your app is shown to a
+user who is browing or searching for apps.</li> 
+<li>Filtering is determined by elements in an app's manifest file,
+aspects of the device being used, and other factors.</li> </ul>
+
+<h2>In this document</h2>
+
+<ol> <li><a href="#how-filters-work">How Filters Work in Android Market</a></li>
+<li><a href="#manifest-filters">Filtering based on Manifest File Elements</a></li>
+<li><a href="#other-filters">Other Filters</a></li> 
+</ol>
+
+<h2>See also</h2>
+ <ol> 
+<li><a
+href="{@docRoot}guide/practices/compatibility.html">Compatibility</a></li>
+<li style="margin-top:2px;"><code><a
+href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code></li>
+<li><code><a
+href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></code></li>
+<li><code><a
+href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></code></li>
+<li><code><a
+href="{@docRoot}guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></code></li>
+<li><code><a
+href="{@docRoot}guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></code></li>
+<li><code><a
+href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</code></a></li>
+</ol>
+
+<div id="qv-extra"> <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png">
+<div id="qv-sub-rule"> <img src="{@docRoot}assets/images/icon_market.jpg"
+style="float:left;margin:0;padding:0;"> <p style="color:#669999;">Interested in
+publishing your app on Android Market?</p> <a id="publish-link"
+href="http://market.android.com/publish">Go to Android Market &raquo;</a> </div>
+</div>
+
+</div> </div>
+
+<p>When a user searches or browses in Android Market, the results are filtered, and
+some applications might not be visible. For example, if an application requires a
+trackball (as specified in the manifest file), then Android Market will not show
+the app on any device that does not have a trackball.</p> <p>The manifest file and
+the device's hardware and features are only part of how applications are filtered
+&#8212; filtering also depends on the country and carrier, the presence or absence
+of a SIM card, and other factors. </p>
+
+<p>Changes to the Android Market filters are independent of changes 
+to the Android platform itself. This document will be updated periodically to reflect 
+any changes that occur. </p>
+
+<h2 id="how-filters-work">How Filters Work in Android Market</h2>
+
+<p>Android Market uses the filter restrictions described below to determine
+whether to show your application to a user who is browsing or searching for
+applications on a given device. When determining whether to display your app,
+Market checks the device's hardware and software capabilities, as well as it's
+carrier, location, and other characteristics. It then compares those against the
+restrictions and dependencies expressed by the application itself, in its
+manifest, <code>.apk</code>, and publishing details. If the application is
+compatible with the device according to the filter rules, Market displays the
+application to the user. Otherwise, Market hides your application from search
+results and category browsing. </p>
+
+<p> You can use the filters described below to control whether Market shows or
+hides your application to users. You can request any combination of the
+available filters for your app &#8212; for example, you could set a
+<code>minSdkVersion</code> requirement of <code>"4"</code> and set
+<code>smallScreens="false"</code> in the app, then when uploading the app to
+Market you could target European countries (carriers) only. Android Market's
+filters would prevent the application from being visible on any device that did
+not match all three of these requirements. </p>
+
+ <p>A filtered app is not visible within Market, even if a user specifically requests 
+the app by clicking a deep link that points directly to the app's ID within Market. 
+All filtering restrictions are associated with an application's version and can
+change between versions. For example:</p> 
+
+<ul> 
+<li>If you publish a new version of your app with stricter restrictions, the app
+will not be visible to users for whom it is filtered, even if those users were
+able see the previous version.</li>
+<li>If a user has installed your application and you publish an upgrade that
+makes the app invisible to the user, the user will not see that an upgrade is
+available. </li>
+</ul>
+
+<h2 id="manifest-filters">Filtering based on Manifest Elements</h2>
+
+<p>Most Market filters are triggered by elements within an application's
+manifest file, <a
+href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>,
+although not everything in the manifest file can trigger filtering. The
+table below lists the manifest elements that you can use to trigger Android
+Market filtering, and explains how the filtering works.</p>
+
+<p class="table-caption"><strong>Table 1.</strong> Manifest elements that
+trigger filtering on Market.</p>
+<table>
+  <tr>
+    <th>Manifest Element</th>
+    <th>Filter Name</th>
+    <th>How It Works</th>
+  </tr>
+  <tr>
+    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code>
+      <!-- ##api level 4## --></td>
+    <td valign="top">Screen Size</td>
+    <td valign="top">
+
+<p>An application indicates the screen sizes that it is capable of supporting by
+setting attributes of the <code>&lt;supports-screens&gt;</code> element. When
+the application is published, Market uses those attributes to determine whether
+to show the application to users, based on the screen sizes of their
+devices. </p>
+
+<p>As a general rule, Market assumes that the platform on the device can adapt
+smaller layouts to larger screens, but cannot adapt larger layouts to smaller
+screens. Thus, if an application declares support for "normal" screen size only,
+Market makes the application available to both normal- and large-screen devices,
+but filters the application so that it is not available to small-screen
+devices.</p>
+
+<p>If an application does not declare attributes for
+<code>&lt;supports-screens&gt;</code>, Market uses the default values for those
+attributes, which vary by API Level. Specifically: </p>
+
+<ul>
+<li><p>In API level 3, the <code>&lt;supports-screens&gt;</code> element itself
+is undefined and no attributes are available. In this case, Market assumes that
+the application is designed for normal-size screens and shows the application to
+devices that have normal or large screens. </p>
+
+<p>This behavior is especially significant for applications that set their
+<code><a
+href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">android:
+minSdkVersion</a></code> to 3 or lower, since Market will filter them from
+small-screen devices by default. Such applications can enable support for
+small-screen devices by adding a <code>android:targetSdkVersion="4"</code>
+attribute to the <code>&lt;uses-sdk&gt;</code> element in their manifest
+files. For more information, see <a
+href="{@docRoot}guide/practices/screens_support.html#strategies">Strategies for
+Legacy Applications</a>.</p></li>
+
+<li>In API Level 4, the defaults for all of the attributes is
+<code>"true"</code>. If an application does not declare a
+<code>&lt;supports-screens&gt;</code> element, Market assumes that the
+application is designed for all screen sizes and does not filter it from any
+devices. If the application does not declare one of the attributes, Market uses
+the default value of <code>"true"</code> and does not filter the app for devices
+of corresponding screen size.</li>
+</ul>
+
+    <p><strong>Example 1</strong><br />
+    The manifest declares <code>&lt;uses-sdk android:minSdkVersion="3"&gt;</code>
+    and does not does not include a <code>&lt;supports-screens&gt;</code> element.
+    <strong>Result</strong>: Android Market will not show the app to a user of a
+    small-screen device, but will show it to users of normal and large-screen
+    devices,  users, unless  other filters apply. </p>
+    <p><strong>Example 2<br />
+    </strong>The manifest declares <code>&lt;uses-sdk android:minSdkVersion="3"
+    android:targetSdkVersion="4"&gt;</code> and does not include a
+    <code>&lt;supports-screens&gt;</code> element.
+    <strong>Result</strong>: Android Market will show the app to users on all 
+    devices, unless other filters apply. </p>
+    <p><strong>Example 3<br />
+    </strong>The manifest declares <code>&lt;uses-sdk android:minSdkVersion="4"&gt;</code>
+    and does not include a <code>&lt;supports-screens&gt;</code> element.
+    <strong>Result</strong>: Android Market will show the app to all users,
+    unless  other filters apply. </p>
+    <p>For more information on how to declare support for screen sizes in your
+    application, see <code><a
+    href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code>
+    and <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
+    Screens</a>.</p>
+</td>
+  </tr>
+  <tr>
+    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></code>
+      <!-- ##api level 3## --></td>
+    <td valign="top">Device
+    Configuration: <br />
+    keyboard, navigation, touch screen</td>
+    <td valign="top"><p>An application can
+    request certain hardware features, and Android Market will  show the app only on devices that have the required hardware.</p>
+      <p><strong>Example 1<br />
+      </strong>The manifest includes <code>&lt;uses-configuration android:reqFiveWayNav=&quot;true&quot; /&gt;</code>, and a user is searching for apps on a device that does not have a five-way navigational control. <strong>Result</strong>: Android Market will not show the app to the user. </p>
+      <p><strong>Example 2<br />
+      </strong>The manifest does not include a <code>&lt;uses-configuration&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>
+<p>For more details, see  <a
+href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><code>&lt;uses-configuration&gt;</code></a>.</p></td>
+  </tr>
+  <tr>
+    <td rowspan="2" valign="top" style="white-space:nowrap;"><code><a
+href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a>
+</code>
+      <!-- ##api level 4## --></td>
+    <td valign="top">Device Features<br />
+      (<code>name</code>)</td>
+    <td valign="top"><p>An application can require certain device features to be
+present on the device. This functionality was introduced in Android 2.0 (API
+Level 5).</p>
+      <p><strong>Example 1<br />
+      </strong>The manifest includes <code>&lt;uses-feature
+android:name=&quot;android.hardware.sensor.light&quot; /&gt;</code>, and a user
+is searching for apps on a device that does not have a light sensor.
+<strong>Result</strong>: Android Market will not show the app to the user. </p>
+      <p><strong>Example 2<br />
+      </strong>The manifest does not include a <code>&lt;uses-feature&gt;</code>
+element. <strong>Result</strong>: Android Market will show the app to all users,
+unless other filters apply.</p>
+      <p>For complete information, see <code><a
+href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a>
+</code>.</p>
+      <p><em>Filtering based on implied features:</em> In some cases, Android
+Market interprets permissions requested through
+<code>&lt;uses-permission&gt;</code> elements as feature requirements equivalent
+to those declared in <code>&lt;uses-feature&gt;</code> elements. See <a
+href="#uses-permission-filtering"><code>&lt;uses-permission&gt;</code></a>,
+below.</p>
+</td>
+  </tr>
+  <tr>
+    <td valign="top">OpenGL-ES
+    Version<br />
+(<code>openGlEsVersion</code>)</td>
+    <td valign="top"><p>An application can require that the device support a specific
+      OpenGL-ES version using the <code>&lt;uses-feature
+        android:openGlEsVersion=&quot;int&quot;&gt;</code> attribute.</p>
+      <p><strong>Example 1<br />
+      </strong>An app
+        requests multiple OpenGL-ES versions by specifying <code>openGlEsVersion</code> multiple times in the
+        manifest.  <strong>Result</strong>: Market assumes that the app requires the highest of the indicated versions.</p>
+<p><strong>Example 2<br />
+</strong>An app
+        requests OpenGL-ES version 1.1, and a user is searching for apps on a device that supports OpenGL-ES version 2.0. <strong>Result</strong>: Android Market will show the app to the user, unless other filters apply. If a
+  device reports that it supports OpenGL-ES version <em>X</em>,  Market assumes that it
+  also supports any version earlier than <em>X</em>.
+</p>
+<p><strong>Example 3<br />
+</strong>A user is searching for apps on a device that does not
+        report an OpenGL-ES version (for example, a device running Android 1.5 or earlier). <strong>Result</strong>: Android Market assumes that the device
+  supports only OpenGL-ES 1.0. Market will only show the user apps that do not specify <code>openGlEsVersion</code>, or apps that do not specify an OpenGL-ES version higher than 1.0. </p>
+      <p><strong>Example 4<br />
+      </strong>The manifest does not specify <code>openGlEsVersion</code>. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply. </p>
+<p>For more details, see <a
+href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><code>&lt;uses-feature&gt;</code></a>.</p></td>
+  </tr>
+  <tr>
+    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></code></td>
+    <td valign="top">Software Libraries</td>
+    <td valign="top"><p>An application can require specific
+    shared libraries to be present on the device. </p>
+      <p><strong>Example 1<br />
+      </strong>An app requires the <code>com.google.android.maps</code> library, and a user is searching for apps on a device that does not have the <code>com.google.android.maps</code> library. <strong>Result</strong>: Android Market will not show the app to the user. </p>
+      <p><strong>Example 2</strong><br />
+        The manifest does not include a <code>&lt;uses-library&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>
+<p>For more details, see <a
+href="{@docRoot}guide/topics/manifest/uses-library-element.html"><code>&lt;uses-library&gt;</code></a>.</p></td>
+  </tr>
+  <tr id="uses-permission-filtering">
+    <td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></code></td>
+    <td valign="top">&nbsp;</td>
+    <td valign="top">Strictly, Android Market does not filter based on
+<code>&lt;uses-permission&gt;</code> elements. However, it does read the
+elements to determine whether the application has hardware feature requirements
+that may not have been properly declared in <code>&lt;uses-feature&gt;</code>
+elements. For example, if an application requests the <code>CAMERA</code>
+permission but does not declare a <code>&lt;uses-feature&gt;</code> element for
+<code>android.hardware.camera</code>, Android Market considers that the
+application requires a camera and should not be shown to users whose devices do
+not offer a camera.</p>
+    <p>In general, if an application requests hardware-related permissions,
+Android Market assumes that the application requires the underlying hardware
+features, even though there might be no corresponding to
+<code>&lt;uses-feature&gt;</code> declarations. Android Market then sets up
+filtering based on the features implied by the <code>&lt;uses-feature&gt;</code>
+declarations.</p>
+    <p>For a list of permissions that imply hardware features, see
+the documentation for the <a
+href="{@docRoot}guide/topics/manifest/uses-feature-element.html#permissions-features"><code>&lt;uses-feature&gt;</code></a>
+element.</p>
+</td>
+  </tr>
+  <tr>
+    <td rowspan="2" valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a></code></td>
+    <td valign="top">Minimum Framework Version (<code>minSdkVersion</code>)</td>
+    <td valign="top"><p>An application can require a minimum API level.  </p>
+      <p><strong>Example 1</strong><br />
+        The manifest includes <code>&lt;uses-sdk
+      android:minSdkVersion=&quot;3&quot;&gt;</code>, and the app uses APIs that were introduced in API Level 3. A user is searching for apps on a device that has API Level 2. <strong>Result</strong>: Android Market will not show the app to the user. </p>
+      <p><strong>Example 2</strong><br />
+      The manifest does not include <code>minSdkVersion</code>, and the app uses APIs that were introduced in API Level 3. A user is searching for apps on a device that has API Level 2. <strong>Result</strong>: Android Market assumes that <code>minSdkVersion</code> is &quot;1&quot; and that the app is compatible with all versions of Android. Market  shows the app to the user and allows the user to download the app. The app crashes at runtime. </p>
+    <p>Because you want to avoid this second scenario, we recommend that you always declare a <code>minSdkVersion</code>. For details, see <a
+href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min"><code>android:minSdkVersion</code></a>.</p></td>
+  </tr>
+  <tr>
+    <td valign="top">Maximum Framework Version (<code>maxSdkVersion</code>)</td>
+    <td valign="top"><p><em>Deprecated.</em> Android
+    2.1 and later do not check or enforce the <code>maxSdkVersion</code> attribute, and
+    the SDK will not compile if <code>maxSdkVersion</code> is set in an app's manifest. For devices already
+    compiled with <code>maxSdkVersion</code>, Market will respect it and use it for
+    filtering.</p>
+<p> Declaring <code>maxSdkVersion</code> is <em>not</em> recommended. For details, see <a
+href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#max"><code>android:maxSdkVersion</code></a>.</p></td>
+  </tr>
+</table>
+
+<h2 id="other-filters">Other Filters</h2>
+<p>Android Market uses other application characteristics to determine whether to show or hide an application for a particular user on a given device, as described in the table below. </p>
+
+<p class="table-caption"><strong>Table 2.</strong> Application and publishing characteristics that affect filtering on Market.</p>
+<table> <tr>
+    <th>Filter Name</th> <th>How It Works</th> </tr>
+
+  <tr>
+    <td valign="top">Publishing Status</td> <td valign="top"><p>Only published applications will appear in
+      searches and browsing within Android Market.</p> <p>Even if an app is unpublished, it can
+        be installed if users can see it in their Downloads area among their purchased,
+        installed, or recently uninstalled apps.</p> <p>If an application has been
+  suspended, users will not be able to reinstall or update it, even if it appears in their Downloads.</p> </td></tr>
+  <tr>
+  <td valign="top">Priced
+    Status</td> <td valign="top"><p>Not all users can see paid apps. To show paid apps, a device
+must have a SIM card and be running Android 1.1 or later, and it must be in a
+country (as determined by SIM carrier) in which paid apps are available.</p></td>
+</tr> <tr>
+  <td valign="top">Country / Carrier Targeting</td> <td valign="top"> <p>When you upload your app to
+    the Android Market, you can select specific countries to target. The app will only
+    be visible to the countries (carriers) that you select, as follows:</p>
+    <ul><li><p>A device's country is determined based on the carrier, if a carrier is
+      available. If no carrier can be determined, the Market application tries to
+      determine the country based on IP.</p></li> <li><p>Carrier is determined based on
+      the device's SIM (for GSM devices), not the current roaming carrier.</p></li></ul>
+</td> </tr> <tr>
+  <td valign="top">Native Platform</td> <td valign="top"><p>An application that includes native
+    libraries that target a specific platform (ARM EABI v7, for example) will only be
+    visible on devices that support that platform. For details about the NDK and using
+    native libraries, see <a href="{@docRoot}sdk/ndk/index.html#overview">What is the
+      Android NDK?</a></p> </tr> <tr>
+        <td valign="top">Forward-Locked Applications</td> <td valign="top"><p>To
+          forward lock an application, set copy protection to "On" when you upload the
+          application to Market. Market will not show copy-protected applications on
+developer devices or unreleased devices.</p></td> </tr> </table>
+
+
diff --git a/docs/html/guide/developing/eclipse-adt.jd b/docs/html/guide/developing/eclipse-adt.jd
index d0fc9b8..1594159 100644
--- a/docs/html/guide/developing/eclipse-adt.jd
+++ b/docs/html/guide/developing/eclipse-adt.jd
@@ -392,11 +392,11 @@
 
 <ul>
 <li>If you are developing multiple related applications that use some of the
-same components, you move the redundant components out of their respective
+same components, you could move the redundant components out of their respective
 application projects and create a single, reuseable set of the same components
 in a library project. </li>
 <li>If you are creating an application that exists in both free and paid
-versions. You move the part of the application that is common to both versions
+versions, you could move the part of the application that is common to both versions
 into a library project. The two dependent projects, with their different package
 names, will reference the library project and provide only the difference
 between the two application versions.</li>
diff --git a/docs/html/guide/developing/other-ide.jd b/docs/html/guide/developing/other-ide.jd
index ff13f43..8c61771a 100644
--- a/docs/html/guide/developing/other-ide.jd
+++ b/docs/html/guide/developing/other-ide.jd
@@ -555,11 +555,11 @@
 
 <ul>
 <li>If you are developing multiple related applications that use some of the
-same components, you move the redundant components out of their respective
+same components, you could move the redundant components out of their respective
 application projects and create a single, reuseable set of the same components
 in a library project. </li>
 <li>If you are creating an application that exists in both free and paid
-versions. You move the part of the application that is common to both versions
+versions, you could move the part of the application that is common to both versions
 into a library project. The two dependent projects, with their different package
 names, will reference the library project and provide only the difference
 between the two application versions.</li>
diff --git a/docs/html/guide/developing/tools/MonkeyDevice.jd b/docs/html/guide/developing/tools/MonkeyDevice.jd
new file mode 100644
index 0000000..34bbba9
--- /dev/null
+++ b/docs/html/guide/developing/tools/MonkeyDevice.jd
@@ -0,0 +1,1353 @@
+page.title=MonkeyDevice
+@jd:body
+<style>
+    h4.jd-details-title {background-color: #DEE8F1;}
+</style>
+<p>
+    A monkeyrunner class that represents a device or emulator accessible by the workstation running
+<code><a href="{@docRoot}guide/developing/tools/monkeyrunner_concepts.html">monkeyrunner</a></code>.
+</p>
+<p>
+    This class is used to control an Android device or emulator. The methods send UI events,
+    retrieve information, install and remove applications, and run applications.
+</p>
+<p>
+    You normally do not have to create an instance of <code>MonkeyDevice</code>. Instead, you
+    use
+<code><a href="{@docRoot}guide/developing/tools/MonkeyRunner.html#waitForConnection">
+MonkeyRunner.waitForConnection()</a></code> to create a new object from a connection to a device or
+emulator. For example, instead of
+using:</p>
+<pre>
+newdevice = MonkeyDevice()
+</pre>
+<p>
+    you would use:
+</p>
+<pre>
+newdevice = MonkeyRunner.waitForConnection()
+</pre>
+<h2>Summary</h2>
+    <table id="constants" class="jd-sumtable" style="background-color: white;">
+       <tr>
+            <th colspan="12" style="background-color: #E2E2E2">Constants</th>
+       </tr>
+        <tr class="api" style="background-color: white;">
+            <td class="jd-typecol"><em>string</em></td>
+            <td class="jd-linkcol"><a href="#ACTION_DOWN">DOWN</a></td>
+            <td class="jd-descrcol" width="100%">
+                Use this with the <code>type</code> argument of
+                <code><a href="#press">press()</a></code> or <code><a href="#touch">touch()</a>
+                </code>
+                to send a DOWN event.
+            </td>
+        </tr>
+        <tr class="api" style="background-color: white;">
+            <td class="jd-typecol"><em>string</em></td>
+            <td class="jd-linkcol"><a href="#ACTION_UP">UP</a></td>
+            <td class="jd-descrcol" width="100%">
+                Use this with the <code>type</code> argument of
+                <code><a href="#press">press()</a></code> or <code><a href="#touch">touch()</a>
+                </code>
+                to send an UP event.
+            </td>
+        </tr>
+        <tr class="api" style="background-color: white;">
+            <td class="jd-typecol"><em>string</em></td>
+            <td class="jd-linkcol"><a href="#ACTION_DOWN_AND_UP">DOWN_AND_UP</a></td>
+            <td class="jd-descrcol" width="100%">
+                Use this with the <code>type</code> argument of
+                <code><a href="#press">press()</a></code> or <code><a href="#touch">touch()</a>
+                </code>
+                to send a DOWN event immediately followed by an UP event.
+            </td>
+        </tr>
+    </table>
+<table id="pubmethods" class="jd-sumtable">
+    <tr>
+        <th colspan="12" style="background-color: #E2E2E2">Methods</th>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#broadcastIntent">broadcastIntent</a>
+                </span>
+                (<em>string</em> uri,
+                <em>string</em> action,
+                <em>string</em> data,
+                <em>string</em> mimetype,
+                <em>iterable</em> categories
+                <em>dictionary</em> extras,
+                <em>component</em> component,
+                <em>iterable</em> flags)
+            </nobr>
+            <div class="jd-descrdiv">
+                Broadcasts an Intent to this device, as if the Intent were coming from an
+                application.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#drag">drag</a>
+                </span>
+                (<em>tuple</em> start,
+                <em>tuple</em> end,
+                <em>float</em> duration,
+                <em>integer</em> steps)
+            </nobr>
+            <div class="jd-descrdiv">
+                Simulates a drag gesture (touch, hold, and move) on this device's screen.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>object</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#getProperty">getProperty</a>
+                </span>
+                (<em>string</em> key)
+            </nobr>
+            <div class="jd-descrdiv">
+                Given the name of a system environment variable, returns its value for this device.
+                The available variable names are listed in the <a href="#getProperty">
+                detailed description</a> of this method.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>object</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#getSystemProperty">getSystemProperty</a>
+                </span>
+                (<em>string</em> key)
+            </nobr>
+            <div class="jd-descrdiv">
+.               The API equivalent of <code>adb shell getprop &lt;key&gt;. This is provided for use
+                by platform developers.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#installPackage">installPackage</a>
+                </span>
+                (<em>string</em> path)
+            </nobr>
+            <div class="jd-descrdiv">
+                Installs the Android application or test package contained in packageFile onto this
+                device. If the application or test package is already installed, it is replaced.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>dictionary</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#instrument">instrument</a>
+                </span>
+                (<em>string</em> className,
+                <em>dictionary</em> args)
+            </nobr>
+            <div class="jd-descrdiv">
+                Runs the specified component under Android instrumentation, and returns the results
+                in a dictionary whose exact format is dictated by the component being run. The
+                component must already be present on this device.
+            </div>
+        </td>
+    </tr>
+    <tr class="api">
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#press">press</a>
+                </span>
+                (<em>string</em> name,
+                <em>dictionary</em> type)
+            </nobr>
+            <div class="jd-descrdiv">
+                Sends the key event specified by type to the key specified by
+                keycode.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#reboot">reboot</a>
+                </span>
+                (<em>string</em> into)
+            </nobr>
+            <div class="jd-descrdiv">
+                Reboots this device into the bootloader specified by bootloadType.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#removePackage">removePackage</a>
+                </span>
+                (<em>string</em> package)
+            </nobr>
+            <div class="jd-descrdiv">
+                Deletes the specified package from this device, including its data and cache.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>object</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#shell">shell</a>
+                </span>
+                (<em>string</em> cmd)
+            </nobr>
+            <div class="jd-descrdiv">
+                Executes an <code>adb</code> shell command and returns the result, if any.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#startActivity">startActivity</a>
+                </span>
+                (<em>string</em> uri,
+                <em>string</em> action,
+                <em>string</em> data,
+                <em>string</em> mimetype,
+                <em>iterable</em> categories
+                <em>dictionary</em> extras,
+                <em>component</em> component,
+                <em>flags</em>)
+            </nobr>
+            <div class="jd-descrdiv">
+                Starts an Activity on this device by sending an Intent constructed from the
+                supplied arguments.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <code>
+                <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">
+                        MonkeyImage
+                    </a>
+                </code>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#takeSnapshot">takeSnapshot</a>()
+                </span>
+            </nobr>
+            <div class="jd-descrdiv">
+                Captures the entire screen buffer of this device, yielding a
+                <code>
+                <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">
+                        MonkeyImage
+                </a>
+                </code> object containing a screen capture of the current display.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#touch">touch</a>
+                </span>
+               (<em>integer</em> x,
+                 <em>integer</em> y,
+                 <em>integer</em> type)
+            </nobr>
+            <div class="jd-descrdiv">
+                Sends a touch event specified by type to the screen location specified
+                by x and y.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#touch">type</a>
+                </span>
+                   (<em>string</em> message)
+            </nobr>
+            <div class="jd-descrdiv">
+                Sends the characters contained in message to this device, as if they
+                had been typed on the device's keyboard. This is equivalent to calling
+                <code><a href="#press">press()</a></code> for each keycode in <code>message</code>
+                using the key event type <code><a href="#ACTION_DOWN_AND_UP"></a>DOWN_AND_UP</code>.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#touch">wake</a>
+                </span>
+                   ()
+            </nobr>
+            <div class="jd-descrdiv">
+                Wakes the screen of this device.
+            </div>
+        </td>
+    </tr>
+</table>
+<!-- ========= ENUM CONSTANTS DETAIL ======== -->
+<h2>Constants</h2>
+<A NAME="ACTION_DOWN"></a>
+<div class="jd-details api">
+    <h4 class="jd-details-title">
+        <span class="normal">
+            <em>string</em>
+        </span>
+            DOWN
+    </h4>
+    <div class="jd-details-descr">
+        <div class="jd-tagdata jd-tagdescr">
+            <p>
+                <code><a href="#press">press()</a></code> or
+                <code><a href="#press">touch()</a></code> value.
+                Specifies that a DOWN event type should be sent to the device, corresponding to
+                pressing down on a key or touching the screen.
+            </p>
+        </div>
+    </div>
+</div>
+<A NAME="ACTION_UP"></A>
+<div class="jd-details api">
+    <h4 class="jd-details-title">
+        <span class="normal">
+            <em>string</em>
+        </span>
+            UP
+    </h4>
+    <div class="jd-details-descr">
+        <div class="jd-tagdata jd-tagdescr">
+            <p>
+                <code><a href="#press">press()</a></code> or
+                <code><a href="#press">touch()</a></code> value.
+                Specifies that an UP event type should be sent to the device, corresponding to
+                releasing a key or lifting up from the screen.
+            </p>
+        </div>
+    </div>
+</div>
+<A NAME="ACTION_DOWN_AND_UP"></A>
+
+<div class="jd-details api">
+    <h4 class="jd-details-title">
+        <span class="normal">
+            <em>string</em>
+        </span>
+            DOWN_AND_UP
+    </h4>
+    <div class="jd-details-descr">
+        <div class="jd-tagdata jd-tagdescr">
+            <p>
+                <code><a href="#press">press()</a></code>,
+                <code><a href="#press">touch()</a></code> or
+                <code><a href="#type">type()</a></code> value.
+                Specifies that a DOWN event type followed by an UP event type should be sent to the
+                device, corresponding to typing a key or clicking the screen.
+            </p>
+        </div>
+    </div>
+</div>
+<!-- ========= METHOD DETAIL ======== -->
+<!-- Public methods -->
+<h2>Public Methods</h2>
+<A NAME="broadcastIntent"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">broadcastIntent</span>
+      <span class="normal">
+      (
+            <em>string</em> uri,
+            <em>string</em> action,
+            <em>string</em> data,
+            <em>string</em> mimetype,
+            <em>iterable</em> categories
+            <em>dictionary</em> extras,
+            <em>component</em> component,
+            <em>iterable</em> flags)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Broadcasts an Intent to this device, as if the Intent were coming from an
+            application. See {@link android.content.Intent Intent} for more information about the
+            arguments.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>uri</th>
+            <td>
+                The URI for the Intent.
+                (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}).
+            </td>
+        </tr>
+        <tr>
+            <th>action</th>
+            <td>
+                The action for this Intent
+                (see {@link android.content.Intent#setAction(java.lang.String) Intent.setAction()}).
+            </td>
+        </tr>
+        <tr>
+            <th>data</th>
+            <td>
+                The data URI for this Intent
+                (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}).
+            </td>
+        </tr>
+        <tr>
+            <th>mimetype</th>
+            <td>
+                The MIME type for the Intent
+                (see {@link android.content.Intent#setType(java.lang.String) Intent.setType()}).
+            </td>
+        </tr>
+        <tr>
+            <th>categories</th>
+            <td>
+                An iterable data structure containing strings that define categories for this
+                Intent
+                (see
+                {@link android.content.Intent#addCategory(java.lang.String) Intent.addCategory()}).
+            </td>
+        </tr>
+        <tr>
+            <th>extras</th>
+            <td>
+                A dictionary of extra data for this Intent
+                (see {@link android.content.Intent#putExtra(java.lang.String,java.lang.String)
+                Intent.putExtra()}
+                for an example).
+                <p>
+                    The key for each dictionary item should be a <em>string</em>. The item's value
+                    can be any simple or structured data type.
+                </p>
+            </td>
+        </tr>
+        <tr>
+            <th>component</th>
+            <td>
+                The component for this Intent (see {@link android.content.ComponentName}).
+                Using this argument will direct the Intent to a specific class within a specific
+                Android package.
+            </td>
+        </tr>
+        <tr>
+            <th>flags</th>
+            <td>
+                An iterable data structure containing flags that control how the Intent is handled
+                (see {@link android.content.Intent#setFlags(int) Intent.setFlags()}).
+            </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="drag"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">drag</span>
+      <span class="normal">
+      (
+            <em>tuple</em> start,
+            <em>tuple</em> end,
+            <em>float</em> duration,
+            <em>integer</em> steps)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Simulates a drag gesture (touch, hold, and move) on this device's screen.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>start</th>
+          <td>
+            The starting point of the drag gesture, in the form of a <em>tuple</em>
+            (x,y) where x and y are <em>integers</em>.
+          </td>
+        </tr>
+        <tr>
+          <th>end</th>
+          <td>
+            The end point of the drag gesture, in the form of a <em>tuple</em> (x,y)
+            where x and y are <em>integers</em>.
+          </td>
+        </tr>
+        <tr>
+            <th>duration</th>
+            <td>The duration of the drag gesture in seconds. The default is 1.0 seconds.</td>
+        </tr>
+        <tr>
+            <th>steps</th>
+            <td>The number of steps to take when interpolating points. The default is 10.</td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="getProperty"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>object</em>
+      </span>
+      <span class="sympad">getProperty</span>
+      <span class="normal">
+        (<em>string</em> key)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Given the name of a system environment variable, returns its value for this device.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>key</th>
+          <td>
+            The name of the system environment variable. The available variable names are listed in
+            <a href="#table1">Table 1. Property variable names</a> at the end of this topic.
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            The value of the variable. The data format varies according to the variable requested.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="getSystemProperty"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>object</em>
+      </span>
+      <span class="sympad">getSystemProperty</span>
+      <span class="normal">
+      (<em>string</em> key)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Synonym for <code><a href="#getProperty">getProperty()</a></code>.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>key</th>
+          <td>
+            The name of the system environment variable. The available variable names are listed in
+            <a href="#table1">Table 1. Property Variable Names</a>.
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            The value of the variable. The data format varies according to the variable requested.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="installPackage"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">installPackage</span>
+      <span class="normal">
+      (<em>string</em> path)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Installs the Android application or test package contained in packageFile
+            onto this device. If the application or test package is already installed, it is
+            replaced.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>path</th>
+          <td>
+            The fully-qualified path and filename of the <code>.apk</code> file to install.
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="instrument"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>dictionary</em>
+      </span>
+      <span class="sympad">instrument</span>
+      <span class="normal">
+      (
+            <em>string</em> className,
+            <em>dictionary</em> args)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Runs the specified component with Android instrumentation, and returns the results
+            in a dictionary whose exact format is dictated by the component being run. The
+            component must already be present on this device.
+        </p>
+        <p>
+            Use this method to start a test case that uses one of Android's test case classes.
+            See <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing
+            Fundamentals</a> to learn more about unit testing with the Android testing
+            framework.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>className</th>
+          <td>
+            The name of an Android component that is already installed on this device, in the
+            standard form packagename/classname, where packagename is the
+            Android package name of a <code>.apk</code> file on this device, and
+            classname is the class name of an Android component (Activity,
+            ContentProvider, Service, or BroadcastReceiver) in that file. Both
+            packagename and classname must be fully qualified. See
+            {@link android.content.ComponentName} for more details.
+          </td>
+        </tr>
+        <tr>
+          <th>args</th>
+          <td>
+            A dictionary containing flags and their values. These are passed to the component as it
+            is started. If the flag does not take a value, set its dictionary value to an empty
+            string.
+          </td>
+        </tr>
+      </table>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+        <ul class="nolist">
+            <li>
+                <p>
+                    A dictionary containing the component's output. The contents of the dictionary
+                    are defined by the component itself.
+                </p>
+                <p>
+                    If you use {@link android.test.InstrumentationTestRunner} as the class name in
+                    the componentName argument, then the result dictionary contains
+                    the single key "stream". The value of "stream" is a <em>string</em> containing
+                    the test output, as if <code>InstrumentationTestRunner</code> was run from the
+                    command line. The format of this output is described in
+                    <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+                    Testing in Other IDEs</a>.
+                </p>
+            </li>
+        </ul>
+    </div>
+    </div>
+  </div>
+</div>
+<A NAME="press"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">press</span>
+      <span class="normal">
+      (<em>string</em> name,
+      <em>integer</em> type)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Sends the key event specified by <code>type</code> to the key specified by
+            <code>keycode</code>.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>name</th>
+          <td>
+            The name of the keycode to send. See {@link android.view.KeyEvent} for a list of
+            keycode names. Use the keycode name, not its integer value.
+          </td>
+        </tr>
+        <tr>
+          <th>type</th>
+          <td>
+            The type of key event to send. The allowed values are <code><a href="#ACTION_DOWN">
+            DOWN</a></code>, <code><a href="#ACTION_UP">UP</a></code>, and
+            <code><a href="#ACTION_DOWN_AND_UP">DOWN_AND_UP</a></code>.
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="reboot"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">reboot</span>
+      <span class="normal">
+      (<em>string</em> bootloadType)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+                Reboots this device into the bootloader specified by <code>bootloadType</code>.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>into</th>
+          <td>
+            The type of bootloader to reboot into. The allowed values are
+            "bootloader", "recovery", or "None".
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="removePackage"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">removePackage</span>
+      <span class="normal">
+      (<em>string</em> package)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Deletes the specified package from this device, including its data and cache.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>package</th>
+          <td>
+            The Android package name of an <code>.apk</code> file on this device.
+          </td>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="shell"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>object</em>
+      </span>
+      <span class="sympad">shell</span>
+      <span class="normal">
+      (<em>string</em> cmd)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Executes an <code>adb</code> shell command and returns the result, if any.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>cmd</th>
+          <td>
+            The command to execute in the <code>adb</code> shell. The form of these commands is
+            described in the topic <a href="{@docRoot}guide/developing/tools/adb.html">Android
+            Debug Bridge</a>.
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            The results of the command, if any. The format of the results is determined by the
+            command.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="startActivity"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">startActivity</span>
+      <span class="normal">
+      (
+            <em>string</em> uri,
+            <em>string</em> action,
+            <em>string</em> data,
+            <em>string</em> mimetype,
+            <em>iterable</em> categories
+            <em>dictionary</em> extras,
+            <em>component</em> component,
+            <em>iterable</em> flags)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+           Starts an Activity on this device by sending an Intent constructed from the
+           supplied arguments.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>uri</th>
+          <td>
+            The URI for the Intent.
+            (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}).
+          </td>
+        </tr>
+        <tr>
+            <th>action</th>
+            <td>
+                The action for the Intent
+                (see {@link android.content.Intent#setAction(java.lang.String) Intent.setAction()}).
+            </td>
+        </tr>
+        <tr>
+            <th>data</th>
+            <td>
+                The data URI for the Intent
+                (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}).
+            </td>
+        </tr>
+        <tr>
+            <th>mimetype</th>
+            <td>
+                The MIME type for the Intent
+                (see {@link android.content.Intent#setType(java.lang.String) Intent.setType()}).
+            </td>
+        </tr>
+        <tr>
+            <th>categories</th>
+            <td>
+                An iterable data structure containing strings that define categories for the
+                Intent
+                (see
+                {@link android.content.Intent#addCategory(java.lang.String) Intent.addCategory()}).
+            </td>
+        </tr>
+        <tr>
+            <th>extras</th>
+            <td>
+                A dictionary of extra data for the Intent
+                (see
+                {@link android.content.Intent#putExtra(java.lang.String,java.lang.String)
+                Intent.putExtra()}
+                for an example).
+                <p>
+                    The key for each dictionary item should be a <em>string</em>. The item's value
+                    can be any simple or structured data type.
+                </p>
+            </td>
+        </tr>
+        <tr>
+            <th>component</th>
+            <td>
+                The component for the Intent
+                (see {@link android.content.ComponentName}). Using this argument will direct the
+                Intent to a specific class within a specific Android package.
+            </td>
+        </tr>
+        <tr>
+            <th>flags</th>
+            <td>
+                An iterable data structure containing flags that control how the Intent is handled
+                (see {@link android.content.Intent#setFlags(int) Intent.setFlags()}).
+            </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="takeSnapshot"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <code>
+            <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">
+                MonkeyImage
+            </a>
+        </code>
+      </span>
+      <span class="sympad">takeSnapshot</span>
+      <span class="normal">
+      ()
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Captures the entire screen buffer of this device, yielding a
+            screen capture of the current display.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            A <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">
+            MonkeyImage</a> object containing the image of the current display.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="touch"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">touch</span>
+      <span class="normal">
+      (
+            <em>integer</em> x,
+            <em>integer</em> y,
+            <em>string</em> type)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Sends a touch event specified by type to the screen location specified
+            by x and y.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>x</th>
+          <td>
+            The horizontal position of the touch in actual device pixels, starting from the left of
+            the screen in its current orientation.
+          </td>
+        </tr>
+        <tr>
+          <th>y</th>
+          <td>
+            The vertical position of the touch in actual device pixels, starting from the top of
+            the screen in its current orientation.
+          </td>
+        </tr>
+        <tr>
+            <th>type</th>
+            <td>
+                The type of key event to send. The allowed values are <code><a href="#ACTION_DOWN">
+                DOWN</a></code>, <code><a href="#ACTION_UP">UP</a></code>, and
+                <code><a href="#ACTION_DOWN_AND_UP">DOWN_AND_UP</a></code>.
+            </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="type"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">type</span>
+      <span class="normal">
+      (<em>string</em> message)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Sends the characters contained in message to this device, as if they
+            had been typed on the device's keyboard. This is equivalent to calling
+            <code><a href="#press">press()</a></code> for each keycode in <code>message</code>
+            using the key event type <code><a href="#ACTION_DOWN_AND_UP">DOWN_AND_UP</a></code>.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>message</th>
+          <td>
+              A string containing the characters to send.
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="wake"></A>
+<div class="jd-details api">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">wake</span>
+      <span class="normal">
+      ()
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Wakes the screen of this device.
+        </p>
+    </div>
+  </div>
+</div>
+<hr></hr>
+<h2>Appendix</h2>
+    <p class="table-caption" id="table1">
+        <strong>Table 1.</strong>Property variable names used with
+        <span class="sympad"><a href="#getProperty">getProperty()</a></span> and
+        <span class="sympad"><a href="#getSystemProperty">getSystemProperty()</a></span>.
+    </p>
+    <table>
+        <tr>
+            <th>
+                Property Group
+            </th>
+            <th>
+                Property
+            </th>
+            <th>
+                Description
+            </th>
+            <th>
+                Notes
+            </th>
+        </tr>
+        <tr>
+            <td rowspan="17"><code>build</code></td>
+            <td><code>board</code></td>
+            <td>Code name for the device's system board</td>
+            <td rowspan="17">
+                See {@link android.os.Build}
+            </td>
+        </tr>
+        <tr>
+            <td><code>brand</code></td>
+            <td>The carrier or provider for which the OS is customized.</td>
+        </tr>
+            <tr>
+            <td><code>device</code></td>
+            <td>The device design name.</td>
+        </tr>
+            <tr>
+            <td><code>fingerprint</code></td>
+            <td>A unique identifier for the currently-running build.</td>
+        </tr>
+            <tr>
+            <td><code>host</code></td>
+            <td></td>
+        </tr>
+            <tr>
+            <td><code>ID</code></td>
+            <td>A changelist number or label.</td>
+        </tr>
+            <tr>
+            <td><code>model</code></td>
+            <td>The end-user-visible name for the device.</td>
+        </tr>
+            <tr>
+            <td><code>product</code></td>
+            <td>The overall product name.</td>
+        </tr>
+            <tr>
+            <td><code>tags</code></td>
+            <td>Comma-separated tags that describe the build, such as "unsigned" and "debug".</td>
+        </tr>
+            <tr>
+            <td><code>type</code></td>
+            <td>The build type, such as "user" or "eng".</td>
+        </tr>
+        <tr>
+            <td><code>user</code></td>
+            <td></td>
+        </tr>
+        <tr>
+            <td><code>CPU_ABI</code></td>
+            <td>
+                The name of the native code instruction set, in the form CPU type plus
+                ABI convention.
+            </td>
+        </tr>
+        <tr>
+            <td><code>manufacturer</code></td>
+            <td>The product/hardware manufacturer.</td>
+        </tr>
+        <tr>
+            <td><code>version.incremental</code></td>
+            <td>
+                The internal code used by the source control system to represent this version
+                of the software.
+            </td>
+        </tr>
+        <tr>
+            <td><code>version.release</code></td>
+            <td>The user-visible name of this version of the software.</td>
+        </tr>
+        <tr>
+            <td><code>version.sdk</code></td>
+            <td>The user-visible SDK version associated with this version of the OS.</td>
+        </tr>
+        <tr>
+            <td><code>version.codename</code></td>
+            <td>
+                The current development codename, or "REL" if this version of the software has been
+                released.
+            </td>
+        </tr>
+        <tr>
+            <td rowspan="3"><code>display</code></td>
+            <td><code>width</code></td>
+            <td>The device's display width in pixels.</td>
+            <td rowspan="3">
+                See
+                {@link android.util.DisplayMetrics} for details.
+            </td>
+        </tr>
+        <tr>
+            <td><code>height</code></td>
+            <td>The device's display height in pixels.</td>
+        </tr>
+        <tr>
+            <td><code>density</code></td>
+            <td>
+                The logical density of the display. This is a factor that scales
+                DIP (Density-Independent Pixel) units to the device's resolution. DIP is adjusted so
+                that 1 DIP is equivalent to one pixel on a 160 pixel-per-inch display. For example,
+                on a 160-dpi screen, density = 1.0, while on a 120-dpi screen, density = .75.
+                <p>
+                    The value does not exactly follow the real screen size, but is adjusted to
+                    conform to large changes in the display DPI. See
+                    {@link android.util.DisplayMetrics#density} for more details.
+                </p>
+            </td>
+        </tr>
+        <tr>
+            <td rowspan="6"><code>am.current</code></td>
+            <td><code>package</code></td>
+            <td>The Android package name of the currently running package.</td>
+            <td rowspan="6">
+                The <code>am.current</code> keys return information about the currently-running
+                Activity.
+            </td>
+        </tr>
+        <tr>
+            <td><code>action</code></td>
+            <td>
+                The current activity's action. This has the same format as the <code>name</code>
+                attribute of the <code>action</code> element in a package manifest.
+            </td>
+        </tr>
+        <tr>
+            <td><code>comp.class</code></td>
+            <td>
+                The class name of the component that started the current Activity. See
+                <code><a href="#comppackage">comp.package</a></code> for more details.</td>
+        </tr>
+        <tr>
+            <td><a name="comppackage"><code>comp.package</code></a></td>
+            <td>
+                The package name of the component that started the current Activity. A component
+                is specified by a package name and the name of class that the package contains.
+            </td>
+        </tr>
+        <tr>
+            <td><code>data</code></td>
+            <td>The data (if any) contained in the Intent that started the current Activity.</td>
+        </tr>
+        <tr>
+            <td><code>categories</code></td>
+            <td>The categories specified by the Intent that started the current Activity.</td>
+        </tr>
+        <tr>
+            <td rowspan="3"><code>clock</code></td>
+            <td><code>realtime</code></td>
+            <td>
+                The number of milliseconds since the device rebooted, including deep-sleep
+                time.
+            </td>
+            <td rowspan="3">
+                See {@link android.os.SystemClock} for more information.
+            </td>
+        </tr>
+        <tr>
+            <td><code>uptime</code></td>
+            <td>
+                The number of milliseconds since the device rebooted, <em>not</em> including
+                deep-sleep time
+            </td>
+        </tr>
+        <tr>
+            <td><code>millis</code></td>
+            <td>current time since the UNIX epoch, in milliseconds.</td>
+        </tr>
+    </table>
diff --git a/docs/html/guide/developing/tools/MonkeyImage.jd b/docs/html/guide/developing/tools/MonkeyImage.jd
new file mode 100644
index 0000000..ae85cb5
--- /dev/null
+++ b/docs/html/guide/developing/tools/MonkeyImage.jd
@@ -0,0 +1,435 @@
+page.title=MonkeyImage
+@jd:body
+<style>
+    h4.jd-details-title {background-color: #DEE8F1;}
+</style>
+
+<p>
+    A monkeyrunner class to hold an image of the device or emulator's screen. The image is
+    copied from the screen buffer during a screenshot. This object's methods allow you to
+    convert the image into various storage formats, write the image to a file, copy parts of
+    the image, and compare this object to other <code>MonkeyImage</code> objects.
+</p>
+<p>
+    You do not need to create new instances of <code>MonkeyImage</code>. Instead, use
+<code><a href="{@docRoot}guide/developing/tools/MonkeyDevice.html#takeSnapshot">
+MonkeyDevice.takeSnapshot()</a></code> to create a new instance from a screenshot. For example, use:
+</p>
+<pre>
+newimage = MonkeyDevice.takeSnapshot()
+</pre>
+<h2>Summary</h2>
+<table id="pubmethods" class="jd-sumtable">
+    <tr>
+        <th colspan="12" style="background-color: #E2E2E2">Methods</th>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>string</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#convertToBytes">convertToBytes</a>
+                </span>
+                (<em>string</em> format)
+            </nobr>
+            <div class="jd-descrdiv">
+                Converts the current image to a particular format and returns it as a
+                <em>string</em> that you can then access as an <em>iterable</em> of binary bytes.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>tuple</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#getRawPixel">getRawPixel</a>
+                </span>
+                (<em>integer</em> x,
+                <em>integer</em> y)
+            </nobr>
+            <div class="jd-descrdiv">
+                Returns the single pixel at the image location (x,y), as an
+                a <em>tuple</em> of <em>integer</em>, in the form (a,r,g,b).
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>integer</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#getRawPixelInt">getRawPixelInt</a>
+                </span>
+                (<em>integer</em> x,
+                 <em>integer</em> y)
+            </nobr>
+            <div class="jd-descrdiv">
+                Returns the single pixel at the image location (x,y), as
+                a 32-bit <em>integer</em>.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <code>
+                    <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">MonkeyImage</a>
+                </code>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#getSubImage">getSubImage</a>
+                </span>
+                (<em>tuple</em> rect)
+            </nobr>
+            <div class="jd-descrdiv">
+                Creates a new <code>MonkeyImage</code> object from a rectangular selection of the
+                current image.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>boolean</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#sameAs">sameAs</a>
+                </span>
+         (<code><a href="{@docRoot}guide/developing/tools/MonkeyImage.html">MonkeyImage</a></code>
+            other,
+            <em>float</em> percent)
+            </nobr>
+            <div class="jd-descrdiv">
+                Compares this <code>MonkeyImage</code> object to another and returns the result of
+                the comparison. The <code>percent</code> argument specifies the percentage
+                difference that is allowed for the two images to be "equal".
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>void</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#writeToFile">writeToFile</a>
+                </span>
+                (<em>string</em> path,
+                <em>string</em> format)
+            </nobr>
+            <div class="jd-descrdiv">
+                Writes the current image to the file specified by <code>filename</code>, in the
+                format specified by <code>format</code>.
+            </div>
+        </td>
+    </tr>
+</table>
+<!-- ========= METHOD DETAIL ======== -->
+<!-- Public methods -->
+<h2>Public Methods</h2>
+<A NAME="convertToBytes"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>string</em>
+      </span>
+      <span class="sympad">convertToBytes</span>
+      <span class="normal">
+      (
+            <em>string</em> format)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Converts the current image to a particular format and returns it as a <em>string</em>
+            that you can then access as an <em>iterable</em> of binary bytes.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>format</th>
+            <td>
+                The desired output format. All of the common raster output formats are supported.
+                The default value is "png" (Portable Network Graphics).
+            </td>
+        </tr>
+        </table>
+    </div>
+</div>
+</div>
+<A NAME="getRawPixel"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>tuple</em>
+      </span>
+      <span class="sympad">getRawPixel</span>
+      <span class="normal">
+        (<em>integer</em> x,
+         <em>integer</em> y)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Returns the single pixel at the image location (x,y), as an
+            a <em>tuple</em> of <em>integer</em>, in the form (a,r,g,b).
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>x</th>
+          <td>
+            The horizontal position of the pixel, starting with 0 at the left of the screen in the
+            orientation it had when the screenshot was taken.
+          </td>
+        </tr>
+        <tr>
+          <th>y</th>
+          <td>
+            The vertical position of the pixel, starting with 0 at the top of the screen in the
+            orientation it had when the screenshot was taken.
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            A tuple of integers representing the pixel, in the form (a,r,g,b) where
+            a is the alpha channel value, and r, g, and b are the red, green, and blue values,
+            respectively.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="getRawPixelInt"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>tuple</em>
+      </span>
+      <span class="sympad">getRawPixelInt</span>
+      <span class="normal">
+        (<em>integer</em> x,
+         <em>integer</em> y)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Returns the single pixel at the image location (x,y), as an
+            an <em>integer</em>. Use this method to economize on memory.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>x</th>
+          <td>
+            The horizontal position of the pixel, starting with 0 at the left of the screen in the
+            orientation it had when the screenshot was taken.
+          </td>
+        </tr>
+        <tr>
+          <th>y</th>
+          <td>
+            The vertical position of the pixel, starting with 0 at the top of the screen in the
+            orientation it had when the screenshot was taken.
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            The a,r,g, and b values of the pixel as 8-bit values combined into a 32-bit
+            integer, with a as the leftmost 8 bits, r the next rightmost, and so forth.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="getSubImage"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+          <code>
+              <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">MonkeyImage</a>
+          </code>
+      </span>
+      <span class="sympad">getSubImage</span>
+      <span class="normal">
+        (<em>tuple</em> rect)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+           Creates a new <code>MonkeyImage</code> object from a rectangular selection of the
+           current image.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>rect</th>
+          <td>
+            A tuple (x, y, w, h) specifying the selection. x and y specify the 0-based pixel
+            position of the upper left-hand corner of the selection. w specifies the width of the
+            region, and h specifies its height, both in units of pixels.
+            <p>
+                The image's orientation is the same as the screen orientation at the time the
+                screenshot was made.
+            </p>
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            A new <code>MonkeyImage</code> object containing the selection.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="sameAs"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>boolean</em>
+      </span>
+      <span class="sympad">sameAs</span>
+      <span class="normal">
+      (
+       <code>
+           <a href="{@docRoot}guide/developing/tools/MonkeyImage.html">MonkeyImage</a>
+       </code> otherImage,
+       <em>float</em> percent
+      )
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+           Compares this <code>MonkeyImage</code> object to another and returns the result of
+           the comparison. The <code>percent</code> argument specifies the percentage
+           difference that is allowed for the two images to be "equal".
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>other</th>
+          <td>
+            Another <code>MonkeyImage</code> object to compare to this one.
+          </td>
+        </tr>
+        <tr>
+          <th>
+            percent
+          </th>
+          <td>
+            A float in the range 0.0 to 1.0, inclusive, indicating
+            the percentage of pixels that need to be the same for the method to return
+            <code>true</code>. The default is 1.0, indicating that all the pixels
+            must match.
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            Boolean <code>true</code> if the images match, or boolean <code>false</code> otherwise.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="writeToFile"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">writeToFile</span>
+      <span class="normal">
+      (<em>string</em> filename,
+       <em>string</em> format)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+           Writes the current image to the file specified by <code>filename</code>, in the
+           format specified by <code>format</code>.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>path</th>
+          <td>
+            The fully-qualified filename and extension of the output file.
+          </td>
+        </tr>
+        <tr>
+            <th>
+                format
+            </th>
+            <td>
+                The output format to use for the file. If no format is provided, then the
+                method tries to guess the format from the filename's extension. If no
+                extension is provided and no format is specified, then the default format of
+                "png" (Portable Network Graphics) is used.
+            </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
diff --git a/docs/html/guide/developing/tools/MonkeyRunner.jd b/docs/html/guide/developing/tools/MonkeyRunner.jd
new file mode 100644
index 0000000..871e06d
--- /dev/null
+++ b/docs/html/guide/developing/tools/MonkeyRunner.jd
@@ -0,0 +1,445 @@
+page.title=MonkeyRunner
+@jd:body
+<style>
+    h4.jd-details-title {background-color: #DEE8F1;}
+</style>
+<p>
+    A monkeyrunner class that contains static utility methods.
+</p>
+<h2>Summary</h2>
+<table id="pubmethods" class="jd-sumtable">
+    <tr>
+        <th colspan="12" style="background-color: #E2E2E2">Methods</th>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#alert">alert</a>
+                </span>
+                (<em>string</em> message,
+                 <em>string</em> title,
+                 <em>string</em> okTitle)
+            </nobr>
+            <div class="jd-descrdiv">
+                Displays an alert dialog to the process running the current
+                program.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>integer</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#choice">choice</a>
+                </span>
+                (<em>string</em> message,
+                 <em>iterable</em> choices,
+                 <em>string</em> title)
+            </nobr>
+            <div class="jd-descrdiv">
+                Displays a dialog with a list of choices to the process running the current program.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#help">help</a>
+                </span>
+                (<em>string</em> format)
+            </nobr>
+            <div class="jd-descrdiv">
+                Displays the monkeyrunner API reference in a style similar to that of Python's
+                <code>pydoc</code> tool, using the specified format.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <em>string</em>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#input">input</a>
+                </span>
+                (<em>string</em> message,
+                 <em>string</em> initialValue,
+                 <em>string</em> title,
+                 <em>string</em> okTitle,
+                 <em>string</em> cancelTitle)
+            </nobr>
+            <div class="jd-descrdiv">
+                Displays a dialog that accepts input.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                void
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#sleep">sleep</a>
+                </span>
+                (<em>float</em> seconds)
+            </nobr>
+            <div class="jd-descrdiv">
+                Pauses the current program for the specified number of seconds.
+            </div>
+        </td>
+    </tr>
+    <tr class="api" >
+        <td class="jd-typecol">
+            <nobr>
+                <code>
+                    <a href="{@docRoot}guide/developing/tools/MonkeyDevice.html">MonkeyDevice</a>
+                </code>
+            </nobr>
+        </td>
+        <td class="jd-linkcol" width="100%">
+            <nobr>
+                <span class="sympad">
+                    <a href="#waitForConnection">waitForConnection</a>
+                </span>
+                (<em>float</em> timeout,
+                <em>string</em> deviceId)
+            </nobr>
+            <div class="jd-descrdiv">
+                Tries to make a connection between the <code>monkeyrunner</code> backend and the
+                specified device or emulator.
+            </div>
+        </td>
+    </tr>
+</table>
+<!-- ========= METHOD DETAIL ======== -->
+<!-- Public methods -->
+<h2>Public Methods</h2>
+<A NAME="alert"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>string</em>
+      </span>
+      <span class="sympad">alert</span>
+      <span class="normal">
+      (
+            <em>string</em> message,
+            <em>string</em> title,
+            <em>string</em> okTitle)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Displays an alert dialog to the process running the current
+            program. The dialog is modal, so the program pauses until the user clicks the dialog's
+            button.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>message</th>
+            <td>
+                The message to display in the dialog.
+            </td>
+        </tr>
+        <tr>
+            <th>title</th>
+            <td>
+                The dialog's title. The default value is "Alert".
+            </td>
+        </tr>
+        <tr>
+            <th>okTitle</th>
+            <td>
+                The text displayed in the dialog button. The default value is "OK".
+            </td>
+        </tr>
+        </table>
+    </div>
+</div>
+</div>
+<A NAME="choice"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>integer</em>
+      </span>
+      <span class="sympad">choice</span>
+      <span class="normal">
+        (<em>string</em> message,
+         <em>iterable</em> choices,
+         <em>string</em> title)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Displays a dialog with a list of choices to the process running the current program. The
+            dialog is modal, so the program pauses until the user clicks one of the dialog's
+            buttons.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>message</th>
+          <td>
+            The prompt message displayed in the dialog.
+          </td>
+        </tr>
+        <tr>
+          <th>choices</th>
+          <td>
+            A Python iterable containing one or more objects that are displayed as strings. The
+            recommended form is an array of strings.
+          </td>
+        </tr>
+        <tr>
+            <th>
+                title
+            </th>
+            <td>
+               The dialog's title. The default is "Input".
+            </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            If the user makes a selection and clicks the "OK" button, the method returns
+            the 0-based index of the selection within the iterable.
+            If the user clicks the "Cancel" button, the method returns -1.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="help"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">help</span>
+      <span class="normal">
+        (<em>string</em> format)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Displays the monkeyrunner API reference in a style similar to that of Python's
+            <code>pydoc</code> tool, using the specified format.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>format</th>
+          <td>
+            The markup format to use in the output. The possible values are "text" for plain text
+            or "html" for HTML.
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="input"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        <em>string</em>
+      </span>
+      <span class="sympad">input</span>
+      <span class="normal">
+        (<em>string</em> message
+         <em>string</em> initialValue,
+         <em>string</em> title,
+         <em>string</em> okTitle,
+         <em>string</em> cancelTitle)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Displays a dialog that accepts input and returns it to the program. The dialog is
+            modal, so the program pauses until the user clicks one of the dialog's buttons.
+        </p>
+        <p>
+            The dialog contains two buttons, one of which displays the okTitle value
+            and the other the cancelTitle value. If the user clicks the okTitle button,
+            the current value of the input box is returned. If the user clicks the cancelTitle
+            button, an empty string is returned.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>message</th>
+          <td>
+            The prompt message displayed in the dialog.
+          </td>
+        </tr>
+        <tr>
+          <th>initialValue</th>
+          <td>
+            The initial value to display in the dialog. The default is an empty string.
+          </td>
+        </tr>
+        <tr>
+          <th>title</th>
+          <td>
+            The dialog's title. The default is "Input".
+          </td>
+        </tr>
+        <tr>
+          <th>okTitle</th>
+          <td>
+            The text displayed in the okTitle button. The default is "OK".
+          </td>
+        </tr>
+        <tr>
+          <th>cancelTitle</th>
+          <td>
+            The text displayed in the cancelTitle button. The default is "Cancel".
+          </td>
+        </tr>
+      </table>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+            If the user clicks the okTitle button, then the method returns the current value of
+            the dialog's input box. If the user clicks the cancelTitle button, the method returns
+            an empty string.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
+<A NAME="sleep"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+        void
+      </span>
+      <span class="sympad">sleep</span>
+      <span class="normal">
+      (
+       <em>float</em> seconds
+      )
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Pauses the current program for the specified number of seconds.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>seconds</th>
+          <td>
+            The number of seconds to pause.
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+</div>
+<A NAME="waitForConnection"></A>
+<div class="jd-details api ">
+    <h4 class="jd-details-title">
+      <span class="normal">
+          <code>
+              <a href="{@docRoot}guide/developing/tools/MonkeyDevice.html">MonkeyDevice</a>
+          </code>
+      </span>
+      <span class="sympad">waitForConnection</span>
+      <span class="normal">
+      (<em>float</em> timeout,
+       <em>string</em> deviceId)
+      </span>
+    </h4>
+  <div class="jd-details-descr">
+
+    <div class="jd-tagdata jd-tagdescr">
+        <p>
+            Tries to make a connection between the <code>monkeyrunner</code> backend and the
+            specified device or emulator.
+        </p>
+    </div>
+    <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Arguments</h5>
+      <table class="jd-tagtable">
+        <tr>
+          <th>timeout</th>
+          <td>
+            The number of seconds to wait for a connection. The default is to wait forever.
+          </td>
+        </tr>
+        <tr>
+            <th>
+                deviceId
+            </th>
+            <td>
+                A regular expression that specifies the serial number of the device or emulator. See
+                the topic
+                <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>
+                for a description of device and emulator serial numbers.
+            </td>
+        </tr>
+      </table>
+    </div>
+        <div class="jd-tagdata">
+      <h5 class="jd-tagtitle">Returns</h5>
+      <ul class="nolist">
+        <li>
+          A <code><a href="{@docRoot}guide/developing/tools/MonkeyDevice.html">MonkeyDevice</a></code>
+          instance for the device or emulator. Use this object to control and communicate with the
+          device or emulator.
+        </li>
+      </ul>
+    </div>
+  </div>
+</div>
diff --git a/docs/html/guide/developing/tools/index.jd b/docs/html/guide/developing/tools/index.jd
index 6e9fde1..899c0dc 100644
--- a/docs/html/guide/developing/tools/index.jd
+++ b/docs/html/guide/developing/tools/index.jd
@@ -3,27 +3,27 @@
 
 <img src="{@docRoot}assets/images/android_wrench.png" alt="" align="right">
 
-<p>The Android SDK includes a variety of custom tools that help you develop mobile 
-applications on the Android platform. The most important of these are the Android 
-Emulator and the Android Development Tools plugin for Eclipse, but the SDK also 
-includes a variety of other tools for debugging, packaging, and installing your 
+<p>The Android SDK includes a variety of custom tools that help you develop mobile
+applications on the Android platform. The most important of these are the Android
+Emulator and the Android Development Tools plugin for Eclipse, but the SDK also
+includes a variety of other tools for debugging, packaging, and installing your
 applications on the emulator. </p>
-    
+
  <dl>
   <dt><a href="adt.html">Android Development Tools Plugin</a> (for the Eclipse IDE)</dt>
-          <dd>The ADT plugin adds powerful extensions to the Eclipse integrated environment, 
-          making creating and debugging your Android applications easier and faster. If you 
-          use Eclipse, the ADT plugin gives you an incredible boost in developing Android 
+          <dd>The ADT plugin adds powerful extensions to the Eclipse integrated environment,
+          making creating and debugging your Android applications easier and faster. If you
+          use Eclipse, the ADT plugin gives you an incredible boost in developing Android
           applications.</dd>
   <dt><a href="emulator.html">Android Emulator</a></dt>
-    <dd>A QEMU-based device-emulation tool that you can use to design, 
+    <dd>A QEMU-based device-emulation tool that you can use to design,
     debug, and test your applications in an actual Android run-time environment. </dd>
 
   <dt><a href="avd.html">Android Virtual Devices (AVDs)</a></dt>
     <dd>Virtual device configurations that you create, to model device
         characteristics in the Android Emulator. In each configuration, you can
         specify the Android platform to run, the hardware options, and the
-        emulator skin to use. Each AVD functions as an independent device with 
+        emulator skin to use. Each AVD functions as an independent device with
         it's own storage for user data, SD card, and so on. </dd>
 
  <dt><a href="hierarchy-viewer.html">Hierarchy Viewer</a></dt>
@@ -37,64 +37,69 @@
 efficiency.
     </dd>
 
-	  <dt><a href="draw9patch.html">Draw 9-patch</a></dt>
-	    <dd>The Draw 9-patch tool allows you to easily create a 
-	    {@link android.graphics.NinePatch} graphic using a WYSIWYG editor. It also previews stretched 
-	     versions of the image, and highlights the area in which content is allowed.
-	    </dd>
+      <dt><a href="draw9patch.html">Draw 9-patch</a></dt>
+        <dd>The Draw 9-patch tool allows you to easily create a
+        {@link android.graphics.NinePatch} graphic using a WYSIWYG editor. It also previews stretched
+         versions of the image, and highlights the area in which content is allowed.
+        </dd>
 
-  <dt><a href="ddms.html" >Dalvik Debug Monitor 
+  <dt><a href="ddms.html" >Dalvik Debug Monitor
       Service</a> (ddms)</dt>
-	    <dd>Integrated with Dalvik, the Android platform's custom VM, this tool 
-	    lets you manage processes on an emulator or device and assists in debugging. 
-	    You can use it to kill processes, select a specific process to debug, 
-	    generate trace data, view heap and thread information, take screenshots 
-	    of the emulator or device, and more. </dd>
-			
+        <dd>Integrated with Dalvik, the Android platform's custom VM, this tool
+        lets you manage processes on an emulator or device and assists in debugging.
+        You can use it to kill processes, select a specific process to debug,
+        generate trace data, view heap and thread information, take screenshots
+        of the emulator or device, and more. </dd>
+
   <dt><a href="adb.html" >Android Debug Bridge</a> (adb)</dt>
-                  <dd>The adb tool lets you install your application's .apk files on an 
-                  emulator or device and access the emulator or device from a command line. 
-                  You can also use it to link a standard debugger to application code running 
+                  <dd>The adb tool lets you install your application's .apk files on an
+                  emulator or device and access the emulator or device from a command line.
+                  You can also use it to link a standard debugger to application code running
                   on an Android emulator or device.</dd>
 
-  <dt><a href="aapt.html">Android Asset 
+  <dt><a href="aapt.html">Android Asset
           Packaging Tool</a> (aapt)</dt>
-                  <dd>The aapt tool lets you create .apk files containing the binaries and 
+                  <dd>The aapt tool lets you create .apk files containing the binaries and
                   resources of Android applications.</dd>
 
-  <dt><a href="aidl.html" >Android Interface 
+  <dt><a href="aidl.html" >Android Interface
   Description Language</a> (aidl)</dt>
             <dd>Lets you generate code for an interprocess interface, such as what
             a service might use.</dd>
 
   <dt><a href="adb.html#sqlite">sqlite3</a></dt>
-      <dd>Included as a convenience, this tool lets you access the SQLite data 
+      <dd>Included as a convenience, this tool lets you access the SQLite data
       files created and used by Android applications.</dd>
 
   <dt><a href="traceview.html" >Traceview</a></dt>
-            <dd> This tool produces graphical analysis views of trace log data that you 
+            <dd> This tool produces graphical analysis views of trace log data that you
             can generate from your Android application. </dd>
 
   <dt><a href="othertools.html#mksdcard">mksdcard</a></dt>
-            <dd>Helps you create a disk image that you can use with the emulator, 
+            <dd>Helps you create a disk image that you can use with the emulator,
                       to simulate the presence of an external storage card (such as an SD card).</dd>
 
   <dt><a href="othertools.html#dx">dx</a></dt>
-                  <dd>The dx tool rewrites .class bytecode into Android bytecode 
+                  <dd>The dx tool rewrites .class bytecode into Android bytecode
                                           (stored in .dex files.)</dd>
 
-  <dt><a href="monkey.html">UI/Application 
+  <dt><a href="monkey.html">UI/Application
   Exerciser Monkey</a></dt>
       <dd>The Monkey is a program that runs on your emulator or device and generates pseudo-random
       streams of user events such as clicks, touches, or gestures, as well as a number of system-
       level events.  You can use the Monkey to stress-test applications that you are developing,
       in a random yet repeatable manner.</dd>
 
+  <dt><a href="monkeyrunner_concepts.html">monkeyrunner</a></dt>
+  <dd>
+    The monkeyrunner tool provides an API for writing Python programs that control an Android device
+    or emulator from outside of Android code.
+  </dd>
   <dt><a  href="othertools.html#android">android</a></dt>
             <dd>A script that lets you manage AVDs and generate <a
-                        href="http://ant.apache.org/" title="Ant">Ant</a> build files that 
+                        href="http://ant.apache.org/" title="Ant">Ant</a> build files that
                         you can use to compile your Android applications. </dd>
-                        
+
   <dt><a  href="zipalign.html">zipalign</a></dt>
             <dd>An important .apk optimization tool. This tool ensures that all uncompressed data starts
             with a particular alignment relative to the start of the file. This should always be used
diff --git a/docs/html/guide/developing/tools/monkeyrunner_concepts.jd b/docs/html/guide/developing/tools/monkeyrunner_concepts.jd
new file mode 100644
index 0000000..1838905
--- /dev/null
+++ b/docs/html/guide/developing/tools/monkeyrunner_concepts.jd
@@ -0,0 +1,308 @@
+page.title=monkeyrunner
+@jd:body
+
+<div id="qv-wrapper">
+  <div id="qv">
+  <h2>In this document</h2>
+  <ol>
+    <li>
+        <a href="#SampleProgram">A Simple monkeyrunner Program</a>
+    </li>
+    <li>
+        <a href="#APIClasses">The monkeyrunner API</a>
+    </li>
+    <li>
+        <a href="#RunningMonkeyRunner">Running monkeyrunner</a>
+    </li>
+    <li>
+        <a href="#Help">monkeyrunner Built-in Help</a>
+    </li>
+    <li>
+        <a href="#Plugins">Extending monkeyrunner with Plugins</a>
+    </li>
+  </ol>
+  <h2>See Also</h2>
+      <ol>
+        <li>
+            <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>
+        </li>
+      </ol>
+  </div>
+</div>
+<p>
+    The monkeyrunner tool provides an API for writing programs that control an Android device
+    or emulator from outside of Android code. With monkeyrunner, you can write a Python program
+    that installs an Android application or test package, runs it, sends keystrokes to it,
+    takes screenshots of its user interface, and stores screenshots on the workstation. The
+    monkeyrunner tool is primarily designed to test applications and devices at the
+    functional/framework level and for running unit test suites, but you are free to use it for
+    other purposes.
+</p>
+<p>
+    The monkeyrunner tool is not related to the
+    <a href="{@docRoot}guide/developing/tools/monkey.html">UI/Application Exerciser Monkey</a>,
+    also known as the <code>monkey</code> tool. The <code>monkey</code> tool runs in an
+    <code><a href="{@docRoot}guide/developing/tools/adb.html">adb</a></code> shell directly on the
+    device or emulator and generates pseudo-random streams of user and system events. In comparison,
+    the monkeyrunner tool controls devices and emulators from a workstation by sending specific
+    commands and events from an API.
+</p>
+<p>
+    The monkeyrunner tool provides these unique features for Android testing:
+</p>
+<ul>
+    <li>
+        Multiple device control: The monkeyrunner API can apply one or more
+        test suites across multiple devices or emulators. You can physically attach all the devices
+        or start up all the emulators (or both) at once, connect to each one in turn
+        programmatically, and then run one or more tests. You can also start up an emulator
+        configuration programmatically, run one or more tests, and then shut down the emulator.
+    </li>
+    <li>
+        Functional testing: monkeyrunner can run an automated start-to-finish test of an Android
+        application. You provide input values with keystrokes or touch events, and view the results
+        as screenshots.
+    </li>
+    <li>
+        Regression testing - monkeyrunner can test application stability by running an application
+        and comparing its output screenshots to a set of screenshots that are known to be correct.
+    </li>
+    <li>
+        Extensible automation - Since monkeyrunner is an API toolkit, you can develop an entire
+        system of Python-based modules and programs for controlling Android devices. Besides using
+        the monkeyrunner API itself, you can use the standard Python
+        <code><a href="http://docs.python.org/library/os.html">os</a></code> and
+        <code><a href="http://docs.python.org/library/subprocess.html">subprocess</a></code>
+        modules to call Android tools such as
+        <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>.
+        <p>
+            You can also add your own classes to the monkeyrunner API. This is described
+            in more detail in the section
+            <a href="#Plugins">Extending monkeyrunner with plugins</a>.
+        </p>
+    </li>
+</ul>
+<p>
+    The monkeyrunner tool uses <a href="http://www.jython.org/">Jython</a>, a
+    implementation of Python that uses the Java programming language. Jython allows the
+    monkeyrunner API to interact easily with the Android framework. With Jython you can
+    use Python syntax to access the constants, classes, and methods of the API.
+</p>
+
+<h2 id="SampleProgram">A Simple monkeyrunner Program</h2>
+<p>
+    Here is a simple monkeyrunner program that connects to a device, creating a
+    <code><a href="{@docRoot}guide/developing/tools/MonkeyDevice.html">MonkeyDevice</a></code>
+    object. Using the <code>MonkeyDevice</code> object, the program installs an Android application
+    package, runs one of its activities, and sends key events to the activity.
+    The program then takes a screenshot of the result, creating a
+    <code><a href="{@docRoot}guide/developing/tools/MonkeyImage.html">MonkeyImage</a></code> object.
+    From this object, the program writes out a <code>.png</code> file containing the screenshot.
+</p>
+<pre>
+# Imports the monkeyrunner modules used by this program
+from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
+
+# Connects to the current device, returning a MonkeyDevice object
+device = MonkeyRunner.waitForConnection()
+
+# Installs the Android package. Notice that this method returns a boolean, so you can test
+# to see if the installation worked.
+device.installPackage('myproject/bin/MyApplication.apk')
+
+# Runs an activity in the application
+device.startActivity(component='com.example.android.myapplication.MainActivity')
+
+# Presses the Menu button
+device.press('KEYCODE_MENU','DOWN_AND_UP')
+
+# Takes a screenshot
+result = device.takeSnapShot
+
+# Writes the screenshot to a file
+result.writeToFile('myproject/shot1.png','png')
+</pre>
+
+<h2 id="APIClasses">The monkeyrunner API</h2>
+<p>
+    The monkeyrunner API is contained in three modules in the package
+    <code>com.android.monkeyrunner</code>:
+</p>
+<ul>
+    <li>
+        <code><a href="{@docRoot}guide/developing/tools/MonkeyRunner.html">MonkeyRunner</a></code>:
+        A class of utility methods for monkeyrunner programs. This class provides a method for
+        connecting monkeyrunner to a device or emulator. It also provides methods for
+        creating UIs for a monkeyrunner program and for displaying the built-in help.
+    </li>
+    <li>
+        <code><a href="{@docRoot}guide/developing/tools/MonkeyDevice.html">MonkeyDevice</a></code>:
+        Represents a device or emulator. This class provides methods for installing and
+        uninstalling packages, starting an Activity, and sending keyboard or touch events to an
+        application. You also use this class to run test packages.
+    </li>
+    <li>
+        <code><a href="{@docRoot}guide/developing/tools/MonkeyImage.html">MonkeyImage</a></code>:
+        Represents a screen capture image. This class provides methods for capturing screens,
+        converting bitmap images to various formats, comparing two MonkeyImage objects, and
+        writing an image to a file.
+    </li>
+</ul>
+<p>
+    In a Python program, you access each class as a Python module. The monkeyrunner tool
+    does not import these modules automatically. To import a module, use the
+    Python <code>from</code> statement:
+</p>
+<pre>
+from com.android.monkeyrunner import &lt;module&gt;
+</pre>
+<p>
+    where <code>&lt;module&gt;</code> is the class name you want to import. You can import more
+    than one module in the same <code>from</code> statement by separating the module names with
+    commas.
+</p>
+<h2 id="RunningMonkeyRunner">Running monkeyrunner</h2>
+<p>
+    You can either run monkeyrunner programs from a file, or enter monkeyrunner statements in
+    an interactive session. You do both by invoking the <code>monkeyrunner</code> command
+    which is found in the <code>tools/</code> subdirectory of your SDK directory.
+    If you provide a filename as an argument, the <code>monkeyrunner</code> command
+    runs the file's contents as a Python program; otherwise, it starts an interactive session.
+</p>
+<p>
+    The syntax of the <code>monkeyrunner</code> command is
+</p>
+<pre>
+monkeyrunner -plugin &lt;plugin_jar&gt; &lt;program_filename&gt; &lt;program_options&gt;
+</pre>
+<p>
+Table 1 explains the flags and arguments.
+</p>
+<p class="table-caption" id="table1">
+  <strong>Table 1.</strong> <code>monkeyrunner</code> flags and arguments.</p>
+
+<table>
+    <tr>
+        <th>Argument</th>
+        <th>Description</th>
+    </tr>
+    <tr>
+        <td>
+            <nobr>
+                <code>-plugin &lt;plugin_jar&gt;</code>
+            </nobr>
+        </td>
+        <td>
+            (Optional) Specifies a <code>.jar</code> file containing a plugin for monkeyrunner.
+            To learn more about monkeyrunner plugins, see
+            <a href="#Plugins">Extending monkeyrunner with plugins</a>. To specify more than one
+            file, include the argument multiple times.
+        </td>
+    </tr>
+    <tr>
+        <td>
+            <nobr>
+                <code>&lt;program_filename&gt;</code>
+            </nobr>
+        </td>
+        <td>
+            If you provide this argument, the <code>monkeyrunner</code> command runs the contents
+            of the file as a Python program. If the argument is not provided, the command starts an
+            interactive session.
+        </td>
+    </tr>
+    <tr>
+        <td>
+            <code>&lt;program_options&gt;</code>
+        </td>
+        <td>
+            (Optional) Flags and arguments for the program in &lt;program_file&gt;.
+        </td>
+    </tr>
+</table>
+<h2 id="Help">monkeyrunner Built-in Help</h2>
+<p>
+    You can generate an API reference for monkeyrunner by running:
+</p>
+<pre>
+monkeyrunner &lt;format&gt; help.py &lt;outfile&gt;
+</pre>
+<p>
+The arguments are:
+</p>
+    <ul>
+        <li>
+            <code>&lt;format&gt;</code> is either <code>text</code> for plain text output
+            or <code>html</code> for HTML output.
+        </li>
+        <li>
+            <code>&lt;outfile&gt;</code> is a path-qualified name for the output file.
+        </li>
+    </ul>
+<h2 id="Plugins">Extending monkeyrunner with Plugins</h2>
+<p>
+    You can extend the monkeyrunner API with classes you write in the Java programming language
+    and build into one or more <code>.jar</code> files. You can use this feature to extend the
+    monkeyrunner API with your own classes or to extend the existing classes. You can also use this
+    feature to initialize the monkeyrunner environment.
+</p>
+<p>
+    To provide a plugin to monkeyrunner, invoke the <code>monkeyrunner</code> command with the
+    <code>-plugin &lt;plugin_jar&gt;</code> argument described in
+    <a href="#table1">table 1</a>.
+</p>
+<p>
+    In your plugin code, you can import and extend the the main monkeyrunner classes
+    <code>MonkeyDevice</code>, <code>MonkeyImage</code>, and <code>MonkeyRunner</code> in
+    <code>com.android.monkeyrunner</code> (see <a href="#APIClasses">The monkeyrunner API</a>).
+</p>
+<p>
+    Note that plugins do not give you access to the Android SDK. You can't import packages
+    such as <code>com.android.app</code>. This is because monkeyrunner interacts with the
+    device or emulator below the level of the framework APIs.
+</p>
+<h3>The plugin startup class</h3>
+<p>
+    The <code>.jar</code> file for a plugin can specify a class that is instantiated before
+    script processing starts. To specify this class, add the key
+    <code>MonkeyRunnerStartupRunner</code> to the <code>.jar</code> file's
+    manifest. The value should be the name of the class to run at startup. The following
+    snippet shows how you would do this within an <code>ant</code> build script:
+</p>
+<pre>
+&lt;jar jarfile=&quot;myplugin&quot; basedir="&#36;&#123;build.dir&#125;&quot;&gt;
+&lt;manifest&gt;
+&lt;attribute name=&quot;MonkeyRunnerStartupRunner&quot; value=&quot;com.myapp.myplugin&quot;/&gt;
+&lt;/manifest&gt;
+&lt;/jar&gt;
+
+
+</pre>
+<p>
+    To get access to monkeyrunner's runtime environment, the startup class can implement
+    <code>com.google.common.base.Predicate&lt;PythonInterpreter&gt;</code>. For example, this
+    class sets up some variables in the default namespace:
+</p>
+<pre>
+package com.android.example;
+
+import com.google.common.base.Predicate;
+import org.python.util.PythonInterpreter;
+
+public class Main implements Predicate&lt;PythonInterpreter&gt; {
+    &#64;Override
+    public boolean apply(PythonInterpreter anInterpreter) {
+
+        /*
+        * Examples of creating and initializing variables in the monkeyrunner environment's
+        * namespace. During execution, the monkeyrunner program can refer to the variables "newtest"
+        * and "use_emulator"
+        *
+        */
+        anInterpreter.set("newtest", "enabled");
+        anInterpreter.set("use_emulator", 1);
+
+        return true;
+    }
+}
+</pre>
diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs
index 2b803424..a43e334 100644
--- a/docs/html/guide/guide_toc.cs
+++ b/docs/html/guide/guide_toc.cs
@@ -254,34 +254,45 @@
             <li><a href="<?cs var:toroot?>guide/topics/search/searchable-config.html">Searchable Configuration</a></li>
           </ul>
       </li>
-      <li class="toggle-list">
-           <div>
-                <a href="<?cs var:toroot ?>guide/topics/testing/index.html">
-                   <span class="en">Testing</span>
-               </a> <span class="new">new!</span>
-           </div>
-           <ul>
-              <li><a href="<?cs var:toroot?>guide/topics/testing/testing_android.html">
-                <span class="en">Testing Fundamentals</span></a>
-              </li>
-              <li><a href="<?cs var:toroot?>guide/topics/testing/activity_testing.html">
-                <span class="en">Activity Testing</span></a>
-              </li>
-              <li><a href="<?cs var:toroot ?>guide/topics/testing/contentprovider_testing.html">
-                <span class="en">Content Provider Testing</span></a>
-              </li>
-              <li><a href="<?cs var:toroot ?>guide/topics/testing/service_testing.html">
-                <span class="en">Service Testing</span></a>
-              </li>
-              <li><a href="<?cs var:toroot ?>guide/topics/testing/what_to_test.html">
-                <span class="en">What To Test</span></a>
-              </li>
-           </ul>
-      </li>
-     <li><a href="<?cs var:toroot?>guide/topics/admin/device-admin.html">
+      <li><a href="<?cs var:toroot?>guide/topics/admin/device-admin.html">
             <span class="en">Device Administration</span>
          </a> <span class="new">new!</span>
-    </li>
+      </li>
+      <li class="toggle-list">
+           <div>
+                <a href="<?cs var:toroot?>guide/topics/testing/index.html">
+                   <span class="en">Testing</span>
+               </a>
+           </div>
+           <ul>
+              <li>
+                <a href="<?cs var:toroot?>guide/topics/testing/testing_android.html">
+                <span class="en">Testing Fundamentals</span></a>
+                <span class="new">new!</span>
+              </li>
+              <li>
+                <a href="<?cs var:toroot?>guide/topics/testing/activity_testing.html">
+                <span class="en">Activity Testing</span></a>
+                <span class="new">new!</span>
+              </li>
+              <li>
+                <a href="<?cs var:toroot?>guide/topics/testing/contentprovider_testing.html">
+                <span class="en">Content Provider Testing</span></a>
+                <span class="new">new!</span>
+              </li>
+              <li>
+                <a href="<?cs var:toroot?>guide/topics/testing/service_testing.html">
+                <span class="en">Service Testing</span></a>
+                <span class="new">new!</span>
+              </li>
+              <li>
+                <a href="<?cs var:toroot ?>guide/topics/testing/what_to_test.html">
+                <span class="en">What To Test</span></a>
+                <span class="new">new!</span>
+              </li>
+
+           </ul>
+      </li>
     </ul>
   </li>
 
@@ -336,6 +347,7 @@
                   <span class="en">Testing in Eclipse, with ADT</span>
                 </a>
               </li>
+
               <li>
                 <a href="<?cs var:toroot ?>guide/developing/testing/testing_otheride.html">
                   <span class="en">Testing in Other IDEs</span>
@@ -363,6 +375,34 @@
               <li><a href="<?cs var:toroot ?>guide/developing/tools/layoutopt.html">layoutopt</a></li>
               <li><a href="<?cs var:toroot ?>guide/developing/tools/othertools.html#mksdcard">mksdcard</a></li>
               <li><a href="<?cs var:toroot ?>guide/developing/tools/monkey.html">Monkey</a></li>
+                            <li class="toggle-list">
+                 <div>
+                     <a href="<?cs var:toroot?>guide/developing/tools/monkeyrunner_concepts.html">
+                     <span class="en">monkeyrunner</span>
+                  </a>
+                      <span class="new">new!</span>
+                  </div>
+                  <ul>
+                      <li>
+                          <a href="<?cs var:toroot?>guide/developing/tools/MonkeyDevice.html">
+                                <span class="en">MonkeyDevice</span>
+                        </a>
+                        <span class="new">new!</span>
+                    </li>
+                    <li>
+                        <a href="<?cs var:toroot?>guide/developing/tools/MonkeyImage.html">
+                            <span class="en">MonkeyImage</span>
+                        </a>
+                        <span class="new">new!</span>
+                    </li>
+                    <li>
+                        <a href="<?cs var:toroot?>guide/developing/tools/MonkeyRunner.html">
+                            <span class="en">MonkeyRunner</span>
+                        </a>
+                        <span class="new">new!</span>
+                    </li>
+                  </ul>
+              </li>
               <li><a href="<?cs var:toroot ?>guide/developing/tools/adb.html#sqlite">sqlite3</a></li>
               <li><a href="<?cs var:toroot ?>guide/developing/tools/traceview.html" >Traceview</a></li>
               <li><a href="<?cs var:toroot ?>guide/developing/tools/zipalign.html" >zipalign</a></li>
diff --git a/docs/html/guide/topics/manifest/uses-feature-element.jd b/docs/html/guide/topics/manifest/uses-feature-element.jd
index 4066daa..45f4a66 100644
--- a/docs/html/guide/topics/manifest/uses-feature-element.jd
+++ b/docs/html/guide/topics/manifest/uses-feature-element.jd
@@ -5,9 +5,9 @@
 
 <dt>syntax:</dt>
 <dd>
-<pre class="stx">&lt;uses-feature android:<a href="#glEsVersion">glEsVersion</a>="<em>integer</em>"
-              android:<a href="#name">name</a>="<em>string</em>"
-              android:<a href="#required">required</a>=["true" | "false"] /&gt;</pre>
+<pre class="stx">&lt;uses-feature android:<a href="#name">name</a>="<em>string</em>"
+              android:<a href="#required">required</a>=["true" | "false"]
+              android:<a href="#glEsVersion">glEsVersion</a>="<em>integer</em>" /&gt;</pre>
 </dd>
 
 <dt>contained in:</dt>
@@ -18,8 +18,8 @@
   <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png"> 
   <div id="qv-sub-rule"> 
     <img src="{@docRoot}assets/images/icon_market.jpg" style="float:left;margin:0;padding:0;"> 
-    <p style="color:#669999;">Android Market and &lt;uses-feature&gt; elements</p> 
-    <p>Android Market filters the applications that are visible to users, so
+    <p style="color:#669999;">Android Market and <code style="color:#669999;">&lt;uses-feature&gt;</code> elements</p>
+    <p style="margin-top:1em;">Android Market filters the applications that are visible to users, so
 that users can see and download only those applications that are compatible with their
 devices. One of the ways Market filters applications is by feature compatibility.</p>
 
@@ -27,70 +27,82 @@
 <code>&lt;uses-feature&gt;</code> elements in each application's manifest, to
 establish the app's feature needs. Market then shows or hides the application to
 each user, based on a comparison with the features available on the user's
-device. For more information, see <a
-href="{@docRoot}guide/appendix/market-filters.html">Market Filters</a>.</p>
+device. </p>
 
-<p style="margin-top:1em;">By specifying the features your application requires,
+<p style="margin-top:1em;">By specifying the features that your application requires,
 you enable Android Market to present your application only to users whose
 devices meet the application's feature requirements, rather than presenting it
 to all users. </p>
+
+<p style="margin-top:1em;" class="caution">For important information about how
+Android Market uses features as the basis for filtering, please read <a
+href="#market-feature-filtering">Android Market and Feature-Based Filtering</a>,
+below.</p>
 </div>
 </div>
 
 <dt>description:</dt>
-<dd>This element declares a specific feature used by the application. Android
-provides some features that may not be equally supported by all Android devices.
-In a manner similar to the <a
-href="uses-sdk-element.html">{@code &lt;uses-sdk>}</a> element, this element
-allows an application to specify which device-variable features it uses. For
-example, an application might specify that it requires a camera with auto-focus
-capabilities.</p>
+<dd>Declares a single hardware or software feature that is used by the
+application.
 
-<p>Declaring a {@code &lt;uses-feature>} element is informational only, meaning
+<p>The purpose of a <code>&lt;uses-feature&gt;</code> declaration is to inform
+any external entity of the set of hardware and software features on which your
+application depends. The element offers a <code>required</code> attribute that
+lets you specify whether your application requires and cannot function without
+the declared feature, or whether it prefers to have the feature but can function
+without it. Because feature support can vary across Android devices, the
+<code>&lt;uses-feature&gt;</code> element serves an important role in letting an
+application describe the device-variable features that it uses.</p>
+
+<p>The set of available features that your application declares corresponds to
+the set of feature constants made available by the Android {@link
+android.content.pm.PackageManager}, which are listed for
+convenience in the <a href="#features-reference">Features Reference</a> tables
+at the bottom of this document.
+
+<p>You must specify each feature in a separate <code>&lt;uses-feature&gt;</code>
+element, so if your application requires multiple features, it would declare
+multiple <code>&lt;uses-feature&gt;</code> elements. For example, an application
+that requires both Bluetooth and camera features in the device would declare
+these two elements:</p>
+
+<pre>
+&lt;uses-feature android:name="android.hardware.bluetooth" />
+&lt;uses-feature android:name="android.hardware.camera" />
+</pre>
+
+<p>In general, you should always make sure to declare
+<code>&lt;uses-feature&gt;</code> elements for all of the features that your
+application requires.</p>
+
+<p>Declared <code>&lt;uses-feature></code> elements are informational only, meaning
 that the Android system itself does not check for matching feature support on
-the device before installing an application. However, note that other services
+the device before installing an application. However, other services
 (such as Android Market) or applications may check your application's 
-{@code &lt;uses-feature>} declarations as part of handling or interacting 
+<code>&lt;uses-feature></code> declarations as part of handling or interacting
 with your application. For this reason, it's very important that you declare all of
 the features (from the list below) that your application uses. </p>
 
 <p>For some features, there may exist a specfic attribute that allows you to define
 a version of the feature, such as the version of Open GL used (declared with
-<a href="#glEsVersion">{@code glEsVersion}</a>). Other features that either do or do not
+<a href="#glEsVersion"><code>glEsVersion</code></a>). Other features that either do or do not
 exist for a device, such as a camera, are declared using the
-<a href="#name">{@code name}</a> attribute.</p>
+<a href="#name"><code>name</code></a> attribute.</p>
 
-<p>Any software or hardware features that may vary among Android-powered devices
-will be listed on this page among the attributes below. If you see any features
-here that you use in your application, you should include a
-{@code &lt;uses-feature>} element for each one. For example, if your
-application uses the device camera, then you should include the following in
-your {@code AndroidManifest.xml}:</p>
 
-<pre>
-&lt;uses-feature android:name="android.hardware.camera" />
-</pre>
+<p>Although the <code>&lt;uses-feature></code> element is only activated for
+devices running API Level 4 or higher, it is recommended to include these
+elements for all applications, even if the <a href="uses-sdk-element.html#min"><code>minSdkVersion</code></a>
+is "3" or lower. Devices running older versions of the platform will simply
+ignore the element.</p>
 
-<p>If you declare {@code android.hardware.camera} this way, then your application is considered
-compatible with all devices that include a camera. If your application also uses auto-focus
-features, then you also need to include a
-{@code &lt;uses-feature>} element that declares the {@code android.hardware.camera.autofocus}
-feature. Also note that you must still request the {@link android.Manifest.permission#CAMERA
-CAMERA} permission. Requesting the permission grants your application access to the
-appropriate hardware and software, while declaring the features used by
-your application ensures proper device compatibility.</p>
-
-<p>Although the {@code &lt;uses-feature>} element is only activated for devices running 
-API Level 4 or higher, it is safe to include this for applications that declare 
-a <a href="uses-sdk-element.html#min">{@code minSdkVersion}</a> 
-of "3" or lower. Devices running older versions of the platform 
-will simply ignore this element, but newer devices will recognize it and enforce 
-installation restrictions based on whether the device supports the feature.</p>
-
-<p class="note"><strong>Note:</strong>
-For each feature required by your application, you must include a new {@code
-&lt;uses-feature>} element. Multiple features cannot be declared in one 
-instance of this element.</p>
+<p class="note"><strong>Note:</strong> When declaring a feature, remember
+that you must also request permissions as appropriate. For example, you must
+still request the {@link android.Manifest.permission#CAMERA}
+permission before your application can access the camera API. Requesting the
+permission grants your application access to the appropriate hardware and
+software, while declaring the features used by your application ensures proper
+device compatibility.</p>
 
 </dd> 
 
@@ -99,7 +111,35 @@
 
 <dd>
 <dl class="attr">
-  <dt><a name="glEsVersion"></a>{@code android:glEsVersion}</dt>
+
+  <dt><a name="name"></a><code>android:name</code></dt>
+  <dd>Specifies a single hardware or software feature used by the application,
+as a descriptor string. Valid descriptor values are listed in the <a
+href="#hw-features">Hardware features</a> and <a href="#sw-features">Software
+features</a> tables, below. </dd>
+
+  <dt><a name="required"></a><code>android:required</code></dt>  <!-- added in api level 5 -->
+  <dd>Boolean value that indicates whether the application requires
+  the feature specified in <code>android:name</code>.
+
+<ul>
+<li>When you declare <code>"android:required="true"</code> for a feature,
+you are specifying that the application <em>cannot function, or is not
+designed to function</em>, when the specified feature is not present on the
+device. </li>
+
+<li>When you declare <code>"android:required="false"</code> for a feature, it
+means that the application <em>prefers to use the feature</em> if present on
+the device, but that it <em>is designed to function without the specified
+feature</em>, if necessary. </li>
+
+</ul>
+
+<p>The default value for <code>android:required</code> if not declared is
+<code>"true"</code>.</p>
+  </dd>
+
+  <dt><a name="glEsVersion"></a><code>android:glEsVersion</code></dt>
   <dd>The OpenGL ES version required by the application. The higher 16 bits
 represent the major number and the lower 16 bits represent the minor number. For
 example, to specify OpenGL ES version 2.0, you would set the value as
@@ -125,110 +165,6 @@
 can check at run-time whether a higher level of OpenGL ES is available.)</p>
   </dd>
 
-  <dt><a name="name"></a>{@code android:name}</dt>
-  <dd>The name of a feature required by the application. 
-  The value must be one of the following accepted strings:
-
-  <table>
-    <tr> 
-       <th>Feature</th>
-       <th>Attribute Value</th> 
-       <th>Description</th> 
-    </tr><tr>
-       <td rowspan="2">Camera</td>
-       <td>{@code android.hardware.camera}</td>
-       <td>The application requires a camera.</td> 
-    </tr><tr>
-       <td colspan="2">
-         <strong>Note:</strong> Any application that requests the 
-         {@link android.Manifest.permission#CAMERA} permission but does <em>not</em>
-         declare any camera features with the {@code &lt;uses-feature>} element will be assumed
-         to use all camera features (auto-focus and flash). Thus, the application will not
-         be compatible with devices that do not support all camera features. Please use
-         {@code &lt;uses-feature>} to declare only the camera features that your
-         application does need. For instance, if you request the
-         {@link android.Manifest.permission#CAMERA} permission, but you do not need auto-focus or
-          flash, then declare only the {@code android.hardware.camera} feature&mdash;the other
-          camera features that you do not request will no longer be assumed as required.
-       </td>
-    </tr><tr>
-      <td>Camera auto-focus</td>
-      <td>{@code android.hardware.camera.autofocus}</td>
-      <td>The application requires a camera with auto-focus capability.
-       As a prerequisite, {@code android.hardware.camera} must also be declared
-       with a separate {@code &lt;uses-feature>} element.
-      </td>
-    </tr><tr>
-      <td>Camera flash</td>
-      <td>{@code android.hardware.camera.flash}</td>
-      <td>The application requires a camera with a flash.
-        As a prerequisite, both {@code android.hardware.camera} and {@code
-        android.hardware.camera.autofocus} must also be declared
-        with separate {@code &lt;uses-feature>} elements.
-      </td>
-    </tr><tr>
-      <td>Light sensor</td>
-      <td>{@code android.hardware.sensor.light}</td>
-      <td>The application requires a device with a light sensor.
-      </td>
-    </tr><tr>
-      <td>Live Wallpaper</td>
-      <td>{@code android.software.live_wallpaper}</td>
-      <td>The application uses or provides Live Wallpapers and should be installed only on devices that support Live Wallpapers.
-      </td>
-    </tr><tr>
-      <td>Proximity sensor</td>
-      <td>{@code android.hardware.sensor.proximity}</td>
-      <td>The application requires a device with a proximity sensor.
-      </td>
-    </tr><tr>
-      <td>Multitouch screen</td>
-      <td>{@code android.hardware.touchscreen.multitouch}</td>
-      <td>The application requires a device that supports multitouch.
-      </td>
-    </tr><tr>
-      <td>Telephony</td>
-      <td>{@code android.hardware.telephony}</td>
-      <td>The application requires a device that includes a telephony radio with data
-         communication services.
-      </td>
-    </tr><tr>
-      <td>CDMA telephony</td>
-      <td>{@code android.hardware.telephony.cdma}</td>
-      <td>The application requires a device that includes a CDMA telephony radio. As a
-        prerequisite, {@code android.hardware.telephony} must also be declared
-        with a separate {@code &lt;uses-feature>} element.
-      </td>
-    </tr><tr>
-      <td>GSM telephony</td>
-      <td>{@code android.hardware.telephony.gsm}</td>
-      <td>The application requires a device that includes a GSM telephony radio. As a
-        prerequisite, {@code android.hardware.telephony} must also be declared
-        with a separate {@code &lt;uses-feature>} element.
-      </td>
-    </tr>
-  </table>
-  </dd>
-
-  <dt><a name="required"></a>{@code android:required}</dt>  <!-- added in api level 5 -->
-  <dd>Indicates whether the feature is required by the application. This is
-    {@code true} by default. <strong>You should not use this attribute for most cases.</strong>
-    </p>
-
-    <p>The only situation in which you should set this attribute {@code false} is when your
-    application requests the {@link android.Manifest.permission#CAMERA} permission, but will degrade
-    gracefully and perform without failure if the device does not have a camera. In this situation,
-    you must declare the {@code android.hardware.camera} feature and set the {@code required}
-    attribute {@code false}. This is necessary because the {@link
-    android.Manifest.permission#CAMERA} permission will automatically turn on the requirement for
-    all camera features. So if your application uses this permission but is still compatible with
-    devices without a camera, then you must set the {@code required} attribute {@code false} for
-    {@code android.hardware.camera} or else it will not install on devices without a camera. Note
-    that, while the permission will enable the requirement for <em>all</em> camera features, you
-    only need to off the requirement for the basic camera feature.</p>
-
-  </dd>
-
 </dl>
 </dd>
 
@@ -239,8 +175,680 @@
 <dt>see also:</dt>
 <dd>
   <ul>
+    <li>{@link android.content.pm.PackageManager}</li>
+    <li>{@link android.content.pm.FeatureInfo}</li>
     <li>{@link android.content.pm.ConfigurationInfo}</li>
+    <li><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><code>&lt;uses-permission&gt;</code></a></li>
+    <li><a href="{@docRoot}guide/appendix/market-filters.html">Android Market Filters</a></li>
   </ul>
 </dd>
 
 </dl>
+
+
+<h2 id="market-feature-filtering">Android Market and Feature-Based Filtering</h2>
+
+<p>Android Market filters the applications that are visible to users, so that
+users can see and download only those applications that are compatible with
+their devices. One of the ways Market filters applications is by feature
+compatibility.</p>
+
+<p>To determine an application's feature compatibility with a given user's
+device, the Android Market service compares:</p>
+
+<ul>
+<li>Features required by the application &mdash; an application declares features in
+<code>&lt;uses-feature&gt;</code> elements in its manifest <br/>with...</li>
+<li>Features available on the device, in hardware or software &mdash;
+a device reports the features it supports as read-only system properties.</li>
+</ul>
+
+<p>To ensure an accurate comparison of features, the Android Package Manager
+provides a shared set of feature constants that both applications and devices
+use to declare feature requirements and support. The available feature constants
+are listed in the <a href="#features-reference">Features Reference</a> tables at
+the bottom of this document, and in the class documentation for {@link
+android.content.pm.PackageManager}.</p>
+
+<p>When the user launches the Market application, the application queries the
+Package Manager for the list of features available on the device by calling
+{@link android.content.pm.PackageManager#getSystemAvailableFeatures()}. The
+Market application then passes the features list up to the Android Market
+service when establishing the session for the user.</p>
+
+<p>Each time you upload an application to the Android Market Publisher Site,
+Android Market scans the application's manifest file. It looks for
+<code>&lt;uses-feature&gt;</code> elements and evaluates them in combination
+with other elements, in some cases, such as <code>&lt;uses-sdk&gt;</code> and
+<code>&lt;uses-permission&gt;</code> elements. After establishing the
+application's set of required features, it stores that list internally as
+metadata associated with the application <code>.apk</code> and the application
+version. </p>
+
+<p>When a user searches or browses for applications using the Android Market
+application, the service compares the features needed by each application with
+the features available on the user's device. If all of an application's required
+features are present on the device, Android Market allows the user to see the
+application and potentially download it. If any required feature is not
+supported by the device, Android Market filters the application so that it is
+not visible to the user and not available for download. </p>
+
+<p>Because the features you declare in <code>&lt;uses-feature&gt;</code>
+elements directly affect how Android Market filters your application, it's
+important to understand how Android Market evaluates the application's manifest
+and establishes the set of required features. The sections below provide more
+information. </p>
+
+<h3 id="declared">Filtering based on explicitly declared features</h3>
+
+<p>An explicitly declared feature is one that your application declares in a
+<code>&lt;uses-feature&gt;</code> element. The feature declaration can include
+an <code>android:required=["true" | "false"]</code> attribute (if you are
+compiling against API level 5 or higher), which lets you specify whether the
+application absolutely requires the feature and cannot function properly without
+it (<code>"true"</code>), or whether the application prefers to use the feature
+if available, but is designed to run without it (<code>"false"</code>).</p>
+
+<p>Android Market handles explictly declared features in this way: </p>
+
+<ul>
+<li>If a feature is explicitly declared as being required, Android Market adds
+the feature to the list of required features for the application. It then
+filters the application from users on devices that do not provide that feature.
+For example:
+<pre>&lt;uses-feature android:name="android.hardware.camera" android:required="true" /&gt;</pre></li>
+<li>If a feature is explicitly declared as <em>not</em> being required, Android
+Market <em>does not</em> add the feature to the list of required features. For
+that reason, an explicity declared non-required feature is never considered when
+filtering the application. Even if the device does not provide the declared
+feature, Android Market will still consider the application compatible with the
+device and will show it to the user, unless other filtering rules apply. For
+example:
+<pre>&lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;</pre></li>
+<li>If a feature is explicitly declared, but without an
+<code>android:required</code> attribute, Android Market assumes that the feature
+is required and sets up filtering on it. </li>
+</ul>
+
+<p>In general, if your application is designed to run on Android 1.6 and earlier
+versions, the <code>android:required</code> attribute is not available in the
+API and Android Market assumes that any and all
+<code>&lt;uses-feature&gt;</code> declarations are required. </p>
+
+<p class="note"><strong>Note:</strong> By declaring a feature explicitly and
+including an <code>android:required="false"</code> attribute, you can
+effectively disable all filtering on Android Market for the specified feature.
+</p>
+
+
+<h3 id="implicit">Filtering based on implicit features</h3>
+
+<p>An <em>implicit</em> feature is one that an application requires in order to
+function properly, but which is <em>not</em> declared in a
+<code>&lt;uses-feature&gt;</code> element in the manifest file. Strictly
+speaking, every application should <em>always</em> declare all features that it
+uses or requires, so the absence of a declaration for a feature used by an
+application should be considered an error. However, as a safeguard for users and
+developers, Android Market looks for implicit features in each application and
+sets up filters for those features, just as it would do for an explicitly
+declared feature. </p>
+
+<p>An application might require a feature but not declare it because: </p>
+
+<ul>
+<li>The application was compiled against an older version of the Android library
+(Android 1.5 or earlier) and the <code>&lt;uses-feature&gt;</code> element was
+not available.</li>
+<li>The developer incorrectly assumed that the feature would be present on all
+devices and a declaration was unnecessary.</li>
+<li>The developer omitted the feature declaration accidentally.</li>
+<li>The developer declared the feature explicitly, but the declaration was not
+valid. For example, a spelling error in the <code>&lt;uses-feature&gt;</code>
+element name or an unrecognized string value for the
+<code>android:name</code> attribute would invalidate the feature declaration.
+</li>
+</ul>
+
+<p>To account for the cases above, Android Market attempts to discover an
+application's implied feature requirements by examining <em>other elements</em>
+declared in the manifest file, specifically,
+<code>&lt;uses-permission&gt;</code> elements.</p>
+
+<p>If an application requests hardware-related permissions, Android Market
+<em>assumes that the application uses the underlying hardware features and
+therefore requires those features</em>, even though there might be no
+corresponding to <code>&lt;uses-feature&gt;</code> declarations. For such
+permissions, Android Market adds the underlying hardware features to the
+metadata that it stores for the application and sets up filters for them.</p>
+
+<p>For example, if an application requests the <code>CAMERA</code> permission
+but does not declare a <code>&lt;uses-feature&gt;</code> element for
+<code>android.hardware.camera</code>, Android Market considers that the
+application requires a camera and should not be shown to users whose devices do
+not offer a camera.</p>
+
+<p>If you don't want Android Market to filter based on a specific implied
+feature, you can disable that behavior. To do so, declare the feature explicitly
+in a <code>&lt;uses-feature&gt;</code> element and include an 
+<code>android:required="false"</code> attribute. For example, to disable
+filtering derived from the <code>CAMERA</code> permission, you would declare
+the feature as shown below.</p>
+
+<pre>&lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;</pre>
+
+<p class="caution">It's important to understand that the permissions that you
+request in <code>&lt;uses-permission&gt;</code> elements can directly affect how
+Android Market filters your application. The reference section <a
+href="permissions-features">Permissions that Imply Feature Requirements</a>,
+below, lists the full set of permissions that imply feature requirements and
+therefore trigger filtering.</p>
+
+<h3 id="bt-permission-handling">Special handling for Bluetooth feature</h3>
+
+<p>Android Market applies slightly different rules than described above, when
+determining filtering for Bluetooth.</p>
+
+<p>If an application declares a Bluetooth permission in a
+<code>&lt;uses-permission&gt;</code> element, but does not explicitly declare
+the Bluetooth feature in a <code>&lt;uses-feature&gt;</code> element, Android
+Market checks the version(s) of the Android platform on which the application is
+designed to run, as specified in the <code>&lt;uses-sdk&gt;</code> element. </p>
+
+<p>As shown in the table below, Android Market enables filtering for the
+Bluetooth feature only if the application declares its lowest or targeted
+platform as Android 2.0 (API level 5) or higher. However, note that Android
+market applies the normal rules for filtering when the application explicitly
+declares the Bluetooth feature in a <code>&lt;uses-feature&gt;</code> element.
+</p>
+
+<p class="caption"><strong>Table 1.</strong> How Android Market determines the
+Bluetooth feature requirement for an application that requests a Bluetooth
+permission but does not declare the Bluetooth feature in a
+<code>&lt;uses-feature&gt;</code> element.</p>
+
+<table style="margin-top:1em;">
+<tr>
+<th><nobr>If <code>minSdkVersion</code> is ...</nobr></th>
+<th><nobr>or <code>targetSdkVersion</code> is</nobr></th>
+<th>Result</th>
+</tr>
+<tr>
+<td><nobr>&lt;=4 (or uses-sdk is not declared)</nobr></td>
+<td>&lt;=4</td>
+<td>Android Market <em>will not</em> filter the application from any devices
+based on their reported support for the <code>android.hardware.bluetooth</code>
+feature.</td>
+</tr>
+<tr>
+<td>&lt;=4</td>
+<td>&gt;=5</td>
+<td rowspan="2">Android Market filters the application from any devices that
+do not support the <code>android.hardware.bluetooth</code> feature (including
+older releases).</td>
+</tr>
+<tr>
+<td>&gt;=5</td>
+<td>&gt;=5</td>
+</tr>
+</table>
+
+<p>The examples below illustrate the different filtering effects, based on how
+Android Market handles the Bluetooth feature. </p>
+
+<dl>
+<dt>In first example, an application that is designed to run on older API levels
+declares a Bluetooth permission, but does not declare the Bluetooth feature in a
+<code>&lt;uses-feature&gt;</code> element.</dt>
+<dd><em>Result:</em> Android Market does not filter the application from any device.</dd>
+</dl>
+
+<pre>&lt;manifest ...>
+...
+    &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    &lt;uses-sdk android:minSdkVersion="3" />
+...
+&lt;/manifest></pre>
+
+<dl>
+<dt>In the second example, below, the same application also declares a target
+API level of "5". </dt>
+<dd><em>Result:</em> Android Market now assumes that the feature is required and
+will filter the application from all devices that do not report Bluetooth support,
+including devices running older versions of the platform. </dd>
+</dl>
+
+<pre>&lt;manifest ...>
+...
+    &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    &lt;uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
+...
+&lt;/manifest></pre>
+
+<dl>
+<dt>Here the same application now specifically declares the Bluetooth feature.</dt>
+<dd><em>Result:</em> Identical to the previous example (filtering is applied).</dd>
+</dl>
+
+<pre>&lt;manifest ...>
+...
+    &lt;uses-feature android:name="android.hardware.bluetooth" />
+    &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    &lt;uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
+...
+&lt;/manifest></pre>
+
+<dl>
+<dt>Finally, in the case below, the same application adds an
+<code>android:required="false"</code> attribute.</dt>
+<dd><em>Result:</em> Android Market disables filtering based on Bluetooth
+feature support, for all devices.</dd>
+</dl>
+
+<pre>&lt;manifest ...>
+...
+    &lt;uses-feature android:name="android.hardware.bluetooth" android:required="false" />
+    &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    &lt;uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
+...
+&lt;/manifest></pre>
+
+
+
+<h3>Testing the features required by your application</h3>
+
+<p>You can use the <code>aapt</code> tool, included in the Android SDK, to
+determine how Android Market will filter your application, based on its declared
+features and permissions. To do so, run  <code>aapt</code> with the <code>dump
+badging</code> command. This causes <code>aapt</code> to parse your
+application's manifest and apply the same rules as used by Android Market to
+determine the features that your application requires. </p>
+
+<p>To use the tool, follow these steps: </p>
+
+<ol>
+<li>First, build and export your application as an unsigned <code>.apk</code>.
+If you are developing in Eclipse with ADT, right-click the project and select
+<strong>Android Tools</strong> &gt; <strong>Export Unsigned Application
+Package</strong>. Select a destination filename and path and click
+<strong>OK</strong>. </li>
+<li>Next, locate the <code>aapt</code> tool, if it is not already in your PATH.
+If you are using SDK Tools r7 or earlier, you can find <code>aapt</code> in the
+<code>&lt;<em>SDK</em>&gt;/platforms/android-&lt;<em>platform</em>&gt;/tools/</code> directory.
+<p class="note"><strong>Note:</strong> You must use the version of
+<code>aapt</code> that is provided for the latest platform release available. If
+you do not have the latest platform release, download it using the <a
+href="{@docRoot}sdk/adding-components.html">Android SDK and AVD Manager</a>.
+</p></li>
+<li>Run <code>aapt</code> using this syntax: </li>
+</ol>
+
+<pre>$ aapt dump badging &lt;<em>path_to_exported_.apk</em>&gt;</pre>
+
+<p>Here's an example of the command output for the second Bluetooth example, above: </p>
+
+<pre>$ ./aapt dump badging BTExample.apk
+package: name='com.example.android.btexample' versionCode='' versionName=''
+<strong>uses-permission:'android.permission.BLUETOOTH_ADMIN'</strong>
+<strong>uses-feature:'android.hardware.bluetooth'</strong>
+sdkVersion:'3'
+targetSdkVersion:'5'
+application: label='BT Example' icon='res/drawable/app_bt_ex.png'
+launchable activity name='com.example.android.btexample.MyActivity'label='' icon=''
+uses-feature:'android.hardware.touchscreen'
+main
+supports-screens: 'small' 'normal' 'large'
+locales: '--_--'
+densities: '160'
+</pre>
+
+
+<h2 id=features-reference>Features Reference</h2>
+
+<p>The tables below provide reference information about hardware and software
+features and the permissions that can imply them on Android Market. </p>
+
+<h3 id="hw-features">Hardware features</h3>
+
+<p>The table below describes the hardware feature descriptors supported by the
+most current platform release. To signal that your application uses or requires
+a hardware feature, declare each value in a <code>android:name</code> attribute
+in a separate <code>&lt;uses-feature&gt;</code> element. </p>
+
+  <table>
+    <tr>
+       <th>Feature Type</th>
+       <th>Feature Descriptor</th>
+       <th>Description</th>
+       <th>Comments</th>
+    </tr>
+    <tr>
+       <td>Bluetooth</td>
+       <td><code>android.hardware.bluetooth</td>
+       <td>The application uses Bluetooth radio features in the device.</td>
+<td>
+</td>
+    </tr>
+    <tr>
+       <td rowspan="3">Camera</td>
+       <td><code>android.hardware.camera</code></td>
+       <td>The application uses the device's camera. If the device supports
+           multiple cameras, the application uses the camera that facing
+           away from the screen.</td>
+       <td></td>
+    </tr>
+<tr>
+  <td><code>android.hardware.camera.autofocus</code></td>
+  <td>Subfeature. The application uses the device camera's autofocus capability.</td>
+  <td rowspan="2">If declared with the <code>"android:required="true"</code>
+attribute, these subfeatures implicitly declare the
+<code>android.hardware.camera</code> parent feature. </td>
+</tr>
+<tr>
+  <td><code>android.hardware.camera.flash</code></td>
+  <td>Subfeature. The application uses the device camera's flash.</td>
+</tr>
+
+<tr>
+  <td rowspan="3">Location</td>
+  <td><code>android.hardware.location</code></td>
+  <td>The application uses one or more features on the device for determining
+location, such as GPS location, network location, or cell location.</td>
+  <td></td>
+</tr>
+<tr>
+  <td><code>android.hardware.location.network</code></td>
+  <td>Subfeature. The application uses coarse location coordinates obtained from
+a network-based geolocation system supported on the device.</td>
+  <td rowspan="2">If declared with the <code>"android:required="true"</code>
+attribute, these subfeatures implicitly declare the
+<code>android.hardware.location</code> parent feature. </td>
+</tr>
+<tr>
+  <td><code>android.hardware.location.gps</code></td>
+  <td>Subfeature. The application uses precise location coordinates obtained
+from a Global Positioning System receiver on the device. </td>
+</tr>
+
+<tr>
+  <td rowspan="4">Sensors</td>
+  <td><code>android.hardware.sensor.accelerometer</code></td>
+  <td>The application uses motion readings from an accelerometer on the
+device.</td>
+  <td></td>
+</tr>
+<tr>
+  <td><code>android.hardware.sensor.compass</code></td>
+  <td>The application uses directional readings from a magnetometer (compass) on
+the device.</td>
+  <td></td>
+</tr>
+<tr>
+  <td><code>android.hardware.sensor.light</code></td>
+  <td>The application uses the device's light sensor.</td>
+  <td></td>
+</tr>
+<tr>
+  <td><code>android.hardware.sensor.proximity</code></td>
+  <td>The application uses the device's proximity sensor.</td>
+  <td></td>
+</tr>
+<tr>
+  <td>Microphone</td>
+  <td><code>android.hardware.microphone</code></td>
+  <td>The application uses a microphone on the device.
+  </td>
+  <td></td>
+</tr>
+
+<tr>
+  <td rowspan="3">Telephony</td>
+  <td><code>android.hardware.telephony</code></td>
+  <td>The application uses telephony features on the device, such as telephony
+radio with data communication services.</td>
+  <td></td>
+</tr>
+<tr>
+  <td><code>android.hardware.telephony.cdma</code></td>
+  <td>Subfeature. The application uses CDMA telephony radio features on the
+device. </td>
+  <td rowspan="2">If declared with the <code>"android:required="true"</code>
+attribute, these subfeatures implicitly declare the
+<code>android.hardware.telephony</code> parent feature. </td>
+</tr>
+<tr>
+  <td><code>android.hardware.telephony.gsm</code></td>
+  <td>Subfeature. The application uses GSM telephony radio features on the
+device.</td>
+</tr>
+
+<tr>
+  <td rowspan="3">Touchscreen</td>
+  <td><code>android.hardware.touchscreen</code></td>
+  <td>The application uses touchscreen capabilities on the device.</td>
+  <td></td>
+</tr>
+<tr>
+  <td><code>android.hardware.touchscreen.multitouch</code></td>
+  <td>The application uses basic two-point multitouch capabilities on the device
+screen.</td>
+  <td>If declared with the <code>"android:required="true"</code> attribute, this
+subfeature implicitly declares the <code>android.hardware.touchscreen</code>
+parent feature. </td>
+</tr>
+<tr>
+  <td><code>android.hardware.touchscreen.multitouch.distinct</code></td>
+  <td>Subfeature. The application uses advanced multipoint multitouch
+capabilities on the device screen, such as for tracking two or more points fully
+independently.</td>
+  <td>If declared with the <code>"android:required="true"</code> attribute, this
+subfeature implicitly declares the
+<code>android.hardware.touchscreen.multitouch</code> parent feature. </td>
+</tr>
+
+<tr>
+  <td>Wifi</td>
+  <td><code>android.hardware.wifi</code></td>
+  <td>The application uses 802.11 networking (wifi) features on the device.</td>
+  <td></td>
+</tr>
+
+  </table>
+
+<h3 id="sw-features">Software features</h3>
+
+<p>The table below describes the software feature descriptors supported by the
+most current platform release. To signal that your application uses or requires
+a software feature, declare each value in a <code>android:name</code> attribute
+in a separate <code>&lt;uses-feature&gt;</code> element. </p>
+
+
+  <table>
+    <tr> 
+       <th>Feature</th>
+       <th>Attribute Value</th> 
+       <th>Description</th>
+    </tr>
+    <tr>
+      <td>Live Wallpaper</td>
+      <td><code>android.software.live_wallpaper</code></td>
+      <td>The application uses or provides Live Wallpapers.
+      </td>
+    </tr>
+  </table>
+
+
+<h3 id="permissions">Permissions that Imply Feature Requirements</h3>
+
+<p>Some feature constants listed in the tables above were made available to
+applications <em>after</em> the corresponding API; for example, the
+<code>android.hardware.bluetooth</code> feature was added in Android 2.2 (API
+level 8), but the bluetooth API that it refers to was added in Android 2.0 (API
+level 5). Because of this, some apps were able to use the API before they had
+the ability to declare that they require the API via the
+<code>&lt;uses-feature&gt;</code> system. </p>
+
+<p>To prevent those apps from being made available unintentionally,  Android
+Market assumes that certain hardware-related permissions indicate that the
+underlying hardware features are required by default. For instance, applications
+that use Bluetooth must request the <code>BLUETOOTH</code> permission in a
+<code>&lt;uses-permission&gt;</code> element &mdash; for legacy apps, Android
+Market assumes that the permission declaration means that the underlying
+<code>android.hardware.bluetooth</code> feature is required by the application
+and sets up filtering based on that feature. </p>
+
+<p>The table below lists permissions that imply feature requirements
+equivalent to those declared in <code>&lt;uses-feature&gt;</code> elements. Note
+that <code>&lt;uses-feature&gt;</code> declarations, including any declared
+<code>android:required</code> attribute, always take precedence over features
+implied by the permissions below. </p>
+
+<p>For any of the permissions below, you can disable filtering based on the
+implied feature by explicitly declaring the implied feature explicitly, in a
+<code>&lt;uses-feature&gt;</code> element, with an
+<code>android:required="false"</code> attribute. For example, to disable any
+filtering based on the <code>CAMERA</code> permission, you would add this
+<code>&lt;uses-feature&gt;</code> declaration to the manifest file:</p>
+
+<pre>&lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;</pre>
+
+<table id="permissions-features" >
+  <tr> 
+    <th>Category</th>
+    <th>This Permission...</th>
+    <th>Implies This Feature Requirement</th>
+    <!-- <th>Comments</th> -->
+  </tr>
+
+
+<tr>
+  <td rowspan="2">Bluetooth</td>
+  <td><code>BLUETOOTH</code></td>
+  <td><code>android.hardware.bluetooth</code>
+<p>(See <a href="#bt-permission-handling">Special handling for Bluetooth feature</a> for details.)</p></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>BLUETOOTH_ADMIN</code></td>
+  <td><code>android.hardware.bluetooth</code></td>
+<!--  <td></td> -->
+</tr>
+
+<tr>
+  <td>Camera</td>
+  <td><code>CAMERA</code></td>
+  <td><code>android.hardware.camera</code> <em>and</em>
+<br><code>android.hardware.camera.autofocus</code></td>
+<!--  <td></td> -->
+</tr>
+
+<tr>
+  <td rowspan="5">Location</td>
+  <td><code>ACCESS_MOCK_LOCATION</code></td>
+  <td><code>android.hardware.location</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>ACCESS_LOCATION_EXTRA_COMMANDS</code></td>
+  <td><code>android.hardware.location</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>INSTALL_LOCATION_PROVIDER</code></td>
+  <td><code>android.hardware.location</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>ACCESS_COARSE_LOCATION</code></td>
+  <td><code>android.hardware.location.network</code> <em>and</em>
+<br><code>android.hardware.location</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>ACCESS_FINE_LOCATION</code></td>
+  <td><code>android.hardware.location.gps</code> <em>and</em>
+<br><code>android.hardware.location</code></td>
+<!--  <td></td> -->
+</tr>
+
+<tr>
+  <td>Microphone</td>
+  <td><code>RECORD_AUDIO</code></td>
+  <td><code>android.hardware.microphone</code></td>
+<!--  <td></td> -->
+</tr>
+
+<tr>
+  <td rowspan="11">Telephony</td>
+  <td><code>CALL_PHONE</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>CALL_PRIVILEGED</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+
+<tr>
+  <td><code>MODIFY_PHONE_STATE</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>PROCESS_OUTGOING_CALLS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>READ_SMS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>RECEIVE_SMS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>RECEIVE_MMS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>RECEIVE_WAP_PUSH</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>SEND_SMS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>WRITE_APN_SETTINGS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>WRITE_SMS</code></td>
+  <td><code>android.hardware.telephony</code></td>
+<!--  <td></td> -->
+</tr>
+
+<tr>
+  <td rowspan="3">Wifi</td>
+  <td><code>ACCESS_WIFI_STATE</code></td>
+  <td><code>android.hardware.wifi</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>CHANGE_WIFI_STATE</code></td>
+  <td><code>android.hardware.wifi</code></td>
+<!--  <td></td> -->
+</tr>
+<tr>
+  <td><code>CHANGE_WIFI_MULTICAST_STATE</code></td>
+  <td><code>android.hardware.wifi</code></td>
+<!--  <td></td> -->
+</tr>
+</table>
\ No newline at end of file
diff --git a/docs/html/guide/topics/manifest/uses-permission-element.jd b/docs/html/guide/topics/manifest/uses-permission-element.jd
index aec765c..085b9f0 100644
--- a/docs/html/guide/topics/manifest/uses-permission-element.jd
+++ b/docs/html/guide/topics/manifest/uses-permission-element.jd
@@ -2,6 +2,38 @@
 @jd:body
 
 <dl class="xml">
+
+ <div class="sidebox-wrapper"> 
+  <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png"> 
+  <div id="qv-sub-rule"> 
+    <img src="{@docRoot}assets/images/icon_market.jpg" style="float:left;margin:0;padding:0;"> 
+    <p style="color:#669999;"><code style="color:#669999;">&lt;uses-permission&gt;</code> and filtering on Android Market. </p>
+
+<p style="margin-top:1em;">In some cases, the permissions that you request
+through <code>&lt;uses-permission&gt;</code> can affect how
+your application is filtered by Android Market.</p>
+
+<p style="margin-top:1em;">If you request a hardware-related permission &mdash;
+<code>CAMERA</code>, for example &mdash; Android Market assumes that your
+application requires the underlying hardware feature and filters the application
+from devices that do not offer it.</p>
+
+<p style="margin-top:1em;">To control filtering, always explicitly declare
+hardware features in <code>&lt;uses-feature&gt;</code> elements, rather than
+relying on Android Market to "discover" the requirements in
+<code>&lt;uses-permission&gt;</code> elements. Then, if you want to disable
+filtering for a particular feature, you can add a
+<code>android:required="false"</code> attribute to the
+<code>&lt;uses-feature&gt;</code> declaration.</p>
+
+<p style="margin-top:1em;" class="caution">For a list of permissions that imply
+hardware features, see the documentation for the <a
+href="{@docRoot}guide/topics/manifest/uses-feature-element.html#permissions-features">
+<code>&lt;uses-feature&gt;</code></a> element.</p>
+</div>
+</div>
+
+
 <dt>syntax:</dt>
 <dd><pre class="stx">&lt;uses-permission android:<a href="#nm">name</a>="<i>string</i>" /&gt;</pre></dd>
 
@@ -10,7 +42,7 @@
 
 <dt>description:</dt>
 <dd>Requests a permission that the application must be granted in 
-order for it to operate correctly.  Permissions are granted when the 
+order for it to operate correctly.  Permissions are granted by the user when the 
 application is installed, not while it's running.
 
 <p>
@@ -38,6 +70,11 @@
 <dd>API Level 1</dd>
 
 <dt>see also:</dt>
-<dd><code><a href="{@docRoot}guide/topics/manifest/permission-element.html">&lt;permission&gt;</a></code></dd>
+<dd>
+<ul>
+  <li><code><a href="{@docRoot}guide/topics/manifest/permission-element.html">&lt;permission&gt;</a></code></li>
+  <li><code><a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></code></li>
+</ul>
+</dd>
 
 </dl>
diff --git a/docs/html/guide/topics/testing/index.jd b/docs/html/guide/topics/testing/index.jd
index b75656f..762a897 100644
--- a/docs/html/guide/topics/testing/index.jd
+++ b/docs/html/guide/topics/testing/index.jd
@@ -59,6 +59,20 @@
         which guides you through a more complex testing scenario.
     </li>
 </ul>
+<h4>Tools</h4>
+<ul>
+    <li>
+        The
+        <a href="{@docRoot}guide/developing/tools/monkey.html">UI/Application Exerciser Monkey</a>,
+        usually called Monkey, is a command-line tool that sends pseudo-random
+        streams of keystrokes, touches, and gestures to a device.
+    </li>
+    <li>
+     The <a href="{@docRoot}guide/developing/tools/monkeyrunner_concepts.html">monkeyrunner</a> tool
+        is an API and execution environment. You use monkeyrunner with Python programs
+        to test applications and devices.
+    </li>
+</ul>
 <h4>Samples</h4>
 <ul>
     <li>
diff --git a/docs/html/guide/topics/testing/testing_android.jd b/docs/html/guide/topics/testing/testing_android.jd
index 2a4c949..d4b0dcc 100755
--- a/docs/html/guide/topics/testing/testing_android.jd
+++ b/docs/html/guide/topics/testing/testing_android.jd
@@ -38,7 +38,7 @@
         <a href="#TestResults">Seeing Test Results</a>
     </li>
     <li>
-        <a href="#Monkeys">Monkey and MonkeyRunner</a>
+        <a href="#Monkeys">monkey and monkeyrunner</a>
     </li>
     <li>
        <a href="#PackageNames">Working With Package Names</a>
@@ -77,6 +77,13 @@
           <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
           Testing in Other IDEs</a>
         </li>
+        <li>
+          <a href="{@docRoot}guide/developing/tools/monkeyrunner_concepts.html">
+          monkeyrunner</a>
+        </li>
+        <li>
+     <a href="{@docRoot}guide/developing/tools/monkey.html">UI/Application Exerciser Monkey</a>
+        </li>
       </ol>
   </div>
 </div>
@@ -112,10 +119,10 @@
     </li>
     <li>
         The SDK also provides
-        <a href="{@docRoot}guide/topics/testing/monkeyrunner.html">MonkeyRunner</a>, an API for
-        testing devices with Jython scripts, and <a
-        href="{@docRoot}guide/developing/tools/monkey.html">Monkey</a>, a command-line tool for
-        stress-testing UIs by sending pseudo-random events to a device.
+  <a href="{@docRoot}guide/developing/tools/monkeyrunner_concepts.html">monkeyrunner</a>, an API
+        testing devices with Python programs, and <a
+        href="{@docRoot}guide/developing/tools/monkey.html">UI/Application Exerciser Monkey</a>,
+        a command-line tool for stress-testing UIs by sending pseudo-random events to a device.
     </li>
 </ul>
 <p>
@@ -540,25 +547,28 @@
     <a href="{@docRoot}guide/developing/testing/testing_otheride.html#RunTestsCommand">
     Testing in Other IDEs</a>.
 </p>
-<h2 id="Monkeys">Monkey and MonkeyRunner</h2>
+<h2 id="Monkeys">monkey and monkeyrunner</h2>
 <p>
     The SDK provides two tools for functional-level application testing:
 </p>
     <ul>
         <li>
-            <a href="{@docRoot}guide/developing/tools/monkey.html">Monkey</a> is a command-line
-            tool that sends pseudo-random streams of keystrokes, touches, and gestures to a
-            device. You run it with the <a href="{@docRoot}guide/developing/tools/adb.html">
-            Android Debug Bridge</a> (adb) tool. You use it to stress-test your application and
-            report back errors that are encountered. You can repeat a stream of events by
-            running the tool each time with the same random number seed.
+The <a href="{@docRoot}guide/developing/tools/monkey.html">UI/Application Exerciser Monkey</a>,
+            usually called "monkey", is a command-line tool that sends pseudo-random streams of
+            keystrokes, touches, and gestures to a device. You run it with the
+            <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a> (adb) tool.
+            You use it to stress-test your application and report back errors that are encountered.
+            You can repeat a stream of events by running the tool each time with the same random
+            number seed.
         </li>
         <li>
-            <a href="{@docRoot}guide/topics/testing/monkeyrunner.html">MonkeyRunner</a> is a
-            Jython API that you use in test programs written in Python. The API includes functions
-            for connecting to a device, installing and uninstalling packages, taking screenshots,
-            comparing two images, and running a test package against an application. Using the API
-            with Python, you can write a wide range of large, powerful, and complex tests.
+    The <a href="{@docRoot}guide/developing/tools/monkeyrunner_concepts.html">monkeyrunner</a> tool
+            is an API and execution environment for test programs written in Python. The API
+            includes functions for connecting to a device, installing and uninstalling packages,
+            taking screenshots, comparing two images, and running a test package against an
+            application. Using the API, you can write a wide range of large, powerful, and complex
+            tests. You run programs that use the API with the <code>monkeyrunner</code> command-line
+            tool.
         </li>
     </ul>
 <h2 id="PackageNames">Working With Package names</h2>
diff --git a/docs/html/resources/dashboard/platform-versions.jd b/docs/html/resources/dashboard/platform-versions.jd
index 3b4ccb0e..cef057e 100644
--- a/docs/html/resources/dashboard/platform-versions.jd
+++ b/docs/html/resources/dashboard/platform-versions.jd
@@ -52,7 +52,7 @@
 <div class="dashboard-panel">
 
 <img alt="" height="250" width="460"
-src="http://chart.apis.google.com/chart?&cht=p&chs=460x250&chd=t:9.7,16.4,0.1,40.4,33.4&chl=
+src="http://chart.apis.google.com/chart?&cht=p&chs=460x250&chd=t:7.9,15.0,0.1,40.8,36.2&chl=
 Android%201.5|Android%201.6|Other*|Android%202.1|Android%202.2&chco=c4df9b,
 6fad0c" />
 
@@ -62,13 +62,13 @@
   <th>API Level</th>
   <th>Distribution</th>
 </tr>
-<tr><td>Android 1.5</td><td>3</td><td>9.7%</td></tr>
-<tr><td>Android 1.6</td><td>4</td><td>16.4%</td></tr>
-<tr><td>Android 2.1</td><td>7</td><td>40.4%</td></tr>
-<tr><td>Android 2.2</td><td>8</td><td>33.4%</td></tr>
+<tr><td>Android 1.5</td><td>3</td><td>7.9%</td></tr>
+<tr><td>Android 1.6</td><td>4</td><td>15.0%</td></tr>
+<tr><td>Android 2.1</td><td>7</td><td>40.8%</td></tr>
+<tr><td>Android 2.2</td><td>8</td><td>36.2%</td></tr>
 </table>
 
-<p><em>Data collected during two weeks ending on October 1, 2010</em></p>
+<p><em>Data collected during two weeks ending on November 1, 2010</em></p>
 <p style="font-size:.9em">* <em>Other: 0.1% of devices running obsolete versions</em></p>
 
 </div><!-- end dashboard-panel -->
@@ -96,19 +96,18 @@
 <div class="dashboard-panel">
 
 <img alt="" height="250" width="660" style="padding:5px;background:#fff"
-src="http://chart.apis.google.com/chart?cht=lc&chs=660x250&chxt=x,y,r&chxr=0,0,12|1,0,100|2,0,100&
-chxl=0:|2010/04/01|04/15|05/01|05/15|06/01|06/15|07/01|07/15|08/01|08/15|09/01|09/15|2010/10/01|1:|0
-%25|25%25|50%25|75%25|100%25|2:|0%25|25%25|50%25|75%25|100%25&chxp=0,0,1,2,3,4,5,6,7,8,9,10,11,12&
-chxtc=0,5&chd=t:99.6,99.6,99.6,99.7,100.6,101.1,99.9,100.0,100.0,99.8,99.9,100.0,100.0|61.5,61.7,62.
-3,63.5,73.0,76.4,78.6,81.1,84.5,86.6,88.0,89.3,90.3|29.4,30.2,32.7,35.3,46.2,51.3,55.1,59.0,64.1,68.
-2,70.4,72.2,73.9|4.0,28.3,32.0,34.9,45.9,51.0,54.9,58.8,64.0,68.1,70.3,72.1,73.8|0.0,0.0,0.0,0.0,0.8
-,1.2,1.8,3.3,4.3,11.3,27.8,32.1,33.4&chm=tAndroid+1.5,7caa36,0,0,15,,t::-5|b,c3df9b,0,1,0|tAndroid+1
-.6,638d23,1,0,15,,t::-5|b,b0db6e,1,2,0|tAndroid+2.0.1,496c13,2,0,15,,t::-5|b,9ddb3d,2,3,0|tAndroid+2
-.1,2f4708,3,1,15,,t:-30:-40|b,89cf19,3,4,0|tAndroid+2.2,131d02,4,9,15,,t::-5|B,6fad0c,4,5,0&chg=7,25
-&chdl=Android+1.5|Android+1.6|Android+2.0.1|Android+2.1|Android+2.2&chco=add274,9ad145,84c323,6ba213
-,507d08" />
+src="http://chart.apis.google.com/chart?&cht=lc&chs=660x250&chxt=x,y,r&chxr=0,0,12|1,0,100|2,0,100&
+chxl=0%3A%7C2010/05/01%7C05/15%7C06/01%7C06/15%7C07/01%7C07/15%7C08/01%7C08/15%7C09/01%7C09/15%7C10/
+01%7C10/15%7C2010/11/01%7C1%3A%7C0%25%7C25%25%7C50%25%7C75%25%7C100%25%7C2%3A%7C0%25%7C25%25%7C50%25
+%7C75%25%7C100%25&chxp=0,0,1,2,3,4,5,6,7,8,9,10,11,12&chxtc=0,5&chd=t:98.9,99.3,100.3,100.8,99.7,99.
+8,99.8,99.7,99.8,99.9,99.9,99.9,99.9|61.6,63.1,72.7,76.1,78.4,80.9,84.3,86.5,87.9,89.2,90.2,91.1,92.
+0|32.0,34.9,45.9,51.0,54.9,58.8,64.0,68.1,70.3,72.1,73.8,75.3,77.0|0.0,0.0,0.8,1.2,1.8,3.3,4.3,11.3,
+27.8,32.1,33.4,34.5,36.2&chm=tAndroid%201.5,7caa36,0,0,15,,t::-5|b,c3df9b,0,1,0|tAndroid%201.6,
+5b831d,1,0,15,,t::-5|b,aadb5e,1,2,0|tAndroid%202.1,38540b,2,0,15,,t::-5|b,91da1e,2,3,0|tAndroid%202.
+2,131d02,3,7,15,,t::-5|B,6fad0c,3,4,0&chg=7,25&chdl=Android%201.5|Android%201.6|Android%202.1|
+Android%202.2&chco=add274,94d134,73ad18,507d08" />
 
-<p><em>Last historical dataset collected during two weeks ending on October 1, 2010</em></p>
+<p><em>Last historical dataset collected during two weeks ending on November 1, 2010</em></p>
 
 
 </div><!-- end dashboard-panel -->
diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp
index 17cdf544..10c64ee 100644
--- a/drm/common/DrmEngineBase.cpp
+++ b/drm/common/DrmEngineBase.cpp
@@ -120,6 +120,11 @@
     return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length);
 }
 
+status_t DrmEngineBase::openDecryptSession(
+    int uniqueId, DecryptHandle* decryptHandle, const char* uri) {
+    return onOpenDecryptSession(uniqueId, decryptHandle, uri);
+}
+
 status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     return onCloseDecryptSession(uniqueId, decryptHandle);
 }
diff --git a/drm/common/DrmInfoStatus.cpp b/drm/common/DrmInfoStatus.cpp
index f3a1516..8ec7311 100644
--- a/drm/common/DrmInfoStatus.cpp
+++ b/drm/common/DrmInfoStatus.cpp
@@ -19,8 +19,9 @@
 using namespace android;
 
 DrmInfoStatus::DrmInfoStatus(
-    int _statusCode, const DrmBuffer* _drmBuffer, const String8& _mimeType) :
+    int _statusCode, int _infoType, const DrmBuffer* _drmBuffer, const String8& _mimeType) :
     statusCode(_statusCode),
+    infoType(_infoType),
     drmBuffer(_drmBuffer),
     mimeType(_mimeType) {
 
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index c28527c..c3d12f0 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -53,27 +53,18 @@
     remote()->transact(REMOVE_UNIQUEID, data, &reply);
 }
 
-status_t BpDrmManagerService::loadPlugIns(int uniqueId) {
-    LOGV("load plugins");
+void BpDrmManagerService::addClient(int uniqueId) {
     Parcel data, reply;
-
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
-
-    remote()->transact(LOAD_PLUGINS, data, &reply);
-    return reply.readInt32();
+    remote()->transact(ADD_CLIENT, data, &reply);
 }
 
-status_t BpDrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
-    LOGV("load plugins from path");
+void BpDrmManagerService::removeClient(int uniqueId) {
     Parcel data, reply;
-
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
-    data.writeString8(plugInDirPath);
-
-    remote()->transact(LOAD_PLUGINS_FROM_PATH, data, &reply);
-    return reply.readInt32();
+    remote()->transact(REMOVE_CLIENT, data, &reply);
 }
 
 status_t BpDrmManagerService::setDrmServiceListener(
@@ -88,17 +79,6 @@
     return reply.readInt32();
 }
 
-status_t BpDrmManagerService::unloadPlugIns(int uniqueId) {
-    LOGV("unload plugins");
-    Parcel data, reply;
-
-    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
-    data.writeInt32(uniqueId);
-
-    remote()->transact(UNLOAD_PLUGINS, data, &reply);
-    return reply.readInt32();
-}
-
 status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
     LOGV("Install DRM Engine");
     Parcel data, reply;
@@ -191,6 +171,7 @@
     if (0 != reply.dataAvail()) {
         //Filling DRM Info Status
         const int statusCode = reply.readInt32();
+        const int infoType = reply.readInt32();
         const String8 mimeType = reply.readString8();
 
         DrmBuffer* drmBuffer = NULL;
@@ -203,7 +184,7 @@
             }
             drmBuffer = new DrmBuffer(data, bufferSize);
         }
-        drmInfoStatus = new DrmInfoStatus(statusCode, drmBuffer, mimeType);
+        drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType);
     }
     return drmInfoStatus;
 }
@@ -538,8 +519,7 @@
     LOGV("Entering BpDrmManagerService::openDecryptSession");
     Parcel data, reply;
 
-    const String16 interfaceDescriptor = IDrmManagerService::getInterfaceDescriptor();
-    data.writeInterfaceToken(interfaceDescriptor);
+    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
     data.writeFileDescriptor(fd);
     data.writeInt32(offset);
@@ -559,6 +539,32 @@
             handle->decryptInfo = new DecryptInfo();
             handle->decryptInfo->decryptBufferLength = reply.readInt32();
         }
+    }
+    return handle;
+}
+
+DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) {
+    LOGV("Entering BpDrmManagerService::openDecryptSession");
+    Parcel data, reply;
+
+    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
+    data.writeInt32(uniqueId);
+    data.writeString8(String8(uri));
+
+    remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply);
+
+    DecryptHandle* handle = NULL;
+    if (0 != reply.dataAvail()) {
+        handle = new DecryptHandle();
+        handle->decryptId = reply.readInt32();
+        handle->mimeType = reply.readString8();
+        handle->decryptApiType = reply.readInt32();
+        handle->status = reply.readInt32();
+        handle->decryptInfo = NULL;
+        if (0 != reply.dataAvail()) {
+            handle->decryptInfo = new DecryptInfo();
+            handle->decryptInfo->decryptBufferLength = reply.readInt32();
+        }
     } else {
         LOGE("no decryptHandle is generated in service side");
     }
@@ -746,25 +752,19 @@
         return DRM_NO_ERROR;
     }
 
-    case LOAD_PLUGINS:
+    case ADD_CLIENT:
     {
-        LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS");
+        LOGV("BnDrmManagerService::onTransact :ADD_CLIENT");
         CHECK_INTERFACE(IDrmManagerService, data, reply);
-
-        status_t status = loadPlugIns(data.readInt32());
-
-        reply->writeInt32(status);
+        addClient(data.readInt32());
         return DRM_NO_ERROR;
     }
 
-    case LOAD_PLUGINS_FROM_PATH:
+    case REMOVE_CLIENT:
     {
-        LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS_FROM_PATH");
+        LOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT");
         CHECK_INTERFACE(IDrmManagerService, data, reply);
-
-        status_t status = loadPlugIns(data.readInt32(), data.readString8());
-
-        reply->writeInt32(status);
+        removeClient(data.readInt32());
         return DRM_NO_ERROR;
     }
 
@@ -783,18 +783,6 @@
         return DRM_NO_ERROR;
     }
 
-    case UNLOAD_PLUGINS:
-    {
-        LOGV("BnDrmManagerService::onTransact :UNLOAD_PLUGINS");
-        CHECK_INTERFACE(IDrmManagerService, data, reply);
-
-        const int uniqueId = data.readInt32();
-        status_t status = unloadPlugIns(uniqueId);
-
-        reply->writeInt32(status);
-        return DRM_NO_ERROR;
-    }
-
     case INSTALL_DRM_ENGINE:
     {
         LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE");
@@ -881,6 +869,7 @@
         if (NULL != drmInfoStatus) {
             //Filling DRM Info Status contents
             reply->writeInt32(drmInfoStatus->statusCode);
+            reply->writeInt32(drmInfoStatus->infoType);
             reply->writeString8(drmInfoStatus->mimeType);
 
             if (NULL != drmInfoStatus->drmBuffer) {
@@ -1232,6 +1221,30 @@
                 reply->writeInt32(handle->decryptInfo->decryptBufferLength);
                 delete handle->decryptInfo; handle->decryptInfo = NULL;
             }
+        }
+        delete handle; handle = NULL;
+        return DRM_NO_ERROR;
+    }
+
+    case OPEN_DECRYPT_SESSION_FROM_URI:
+    {
+        LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI");
+        CHECK_INTERFACE(IDrmManagerService, data, reply);
+
+        const int uniqueId = data.readInt32();
+        const String8 uri = data.readString8();
+
+        DecryptHandle* handle = openDecryptSession(uniqueId, uri.string());
+
+        if (NULL != handle) {
+            reply->writeInt32(handle->decryptId);
+            reply->writeString8(handle->mimeType);
+            reply->writeInt32(handle->decryptApiType);
+            reply->writeInt32(handle->status);
+            if (NULL != handle->decryptInfo) {
+                reply->writeInt32(handle->decryptInfo->decryptBufferLength);
+                delete handle->decryptInfo; handle->decryptInfo = NULL;
+            }
         } else {
             LOGE("NULL decryptHandle is returned");
         }
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index 52527dc..35e62f3 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -85,22 +85,31 @@
     }
 }
 
-status_t DrmManager::loadPlugIns(int uniqueId) {
+status_t DrmManager::loadPlugIns() {
     String8 pluginDirPath("/system/lib/drm/plugins/native");
-    return loadPlugIns(uniqueId, pluginDirPath);
+    return loadPlugIns(pluginDirPath);
 }
 
-status_t DrmManager::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
+status_t DrmManager::loadPlugIns(const String8& plugInDirPath) {
     if (mSupportInfoToPlugInIdMap.isEmpty()) {
         mPlugInManager.loadPlugIns(plugInDirPath);
-
-        initializePlugIns(uniqueId);
-
-        populate(uniqueId);
-    } else {
-        initializePlugIns(uniqueId);
+        Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
+        for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
+            String8 plugInPath = plugInPathList[i];
+            DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0);
+            if (NULL != info) {
+                mSupportInfoToPlugInIdMap.add(*info, plugInPath);
+            }
+        }
     }
+    return DRM_NO_ERROR;
+}
 
+status_t DrmManager::unloadPlugIns() {
+    mConvertSessionMap.clear();
+    mDecryptSessionMap.clear();
+    mPlugInManager.unloadPlugIns();
+    mSupportInfoToPlugInIdMap.clear();
     return DRM_NO_ERROR;
 }
 
@@ -111,21 +120,23 @@
     return DRM_NO_ERROR;
 }
 
-status_t DrmManager::unloadPlugIns(int uniqueId) {
-    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
+void DrmManager::addClient(int uniqueId) {
+    if (!mSupportInfoToPlugInIdMap.isEmpty()) {
+        Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
+        for (unsigned int index = 0; index < plugInIdList.size(); index++) {
+            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
+            rDrmEngine.initialize(uniqueId);
+            rDrmEngine.setOnInfoListener(uniqueId, this);
+        }
+    }
+}
 
+void DrmManager::removeClient(int uniqueId) {
+    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
     for (unsigned int index = 0; index < plugInIdList.size(); index++) {
         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
         rDrmEngine.terminate(uniqueId);
     }
-
-    if (0 >= mUniqueIdVector.size()) {
-        mConvertSessionMap.clear();
-        mDecryptSessionMap.clear();
-        mSupportInfoToPlugInIdMap.clear();
-        mPlugInManager.unloadPlugIns();
-    }
-    return DRM_NO_ERROR;
 }
 
 DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) {
@@ -144,7 +155,7 @@
     rDrmEngine.initialize(uniqueId);
     rDrmEngine.setOnInfoListener(uniqueId, this);
 
-    DrmSupportInfo* info = rDrmEngine.getSupportInfo(uniqueId);
+    DrmSupportInfo* info = rDrmEngine.getSupportInfo(0);
     mSupportInfoToPlugInIdMap.add(*info, absolutePath);
 
     return DRM_NO_ERROR;
@@ -154,7 +165,7 @@
     const String8 plugInId = getSupportedPlugInId(mimeType);
     bool result = (EMPTY_STRING != plugInId) ? true : false;
 
-    if (NULL != path) {
+    if (0 < path.length()) {
         if (result) {
             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
             result = rDrmEngine.canHandle(uniqueId, path);
@@ -340,7 +351,7 @@
         for (int i = 0; i < size; ++i) {
             String8 plugInPath = plugInPathList[i];
             DrmSupportInfo* drmSupportInfo
-                = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId);
+                = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0);
             if (NULL != drmSupportInfo) {
                 drmSupportInfoList.add(*drmSupportInfo);
                 delete drmSupportInfo; drmSupportInfo = NULL;
@@ -360,12 +371,12 @@
 }
 
 DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) {
+    Mutex::Autolock _l(mDecryptLock);
     status_t result = DRM_ERROR_CANNOT_HANDLE;
     Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
 
     DecryptHandle* handle = new DecryptHandle();
     if (NULL != handle) {
-        Mutex::Autolock _l(mDecryptLock);
         handle->decryptId = mDecryptSessionId + 1;
 
         for (unsigned int index = 0; index < plugInIdList.size(); index++) {
@@ -380,16 +391,42 @@
             }
         }
     }
+    if (DRM_NO_ERROR != result) {
+        delete handle; handle = NULL;
+    }
+    return handle;
+}
 
+DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) {
+    Mutex::Autolock _l(mDecryptLock);
+    status_t result = DRM_ERROR_CANNOT_HANDLE;
+    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
+
+    DecryptHandle* handle = new DecryptHandle();
+    if (NULL != handle) {
+        handle->decryptId = mDecryptSessionId + 1;
+
+        for (unsigned int index = 0; index < plugInIdList.size(); index++) {
+            String8 plugInId = plugInIdList.itemAt(index);
+            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
+            result = rDrmEngine.openDecryptSession(uniqueId, handle, uri);
+
+            if (DRM_NO_ERROR == result) {
+                ++mDecryptSessionId;
+                mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
+                break;
+            }
+        }
+    }
     if (DRM_NO_ERROR != result) {
         delete handle; handle = NULL;
         LOGE("DrmManager::openDecryptSession: no capable plug-in found");
     }
-
     return handle;
 }
 
 status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+    Mutex::Autolock _l(mDecryptLock);
     status_t result = DRM_ERROR_UNKNOWN;
     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
@@ -443,28 +480,6 @@
     return result;
 }
 
-void DrmManager::initializePlugIns(int uniqueId) {
-    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
-
-    for (unsigned int index = 0; index < plugInIdList.size(); index++) {
-        IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
-        rDrmEngine.initialize(uniqueId);
-        rDrmEngine.setOnInfoListener(uniqueId, this);
-    }
-}
-
-void DrmManager::populate(int uniqueId) {
-    Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
-
-    for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
-        String8 plugInPath = plugInPathList[i];
-        DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId);
-        if (NULL != info) {
-            mSupportInfoToPlugInIdMap.add(*info, plugInPath);
-        }
-    }
-}
-
 String8 DrmManager::getSupportedPlugInId(
             int uniqueId, const String8& path, const String8& mimeType) {
     String8 plugInId("");
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index cf9bab1..8cf510d 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -27,21 +27,21 @@
 
 using namespace android;
 
-#define SUCCESS 0
-
 void DrmManagerService::instantiate() {
     LOGV("instantiate");
     defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService());
 }
 
-DrmManagerService::DrmManagerService() {
+DrmManagerService::DrmManagerService() :
+        mDrmManager(NULL) {
     LOGV("created");
-    mDrmManager = NULL;
     mDrmManager = new DrmManager();
+    mDrmManager->loadPlugIns();
 }
 
 DrmManagerService::~DrmManagerService() {
     LOGV("Destroyed");
+    mDrmManager->unloadPlugIns();
     delete mDrmManager; mDrmManager = NULL;
 }
 
@@ -53,14 +53,12 @@
     mDrmManager->removeUniqueId(uniqueId);
 }
 
-status_t DrmManagerService::loadPlugIns(int uniqueId) {
-    LOGV("Entering load plugins");
-    return mDrmManager->loadPlugIns(uniqueId);
+void DrmManagerService::addClient(int uniqueId) {
+    mDrmManager->addClient(uniqueId);
 }
 
-status_t DrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
-    LOGV("Entering load plugins from path");
-    return mDrmManager->loadPlugIns(uniqueId, plugInDirPath);
+void DrmManagerService::removeClient(int uniqueId) {
+    mDrmManager->removeClient(uniqueId);
 }
 
 status_t DrmManagerService::setDrmServiceListener(
@@ -70,11 +68,6 @@
     return DRM_NO_ERROR;
 }
 
-status_t DrmManagerService::unloadPlugIns(int uniqueId) {
-    LOGV("Entering unload plugins");
-    return mDrmManager->unloadPlugIns(uniqueId);
-}
-
 status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
     LOGV("Entering installDrmEngine");
     return mDrmManager->installDrmEngine(uniqueId, drmEngineFile);
@@ -182,6 +175,12 @@
     return mDrmManager->openDecryptSession(uniqueId, fd, offset, length);
 }
 
+DecryptHandle* DrmManagerService::openDecryptSession(
+            int uniqueId, const char* uri) {
+    LOGV("Entering DrmManagerService::openDecryptSession with uri");
+    return mDrmManager->openDecryptSession(uniqueId, uri);
+}
+
 status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     LOGV("Entering closeDecryptSession");
     return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
diff --git a/drm/java/android/drm/DrmErrorEvent.java b/drm/java/android/drm/DrmErrorEvent.java
index 8e71634..9294884 100644
--- a/drm/java/android/drm/DrmErrorEvent.java
+++ b/drm/java/android/drm/DrmErrorEvent.java
@@ -45,35 +45,19 @@
      */
     public static final int TYPE_NO_INTERNET_CONNECTION = 2005;
     /**
-     * TYPE_REGISTRATION_FAILED, when failed to register with the service.
+     * TYPE_PROCESS_DRM_INFO_FAILED, when failed to process DrmInfo.
      */
-    public static final int TYPE_REGISTRATION_FAILED = 2006;
-    /**
-     * TYPE_UNREGISTRATION_FAILED, when failed to unregister with the service.
-     */
-    public static final int TYPE_UNREGISTRATION_FAILED = 2007;
-    /**
-     * TYPE_RIGHTS_ACQUISITION_FAILED, when failed to acquire the rights information required.
-     */
-    public static final int TYPE_RIGHTS_ACQUISITION_FAILED = 2008;
-    /**
-     * TYPE_INITIALIZE_FAILED, when failed to load and initialize the available plugins.
-     */
-    public static final int TYPE_INITIALIZE_FAILED = 2009;
-    /**
-     * TYPE_FINALIZE_FAILED, when failed to unload and finalize the loaded plugins.
-     */
-    public static final int TYPE_FINALIZE_FAILED = 2010;
+    public static final int TYPE_PROCESS_DRM_INFO_FAILED = 2006;
     /**
      * TYPE_REMOVE_ALL_RIGHTS_FAILED, when failed to remove all the rights objects
      * associated with all DRM schemes.
      */
-    public static final int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2011;
+    public static final int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2007;
     /**
      * TYPE_DRM_INFO_ACQUISITION_FAILED, when failed to get the required information to
      * communicate with the service.
      */
-    public static final int TYPE_DRM_INFO_ACQUISITION_FAILED = 2012;
+    public static final int TYPE_DRM_INFO_ACQUISITION_FAILED = 2008;
 
     /**
      * constructor to create DrmErrorEvent object with given parameters
diff --git a/drm/java/android/drm/DrmEvent.java b/drm/java/android/drm/DrmEvent.java
index d6e0c3a..583337f 100644
--- a/drm/java/android/drm/DrmEvent.java
+++ b/drm/java/android/drm/DrmEvent.java
@@ -23,35 +23,19 @@
  */
 public class DrmEvent {
     /**
-     * Constant field signifies that unload and finalize the loaded plugins successfully
-     */
-    public static final int TYPE_FINALIZED = 1001;
-    /**
-     * Constant field signifies that register with the service successfully
-     */
-    public static final int TYPE_REGISTERED = 1002;
-    /**
-     * Constant field signifies that load and initialized the available plugins successfully
-     */
-    public static final int TYPE_INITIALIZED = 1003;
-    /**
-     * Constant field signifies that unregister with the service successfully
-     */
-    public static final int TYPE_UNREGISTERED = 1004;
-    /**
-     * Constant field signifies that rights information is acquired successfully
-     */
-    public static final int TYPE_RIGHTS_ACQUIRED = 1005;
-    /**
      * Constant field signifies that all the rights information associated with
      * all DRM schemes are removed successfully
      */
-    public static final int TYPE_ALL_RIGHTS_REMOVED = 1006;
+    public static final int TYPE_ALL_RIGHTS_REMOVED = 1001;
+    /**
+     * Constant field signifies that given information is processed successfully
+     */
+    public static final int TYPE_DRM_INFO_PROCESSED = 1002;
     /**
      * Constant field signifies that the required information to communicate with
      * the service is acquired sucessfully
      */
-    public static final int TYPE_DRM_INFO_ACQUIRED = 1007;
+    public static final int TYPE_DRM_INFO_ACQUIRED = 1003;
 
     public static final String DRM_INFO_STATUS_OBJECT = "drm_info_status_object";
     public static final String DRM_INFO_OBJECT = "drm_info_object";
diff --git a/drm/java/android/drm/DrmInfoStatus.java b/drm/java/android/drm/DrmInfoStatus.java
index 7e9ca3e..b37ea51 100644
--- a/drm/java/android/drm/DrmInfoStatus.java
+++ b/drm/java/android/drm/DrmInfoStatus.java
@@ -31,6 +31,7 @@
     public static final int STATUS_ERROR = 2;
 
     public final int statusCode;
+    public final int infoType;
     public final String mimeType;
     public final ProcessedData data;
 
@@ -38,11 +39,13 @@
      * constructor to create DrmInfoStatus object with given parameters
      *
      * @param _statusCode Status of the communication
+     * @param _infoType Type of the DRM information processed
      * @param _data The processed data
      * @param _mimeType MIME type
      */
-    public DrmInfoStatus(int _statusCode, ProcessedData _data, String _mimeType) {
+    public DrmInfoStatus(int _statusCode, int _infoType, ProcessedData _data, String _mimeType) {
         statusCode = _statusCode;
+        infoType = _infoType;
         data = _data;
         mimeType = _mimeType;
     }
diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java
index 147c530..5044d36 100644
--- a/drm/java/android/drm/DrmManagerClient.java
+++ b/drm/java/android/drm/DrmManagerClient.java
@@ -16,9 +16,11 @@
 
 package android.drm;
 
+import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
+import android.database.sqlite.SQLiteException;
 import android.net.Uri;
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -99,14 +101,9 @@
         public void onError(DrmManagerClient client, DrmErrorEvent event);
     }
 
-    private static final int STATE_UNINITIALIZED = 0;
-    private static final int STATE_INITIALIZED = 1;
-
-    private static final int ACTION_INITIALIZE = 1000;
-    private static final int ACTION_FINALIZE = 1001;
-    private static final int ACTION_REMOVE_ALL_RIGHTS = 1002;
-    private static final int ACTION_ACQUIRE_DRM_INFO = 1003;
-    private static final int ACTION_PROCESS_DRM_INFO = 1004;
+    private static final int ACTION_REMOVE_ALL_RIGHTS = 1001;
+    private static final int ACTION_ACQUIRE_DRM_INFO = 1002;
+    private static final int ACTION_PROCESS_DRM_INFO = 1003;
 
     private int mUniqueId;
     private int mNativeContext;
@@ -116,7 +113,6 @@
     private OnInfoListener mOnInfoListener;
     private OnEventListener mOnEventListener;
     private OnErrorListener mOnErrorListener;
-    private int mCurrentState = STATE_UNINITIALIZED;
 
     private class EventHandler extends Handler {
 
@@ -130,16 +126,6 @@
             HashMap<String, Object> attributes = new HashMap<String, Object>();
 
             switch(msg.what) {
-            case ACTION_INITIALIZE: {
-                if (ERROR_NONE == _loadPlugIns(mUniqueId, msg.obj)) {
-                    mCurrentState = STATE_INITIALIZED;
-                    event = new DrmEvent(mUniqueId, DrmEvent.TYPE_INITIALIZED, null);
-                } else {
-                    error = new DrmErrorEvent(mUniqueId,
-                            DrmErrorEvent.TYPE_INITIALIZE_FAILED, null);
-                }
-                break;
-            }
             case ACTION_ACQUIRE_DRM_INFO: {
                 final DrmInfoRequest request = (DrmInfoRequest) msg.obj;
                 DrmInfo drmInfo = _acquireDrmInfo(mUniqueId, request);
@@ -157,10 +143,10 @@
                 DrmInfoStatus status = _processDrmInfo(mUniqueId, drmInfo);
                 if (null != status && DrmInfoStatus.STATUS_OK == status.statusCode) {
                     attributes.put(DrmEvent.DRM_INFO_STATUS_OBJECT, status);
-                    event = new DrmEvent(mUniqueId, getEventType(drmInfo.getInfoType()), null);
+                    event = new DrmEvent(mUniqueId, getEventType(status.infoType), null);
                 } else {
-                    error = new DrmErrorEvent(mUniqueId,
-                            getErrorType(drmInfo.getInfoType()), null);
+                    int infoType = (null != status) ? status.infoType : drmInfo.getInfoType();
+                    error = new DrmErrorEvent(mUniqueId, getErrorType(infoType), null);
                 }
                 break;
             }
@@ -173,16 +159,6 @@
                 }
                 break;
             }
-            case ACTION_FINALIZE: {
-                if (ERROR_NONE == _unloadPlugIns(mUniqueId)) {
-                    mCurrentState = STATE_UNINITIALIZED;
-                    event = new DrmEvent(mUniqueId, DrmEvent.TYPE_FINALIZED, null);
-                } else {
-                    error = new DrmErrorEvent(mUniqueId,
-                            DrmErrorEvent.TYPE_FINALIZE_FAILED, null);
-                }
-                break;
-            }
             default:
                 Log.e(TAG, "Unknown message type " + msg.what);
                 return;
@@ -283,6 +259,12 @@
 
         // save the unique id
         mUniqueId = hashCode();
+
+        _initialize(mUniqueId, new WeakReference<DrmManagerClient>(this));
+    }
+
+    protected void finalize() {
+        _finalize(mUniqueId);
     }
 
     /**
@@ -322,58 +304,11 @@
     }
 
     /**
-     * Initializes DrmFramework, which loads all available plug-ins
-     * in the default plug-in directory path
-     *
-     * @return
-     *     ERROR_NONE for success
-     *     ERROR_UNKNOWN for failure
-     */
-    public int loadPlugIns() {
-        int result = ERROR_UNKNOWN;
-        if (STATE_UNINITIALIZED == getState()) {
-            if (null != mEventHandler) {
-                Message msg = mEventHandler.obtainMessage(
-                        ACTION_INITIALIZE, new WeakReference<DrmManagerClient>(this));
-                result = (mEventHandler.sendMessage(msg)) ? ERROR_NONE : result;
-            }
-        } else {
-            result = ERROR_NONE;
-        }
-        return result;
-    }
-
-    /**
-     * Finalize DrmFramework, which release resources associated with each plug-in
-     * and unload all plug-ins.
-     *
-     * @return
-     *     ERROR_NONE for success
-     *     ERROR_UNKNOWN for failure
-     */
-    public int unloadPlugIns() {
-        int result = ERROR_UNKNOWN;
-        if (STATE_INITIALIZED == getState()) {
-            if (null != mEventHandler) {
-                Message msg = mEventHandler.obtainMessage(ACTION_FINALIZE);
-                result = (mEventHandler.sendMessage(msg)) ? ERROR_NONE : result;
-            }
-        } else {
-            result = ERROR_NONE;
-        }
-        return result;
-    }
-
-    /**
      * Retrieves informations about all the plug-ins registered with DrmFramework.
      *
      * @return Array of DrmEngine plug-in strings
      */
     public String[] getAvailableDrmEngines() {
-        if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
-        }
-
         DrmSupportInfo[] supportInfos = _getAllSupportInfo(mUniqueId);
         ArrayList<String> descriptions = new ArrayList<String>();
 
@@ -396,8 +331,6 @@
     public ContentValues getConstraints(String path, int action) {
         if (null == path || path.equals("") || !DrmStore.Action.isValid(action)) {
             throw new IllegalArgumentException("Given usage or path is invalid/null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _getConstraints(mUniqueId, path, action);
     }
@@ -411,6 +344,9 @@
      *         or null in case of failure
      */
     public ContentValues getConstraints(Uri uri, int action) {
+        if (null == uri || Uri.EMPTY == uri) {
+            throw new IllegalArgumentException("Uri should be non null");
+        }
         return getConstraints(convertUriToPath(uri), action);
     }
 
@@ -432,8 +368,6 @@
             DrmRights drmRights, String rightsPath, String contentPath) throws IOException {
         if (null == drmRights || !drmRights.isValid()) {
             throw new IllegalArgumentException("Given drmRights or contentPath is not valid");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         if (null != rightsPath && !rightsPath.equals("")) {
             DrmUtils.writeToFile(rightsPath, drmRights.getData());
@@ -451,8 +385,6 @@
         if (null == engineFilePath || engineFilePath.equals("")) {
             throw new IllegalArgumentException(
                 "Given engineFilePath: "+ engineFilePath + "is not valid");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         _installDrmEngine(mUniqueId, engineFilePath);
     }
@@ -464,14 +396,11 @@
      * @param mimeType Mimetype of the object to be handled
      * @return
      *        true - if the given mimeType or path can be handled
-     *        false - cannot be handled. false will be return in case
-     *        the state is uninitialized
+     *        false - cannot be handled.
      */
     public boolean canHandle(String path, String mimeType) {
         if ((null == path || path.equals("")) && (null == mimeType || mimeType.equals(""))) {
             throw new IllegalArgumentException("Path or the mimetype should be non null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _canHandle(mUniqueId, path, mimeType);
     }
@@ -483,8 +412,7 @@
      * @param mimeType Mimetype of the object to be handled
      * @return
      *        true - if the given mimeType or path can be handled
-     *        false - cannot be handled. false will be return in case
-     *        the state is uninitialized
+     *        false - cannot be handled.
      */
     public boolean canHandle(Uri uri, String mimeType) {
         if ((null == uri || Uri.EMPTY == uri) && (null == mimeType || mimeType.equals(""))) {
@@ -504,8 +432,6 @@
     public int processDrmInfo(DrmInfo drmInfo) {
         if (null == drmInfo || !drmInfo.isValid()) {
             throw new IllegalArgumentException("Given drmInfo is invalid/null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         int result = ERROR_UNKNOWN;
         if (null != mEventHandler) {
@@ -526,8 +452,6 @@
     public int acquireDrmInfo(DrmInfoRequest drmInfoRequest) {
         if (null == drmInfoRequest || !drmInfoRequest.isValid()) {
             throw new IllegalArgumentException("Given drmInfoRequest is invalid/null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         int result = ERROR_UNKNOWN;
         if (null != mEventHandler) {
@@ -550,8 +474,6 @@
     public int getDrmObjectType(String path, String mimeType) {
         if ((null == path || path.equals("")) && (null == mimeType || mimeType.equals(""))) {
             throw new IllegalArgumentException("Path or the mimetype should be non null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _getDrmObjectType(mUniqueId, path, mimeType);
     }
@@ -589,8 +511,6 @@
     public String getOriginalMimeType(String path) {
         if (null == path || path.equals("")) {
             throw new IllegalArgumentException("Given path should be non null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _getOriginalMimeType(mUniqueId, path);
     }
@@ -644,8 +564,6 @@
     public int checkRightsStatus(String path, int action) {
         if (null == path || path.equals("") || !DrmStore.Action.isValid(action)) {
             throw new IllegalArgumentException("Given path or action is not valid");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _checkRightsStatus(mUniqueId, path, action);
     }
@@ -676,8 +594,6 @@
     public int removeRights(String path) {
         if (null == path || path.equals("")) {
             throw new IllegalArgumentException("Given path should be non null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _removeRights(mUniqueId, path);
     }
@@ -706,9 +622,6 @@
      *     ERROR_UNKNOWN for failure
      */
     public int removeAllRights() {
-        if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
-        }
         int result = ERROR_UNKNOWN;
         if (null != mEventHandler) {
             Message msg = mEventHandler.obtainMessage(ACTION_REMOVE_ALL_RIGHTS);
@@ -729,8 +642,6 @@
     public int openConvertSession(String mimeType) {
         if (null == mimeType || mimeType.equals("")) {
             throw new IllegalArgumentException("Path or the mimeType should be non null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _openConvertSession(mUniqueId, mimeType);
     }
@@ -750,8 +661,6 @@
     public DrmConvertedStatus convertData(int convertId, byte[] inputData) {
         if (null == inputData || 0 >= inputData.length) {
             throw new IllegalArgumentException("Given inputData should be non null");
-        } else if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
         }
         return _convertData(mUniqueId, convertId, inputData);
     }
@@ -769,28 +678,17 @@
      *     the application on which offset these signature data should be appended.
      */
     public DrmConvertedStatus closeConvertSession(int convertId) {
-        if (STATE_UNINITIALIZED == getState()) {
-            throw new IllegalStateException("Not Initialized yet");
-        }
         return _closeConvertSession(mUniqueId, convertId);
     }
 
-    private int getState() {
-        return mCurrentState;
-    }
-
     private int getEventType(int infoType) {
         int eventType = -1;
 
         switch (infoType) {
         case DrmInfoRequest.TYPE_REGISTRATION_INFO:
-            eventType = DrmEvent.TYPE_REGISTERED;
-            break;
         case DrmInfoRequest.TYPE_UNREGISTRATION_INFO:
-            eventType = DrmEvent.TYPE_UNREGISTERED;
-            break;
         case DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_INFO:
-            eventType = DrmEvent.TYPE_RIGHTS_ACQUIRED;
+            eventType = DrmEvent.TYPE_DRM_INFO_PROCESSED;
             break;
         }
         return eventType;
@@ -801,13 +699,9 @@
 
         switch (infoType) {
         case DrmInfoRequest.TYPE_REGISTRATION_INFO:
-            error = DrmErrorEvent.TYPE_REGISTRATION_FAILED;
-            break;
         case DrmInfoRequest.TYPE_UNREGISTRATION_INFO:
-            error = DrmErrorEvent.TYPE_UNREGISTRATION_FAILED;
-            break;
         case DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_INFO:
-            error = DrmErrorEvent.TYPE_RIGHTS_ACQUISITION_FAILED;
+            error = DrmErrorEvent.TYPE_PROCESS_DRM_INFO_FAILED;
             break;
         }
         return error;
@@ -822,25 +716,35 @@
      * <row_index> the index of the content in given table
      */
     private String convertUriToPath(Uri uri) {
+        String path = null;
         String scheme = uri.getScheme();
-        if (null == scheme || scheme.equals("file")) {
-            return uri.getPath();
+        if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
+            path = uri.getPath();
+        } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
+            String[] projection = new String[] {MediaStore.MediaColumns.DATA};
+            Cursor cursor = null;
+            try {
+                cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
+            } catch (SQLiteException e) {
+                throw new IllegalArgumentException("Given Uri is not formatted in a way " +
+                        "so that it can be found in media store.");
+            }
+            if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
+                throw new IllegalArgumentException("Given Uri could not be found in media store");
+            }
+            int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
+            path = cursor.getString(pathIndex);
+            cursor.close();
+        } else {
+            throw new IllegalArgumentException("Given Uri scheme is not supported");
         }
-        String[] projection = new String[] {MediaStore.MediaColumns.DATA};
-        Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
-        if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
-            throw new IllegalArgumentException("Given Uri could not be found in media store");
-        }
-        int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
-        String path = cursor.getString(pathIndex);
-        cursor.close();
         return path;
     }
 
     // private native interfaces
-    private native int _loadPlugIns(int uniqueId, Object weak_this);
+    private native void _initialize(int uniqueId, Object weak_this);
 
-    private native int _unloadPlugIns(int uniqueId);
+    private native void _finalize(int uniqueId);
 
     private native void _installDrmEngine(int uniqueId, String engineFilepath);
 
diff --git a/drm/java/android/drm/DrmUtils.java b/drm/java/android/drm/DrmUtils.java
index 5e5397c..8903485 100644
--- a/drm/java/android/drm/DrmUtils.java
+++ b/drm/java/android/drm/DrmUtils.java
@@ -167,6 +167,9 @@
 
                 //Fetch Value
                 String strValue = readMultipleBytes(constraintData, valueLength, index);
+                if (strValue.equals(" ")) {
+                    strValue = "";
+                }
                 index += valueLength;
                 mMap.put(strKey, strValue);
             }
diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp
index 6158b66..e5e4547 100644
--- a/drm/jni/android_drm_DrmManagerClient.cpp
+++ b/drm/jni/android_drm_DrmManagerClient.cpp
@@ -15,7 +15,7 @@
  */
 
 //#define LOG_NDEBUG 0
-#define LOG_TAG "DrmManager-JNI"
+#define LOG_TAG "android_drm_DrmManagerClient"
 #include <utils/Log.h>
 
 #include <jni.h>
@@ -223,38 +223,32 @@
     return sp<DrmManagerClientImpl>(client);
 }
 
-static jint android_drm_DrmManagerClient_loadPlugIns(
+static void android_drm_DrmManagerClient_initialize(
         JNIEnv* env, jobject thiz, jint uniqueId, jobject weak_thiz) {
-    LOGV("load plugins - Enter");
+    LOGV("initialize - Enter");
 
     sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId);
+    drmManager->addClient(uniqueId);
 
     // Set the listener to DrmManager
     sp<DrmManagerClient::OnInfoListener> listener = new JNIOnInfoListener(env, thiz, weak_thiz);
     drmManager->setOnInfoListener(uniqueId, listener);
 
     setDrmManagerClientImpl(env, thiz, drmManager);
-
-    LOGV("load plugins - Exit");
-    return getDrmManagerClientImpl(env, thiz)->loadPlugIns(uniqueId);
+    LOGV("initialize - Exit");
 }
 
-static jint android_drm_DrmManagerClient_unloadPlugIns(JNIEnv* env, jobject thiz, jint uniqueId) {
-    LOGV("unload plugins - Enter");
-    sp<DrmManagerClientImpl> client = getDrmManagerClientImpl(env, thiz);
-
+static void android_drm_DrmManagerClient_finalize(JNIEnv* env, jobject thiz, jint uniqueId) {
+    LOGV("finalize - Enter");
     DrmManagerClientImpl::remove(uniqueId);
-    int result = client->unloadPlugIns(uniqueId);
-    if (DRM_NO_ERROR == result) {
-        client->setOnInfoListener(uniqueId, NULL);
+    getDrmManagerClientImpl(env, thiz)->setOnInfoListener(uniqueId, NULL);
 
-        sp<DrmManagerClientImpl> oldClient = setDrmManagerClientImpl(env, thiz, NULL);
-        if (oldClient != NULL) {
-            oldClient->setOnInfoListener(uniqueId, NULL);
-        }
+    sp<DrmManagerClientImpl> oldClient = setDrmManagerClientImpl(env, thiz, NULL);
+    if (oldClient != NULL) {
+        oldClient->setOnInfoListener(uniqueId, NULL);
+        oldClient->removeClient(uniqueId);
     }
-    LOGV("unload plugins - Exit");
-    return result;
+    LOGV("finalize - Exit");
 }
 
 static jobject android_drm_DrmManagerClient_getConstraintsFromContent(
@@ -441,6 +435,7 @@
 
     if (NULL != localRef && NULL != pDrmInfoStatus) {
         int statusCode = pDrmInfoStatus->statusCode;
+        int infoType = pDrmInfoStatus->infoType;
 
         jbyteArray dataArray = NULL;
         if (NULL != pDrmInfoStatus->drmBuffer) {
@@ -461,10 +456,10 @@
 
         constructorId
             = env->GetMethodID(localRef,
-                "<init>", "(ILandroid/drm/ProcessedData;Ljava/lang/String;)V");
+                "<init>", "(IILandroid/drm/ProcessedData;Ljava/lang/String;)V");
 
-        drmInfoStatus = env->NewObject(localRef, constructorId, statusCode, processedData,
-                                env->NewStringUTF(pDrmInfoStatus->mimeType.string()));
+        drmInfoStatus = env->NewObject(localRef, constructorId, statusCode, infoType,
+                processedData, env->NewStringUTF(pDrmInfoStatus->mimeType.string()));
     }
 
     delete mData; mData = NULL;
@@ -678,11 +673,11 @@
 
 static JNINativeMethod nativeMethods[] = {
 
-    {"_loadPlugIns", "(ILjava/lang/Object;)I",
-                                    (void*)android_drm_DrmManagerClient_loadPlugIns},
+    {"_initialize", "(ILjava/lang/Object;)V",
+                                    (void*)android_drm_DrmManagerClient_initialize},
 
-    {"_unloadPlugIns", "(I)I",
-                                    (void*)android_drm_DrmManagerClient_unloadPlugIns},
+    {"_finalize", "(I)V",
+                                    (void*)android_drm_DrmManagerClient_finalize},
 
     {"_getConstraints", "(ILjava/lang/String;I)Landroid/content/ContentValues;",
                                     (void*)android_drm_DrmManagerClient_getConstraintsFromContent},
diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp
index c996994..f0439eb 100644
--- a/drm/libdrmframework/DrmManagerClient.cpp
+++ b/drm/libdrmframework/DrmManagerClient.cpp
@@ -22,36 +22,23 @@
 
 using namespace android;
 
-DrmManagerClient::DrmManagerClient() {
-    int uniqueId = 0;
-    mDrmManagerClientImpl = NULL;
-
-    mDrmManagerClientImpl = DrmManagerClientImpl::create(&uniqueId);
-    mUniqueId = uniqueId;
-
-    loadPlugIns();
+DrmManagerClient::DrmManagerClient():
+        mUniqueId(0), mDrmManagerClientImpl(NULL) {
+    mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId);
+    mDrmManagerClientImpl->addClient(mUniqueId);
 }
 
 DrmManagerClient::~DrmManagerClient() {
     DrmManagerClientImpl::remove(mUniqueId);
-    unloadPlugIns();
-
+    mDrmManagerClientImpl->removeClient(mUniqueId);
     delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL;
 }
 
-status_t DrmManagerClient::loadPlugIns() {
-    return mDrmManagerClientImpl->loadPlugIns(mUniqueId);
-}
-
 status_t DrmManagerClient::setOnInfoListener(
                     const sp<DrmManagerClient::OnInfoListener>& infoListener) {
     return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener);
 }
 
-status_t DrmManagerClient::unloadPlugIns() {
-    return mDrmManagerClientImpl->unloadPlugIns(mUniqueId);
-}
-
 DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) {
     return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action);
 }
@@ -86,6 +73,7 @@
 }
 
 status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) {
+    Mutex::Autolock _l(mDecryptLock);
     return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve);
 }
 
@@ -128,12 +116,17 @@
     return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length);
 }
 
+DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) {
+    return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri);
+}
+
 status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) {
     return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
 }
 
 status_t DrmManagerClient::initializeDecryptUnit(
             DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
+    Mutex::Autolock _l(mDecryptLock);
     return mDrmManagerClientImpl->initializeDecryptUnit(
             mUniqueId, decryptHandle, decryptUnitId, headerInfo);
 }
@@ -141,16 +134,19 @@
 status_t DrmManagerClient::decrypt(
     DecryptHandle* decryptHandle, int decryptUnitId,
     const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
+    Mutex::Autolock _l(mDecryptLock);
     return mDrmManagerClientImpl->decrypt(
             mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
 }
 
 status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) {
+    Mutex::Autolock _l(mDecryptLock);
     return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId);
 }
 
 ssize_t DrmManagerClient::pread(
             DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) {
+    Mutex::Autolock _l(mDecryptLock);
     return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset);
 }
 
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index 272adcd..b3ae9a7 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -46,14 +46,6 @@
     getDrmManagerService()->removeUniqueId(uniqueId);
 }
 
-DrmManagerClientImpl::DrmManagerClientImpl() {
-
-}
-
-DrmManagerClientImpl::~DrmManagerClientImpl() {
-
-}
-
 const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() {
     mMutex.lock();
     if (NULL == mDrmManagerService.get()) {
@@ -77,16 +69,12 @@
     return mDrmManagerService;
 }
 
-status_t DrmManagerClientImpl::loadPlugIns(int uniqueId) {
-    return getDrmManagerService()->loadPlugIns(uniqueId);
+void DrmManagerClientImpl::addClient(int uniqueId) {
+    getDrmManagerService()->addClient(uniqueId);
 }
 
-status_t DrmManagerClientImpl::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
-    status_t status = DRM_ERROR_UNKNOWN;
-    if (EMPTY_STRING != plugInDirPath) {
-        status = getDrmManagerService()->loadPlugIns(uniqueId, plugInDirPath);
-    }
-    return status;
+void DrmManagerClientImpl::removeClient(int uniqueId) {
+    getDrmManagerService()->removeClient(uniqueId);
 }
 
 status_t DrmManagerClientImpl::setOnInfoListener(
@@ -96,10 +84,6 @@
     return getDrmManagerService()->setDrmServiceListener(uniqueId, this);
 }
 
-status_t DrmManagerClientImpl::unloadPlugIns(int uniqueId) {
-    return getDrmManagerService()->unloadPlugIns(uniqueId);
-}
-
 status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
     status_t status = DRM_ERROR_UNKNOWN;
     if (EMPTY_STRING != drmEngineFile) {
@@ -251,6 +235,14 @@
     return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length);
 }
 
+DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char* uri) {
+    DecryptHandle* handle = NULL;
+    if (NULL != uri) {
+        handle = getDrmManagerService()->openDecryptSession(uniqueId, uri);
+    }
+    return handle;
+}
+
 status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     status_t status = DRM_ERROR_UNKNOWN;
     if (NULL != decryptHandle) {
diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h
index dc3e460..d782f5b 100644
--- a/drm/libdrmframework/include/DrmManager.h
+++ b/drm/libdrmframework/include/DrmManager.h
@@ -57,15 +57,19 @@
 
     void removeUniqueId(int uniqueId);
 
-    status_t loadPlugIns(int uniqueId);
+    void addClient(int uniqueId);
 
-    status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+    void removeClient(int uniqueId);
+
+    status_t loadPlugIns();
+
+    status_t loadPlugIns(const String8& plugInDirPath);
+
+    status_t unloadPlugIns();
 
     status_t setDrmServiceListener(
             int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
 
-    status_t unloadPlugIns(int uniqueId);
-
     status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
 
     DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
@@ -107,6 +111,8 @@
 
     DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
 
+    DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -129,12 +135,8 @@
 
     String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
 
-    void populate(int uniqueId);
-
     bool canHandle(int uniqueId, const String8& path);
 
-    void initializePlugIns(int uniqueId);
-
 private:
     static Vector<int> mUniqueIdVector;
     static const String8 EMPTY_STRING;
diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h
index 492c7f5..1c6be46 100644
--- a/drm/libdrmframework/include/DrmManagerClientImpl.h
+++ b/drm/libdrmframework/include/DrmManagerClientImpl.h
@@ -35,36 +35,29 @@
  */
 class DrmManagerClientImpl : public BnDrmServiceListener {
 private:
-    DrmManagerClientImpl();
+    DrmManagerClientImpl() { }
 
 public:
     static DrmManagerClientImpl* create(int* pUniqueId);
 
     static void remove(int uniqueId);
 
-    virtual ~DrmManagerClientImpl();
+    virtual ~DrmManagerClientImpl() { }
 
 public:
     /**
-     * Initialize DRM Manager
-     *     load available plug-ins from default plugInDirPath
+     * Adds the client respective to given unique id.
      *
      * @param[in] uniqueId Unique identifier for a session
-     * @return status_t
-     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
      */
-    status_t loadPlugIns(int uniqueId);
+    void addClient(int uniqueId);
 
     /**
-     * Finalize DRM Manager
-     *     release resources associated with each plug-in
-     *     unload all plug-ins and etc.
+     * Removes the client respective to given unique id.
      *
      * @param[in] uniqueId Unique identifier for a session
-     * @return status_t
-     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
      */
-    status_t unloadPlugIns(int uniqueId);
+    void removeClient(int uniqueId);
 
     /**
      * Register a callback to be invoked when the caller required to
@@ -301,6 +294,16 @@
     DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] uri Path of the protected content to be decrypted
+     * @return
+     *     Handle for the decryption session
+     */
+    DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
@@ -379,17 +382,6 @@
 
 private:
     /**
-     * Initialize DRM Manager
-     *     load available plug-ins from plugInDirPath
-     *
-     * @param[in] uniqueId Unique identifier for a session
-     * @param[in] plugInDirPath Directory from where to load plug-ins
-     * @return status_t
-     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
-     */
-    status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
-
-    /**
      * Install new DRM Engine Plug-in at the runtime
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h
index f455e15..4a3aeae 100644
--- a/drm/libdrmframework/include/DrmManagerService.h
+++ b/drm/libdrmframework/include/DrmManagerService.h
@@ -50,15 +50,13 @@
 
     void removeUniqueId(int uniqueId);
 
-    status_t loadPlugIns(int uniqueId);
+    void addClient(int uniqueId);
 
-    status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+    void removeClient(int uniqueId);
 
     status_t setDrmServiceListener(
             int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
 
-    status_t unloadPlugIns(int uniqueId);
-
     status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
 
     DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
@@ -100,6 +98,8 @@
 
     DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
 
+    DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h
index 5c668ed..1275488 100644
--- a/drm/libdrmframework/include/IDrmManagerService.h
+++ b/drm/libdrmframework/include/IDrmManagerService.h
@@ -46,10 +46,9 @@
     enum {
         ADD_UNIQUEID = IBinder::FIRST_CALL_TRANSACTION,
         REMOVE_UNIQUEID,
-        LOAD_PLUGINS,
-        LOAD_PLUGINS_FROM_PATH,
+        ADD_CLIENT,
+        REMOVE_CLIENT,
         SET_DRM_SERVICE_LISTENER,
-        UNLOAD_PLUGINS,
         INSTALL_DRM_ENGINE,
         GET_CONSTRAINTS_FROM_CONTENT,
         CAN_HANDLE,
@@ -69,6 +68,7 @@
         CLOSE_CONVERT_SESSION,
         GET_ALL_SUPPORT_INFO,
         OPEN_DECRYPT_SESSION,
+        OPEN_DECRYPT_SESSION_FROM_URI,
         CLOSE_DECRYPT_SESSION,
         INITIALIZE_DECRYPT_UNIT,
         DECRYPT,
@@ -84,15 +84,13 @@
 
     virtual void removeUniqueId(int uniqueId) = 0;
 
-    virtual status_t loadPlugIns(int uniqueId) = 0;
+    virtual void addClient(int uniqueId) = 0;
 
-    virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath) = 0;
+    virtual void removeClient(int uniqueId) = 0;
 
     virtual status_t setDrmServiceListener(
             int uniqueId, const sp<IDrmServiceListener>& infoListener) = 0;
 
-    virtual status_t unloadPlugIns(int uniqueId) = 0;
-
     virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile) = 0;
 
     virtual DrmConstraints* getConstraints(
@@ -140,6 +138,8 @@
 
     virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length) = 0;
 
+    virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri) = 0;
+
     virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
 
     virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -168,15 +168,13 @@
 
     virtual void removeUniqueId(int uniqueId);
 
-    virtual status_t loadPlugIns(int uniqueId);
+    virtual void addClient(int uniqueId);
 
-    virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+    virtual void removeClient(int uniqueId);
 
     virtual status_t setDrmServiceListener(
             int uniqueId, const sp<IDrmServiceListener>& infoListener);
 
-    virtual status_t unloadPlugIns(int uniqueId);
-
     virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
 
     virtual DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
@@ -221,6 +219,8 @@
 
     virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
 
+    virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
+
     virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
index b355534..5851af5 100644
--- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
+++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
@@ -80,6 +80,9 @@
     status_t openDecryptSession(
             int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length);
 
+    status_t openDecryptSession(
+            int uniqueId, DecryptHandle* decryptHandle, const char* uri);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -355,6 +358,18 @@
             int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0;
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] decryptHandle Handle for the current decryption session
+     * @param[in] uri Path of the protected content to be decrypted
+     * @return
+     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
+     */
+    virtual status_t onOpenDecryptSession(
+            int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0;
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
index b711500..cc03ef2 100644
--- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h
+++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
@@ -315,6 +315,18 @@
         int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0;
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] decryptHandle Handle for the current decryption session
+     * @param[in] uri Path of the protected content to be decrypted
+     * @return
+     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
+     */
+    virtual status_t openDecryptSession(
+        int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0;
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h
index eed1628..ddb7fd3 100644
--- a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h
+++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h
@@ -74,6 +74,9 @@
     status_t onOpenDecryptSession(
             int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length);
 
+    status_t onOpenDecryptSession(
+            int uniqueId, DecryptHandle* decryptHandle, const char* uri);
+
     status_t onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
index 4c7714d..41f8e91 100644
--- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
+++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
@@ -74,14 +74,14 @@
         switch (drmInfo->getInfoType()) {
         case DrmInfoRequest::TYPE_REGISTRATION_INFO: {
             const DrmBuffer* emptyBuffer = new DrmBuffer();
-            drmInfoStatus
-                = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType());
+            drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK,
+                    DrmInfoRequest::TYPE_REGISTRATION_INFO, emptyBuffer, drmInfo->getMimeType());
             break;
         }
         case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: {
             const DrmBuffer* emptyBuffer = new DrmBuffer();
-            drmInfoStatus
-                = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType());
+            drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK,
+                    DrmInfoRequest::TYPE_UNREGISTRATION_INFO, emptyBuffer, drmInfo->getMimeType());
             break;
         }
         case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: {
@@ -91,8 +91,8 @@
             data = new char[bufferSize];
             memcpy(data, licenseString.string(), bufferSize);
             const DrmBuffer* buffer = new DrmBuffer(data, bufferSize);
-            drmInfoStatus
-                = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, buffer, drmInfo->getMimeType());
+            drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK,
+                    DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO, buffer, drmInfo->getMimeType());
             break;
         }
         }
@@ -243,6 +243,11 @@
     return DRM_ERROR_CANNOT_HANDLE;
 }
 
+status_t DrmPassthruPlugIn::onOpenDecryptSession(
+            int uniqueId, DecryptHandle* decryptHandle, const char* uri) {
+    return DRM_ERROR_CANNOT_HANDLE;
+}
+
 status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     LOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId);
     if (NULL != decryptHandle) {
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index f8ad5cc..dfd6ac8 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -199,6 +199,7 @@
             throw new IllegalStateException("Resize only support for 1D allocations at this time.");
         }
         mRS.nAllocationResize1D(mID, dimX);
+        mRS.finish();  // Necessary because resize is fifoed and update is async.
 
         int typeID = mRS.nAllocationGetType(mID);
         mType = new Type(typeID, mRS);
diff --git a/graphics/java/android/renderscript/RSDriverException.java b/graphics/java/android/renderscript/RSDriverException.java
new file mode 100644
index 0000000..61787e6
--- /dev/null
+++ b/graphics/java/android/renderscript/RSDriverException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.renderscript;
+
+
+/**
+ * Base class for all exceptions thrown by the Android
+ * Renderscript
+ * @hide
+ */
+public class RSDriverException extends RSRuntimeException {
+    public RSDriverException(String string) {
+        super(string);
+    }
+}
+
+
+
diff --git a/graphics/java/android/renderscript/RSIllegalArgumentException.java b/graphics/java/android/renderscript/RSIllegalArgumentException.java
new file mode 100644
index 0000000..8d67a8d
--- /dev/null
+++ b/graphics/java/android/renderscript/RSIllegalArgumentException.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.renderscript;
+
+
+/**
+ * Base class for all exceptions thrown by the Android
+ * Renderscript
+ * @hide
+ */
+public class RSIllegalArgumentException extends RSRuntimeException {
+    public RSIllegalArgumentException(String string) {
+        super(string);
+    }
+}
+
+
diff --git a/graphics/java/android/renderscript/RSInvalidStateException.java b/graphics/java/android/renderscript/RSInvalidStateException.java
new file mode 100644
index 0000000..53b9479
--- /dev/null
+++ b/graphics/java/android/renderscript/RSInvalidStateException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.renderscript;
+
+
+/**
+ * Base class for all exceptions thrown by the Android
+ * Renderscript
+ * @hide
+ */
+public class RSInvalidStateException extends RSRuntimeException {
+    public RSInvalidStateException(String string) {
+        super(string);
+    }
+}
+
+
+
diff --git a/graphics/java/android/renderscript/RSRuntimeException.java b/graphics/java/android/renderscript/RSRuntimeException.java
new file mode 100644
index 0000000..4c97937
--- /dev/null
+++ b/graphics/java/android/renderscript/RSRuntimeException.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.renderscript;
+
+
+/**
+ * Base class for all exceptions thrown by the Android
+ * Renderscript
+ * @hide
+ */
+public class RSRuntimeException
+  extends java.lang.RuntimeException {
+    public RSRuntimeException(String string) {
+        super(string);
+    }
+}
+
diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java
index 5fe69cd..21cbb9a 100644
--- a/graphics/java/android/renderscript/RenderScriptGL.java
+++ b/graphics/java/android/renderscript/RenderScriptGL.java
@@ -128,6 +128,9 @@
                                     mSurfaceConfig.mStencilMin, mSurfaceConfig.mStencilPref,
                                     mSurfaceConfig.mSamplesMin, mSurfaceConfig.mSamplesPref,
                                     mSurfaceConfig.mSamplesQ);
+        if (mContext == 0) {
+            throw new RSDriverException("Failed to create RS context.");
+        }
         mMessageThread = new MessageThread(this);
         mMessageThread.start();
         Element.initPredefined(this);
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index caa8b13..9a40d1f 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -33,8 +33,6 @@
     int mElementCount;
     Element mElement;
 
-    Class mJavaClass;
-
     public Element getElement() {
         return mElement;
     }
@@ -124,12 +122,6 @@
         calcElementCount();
     }
 
-    public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
-        android.util.Log.e("RenderScript", "Calling depricated createFromClass");
-        return null;
-    }
-
-
     public static class Builder {
         RenderScript mRS;
         Dimension[] mDimensions;
diff --git a/include/drm/DrmInfoEvent.h b/include/drm/DrmInfoEvent.h
index c722bd3..7b409ff 100644
--- a/include/drm/DrmInfoEvent.h
+++ b/include/drm/DrmInfoEvent.h
@@ -59,8 +59,8 @@
     //! TYPE_NO_INTERNET_CONNECTION, when the Internet connection is missing and no attempt
     //! can be made to renew rights
     static const int TYPE_NO_INTERNET_CONNECTION = 2005;
-    //! TYPE_REGISTRATION_FAILED, when registration with server failed.
-    static const int TYPE_REGISTRATION_FAILED = 2006;
+    //! TYPE_PROCESS_DRM_INFO_FAILED, when failed to process DrmInfo.
+    static const int TYPE_PROCESS_DRM_INFO_FAILED = 2006;
 
 public:
     /**
diff --git a/include/drm/DrmInfoStatus.h b/include/drm/DrmInfoStatus.h
index 806aea1..88c0f40 100644
--- a/include/drm/DrmInfoStatus.h
+++ b/include/drm/DrmInfoStatus.h
@@ -41,10 +41,11 @@
      * Constructor for DrmInfoStatus
      *
      * @param[in] _statusCode Status of the communication
+     * @param[in] _infoType Type of the DRM information processed
      * @param[in] _drmBuffer Rights information
      * @param[in] _mimeType MIME type
      */
-    DrmInfoStatus(int _statusCode, const DrmBuffer* _drmBuffer, const String8& _mimeType);
+    DrmInfoStatus(int _statusCode, int _infoType, const DrmBuffer* _drmBuffer, const String8& _mimeType);
 
     /**
      * Destructor for DrmInfoStatus
@@ -55,6 +56,7 @@
 
 public:
     int statusCode;
+    int infoType;
     const DrmBuffer* drmBuffer;
     String8 mimeType;
 };
diff --git a/include/drm/DrmManagerClient.h b/include/drm/DrmManagerClient.h
index c2ad084..5963c42 100644
--- a/include/drm/DrmManagerClient.h
+++ b/include/drm/DrmManagerClient.h
@@ -17,6 +17,7 @@
 #ifndef __DRM_MANAGER_CLIENT_H__
 #define __DRM_MANAGER_CLIENT_H__
 
+#include <utils/threads.h>
 #include <binder/IInterface.h>
 #include "drm_framework_common.h"
 
@@ -67,6 +68,15 @@
     DecryptHandle* openDecryptSession(int fd, int offset, int length);
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uri Path of the protected content to be decrypted
+     * @return
+     *     Handle for the decryption session
+     */
+    DecryptHandle* openDecryptSession(const char* uri);
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] decryptHandle Handle for the decryption session
@@ -339,27 +349,8 @@
     status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray);
 
 private:
-    /**
-     * Initialize DRM Manager
-     *     load available plug-ins from default plugInDirPath
-     *
-     * @return status_t
-     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
-     */
-    status_t loadPlugIns();
-
-    /**
-     * Finalize DRM Manager
-     *    release resources associated with each plug-in
-     *    unload all plug-ins and etc.
-     *
-     * @return status_t
-     *    Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
-     */
-    status_t unloadPlugIns();
-
-private:
     int mUniqueId;
+    Mutex mDecryptLock;
     DrmManagerClientImpl* mDrmManagerClientImpl;
 };
 
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 9fd905f..1081c35 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -262,11 +262,15 @@
         DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
         DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
         DEVICE_OUT_AUX_DIGITAL = 0x400,
+        DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
+        DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
         DEVICE_OUT_DEFAULT = 0x8000,
         DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
                 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
                 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
-                DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_DEFAULT),
+                DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
+                DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
+                DEVICE_OUT_DEFAULT),
         DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
                 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
 
@@ -309,6 +313,8 @@
         FORCE_WIRED_ACCESSORY,
         FORCE_BT_CAR_DOCK,
         FORCE_BT_DESK_DOCK,
+        FORCE_ANALOG_DOCK,
+        FORCE_DIGITAL_DOCK,
         NUM_FORCE_CONFIG,
         FORCE_DEFAULT = FORCE_NONE
     };
diff --git a/include/media/stagefright/HardwareAPI.h b/include/media/stagefright/HardwareAPI.h
index b009e1b..4fd281b 100644
--- a/include/media/stagefright/HardwareAPI.h
+++ b/include/media/stagefright/HardwareAPI.h
@@ -37,11 +37,11 @@
 // buffers.  This is the mode that will be used when CPU access to the buffer is
 // required.
 //
-// When Android native buffer use has been enabled, the OMX node must support
-// only color formats in the range [OMX_COLOR_FormatAndroidPrivateStart,
-// OMX_COLOR_FormatAndroidPrivateEnd).  The node should then expect to receive
+// When Android native buffer use has been enabled for a given port, the video
+// color format for the port is to be interpreted as an Android pixel format
+// rather than an OMX color format.  The node should then expect to receive
 // UseAndroidNativeBuffer calls (via OMX_SetParameter) rather than UseBuffer
-// calls.
+// calls for that port.
 struct EnableAndroidNativeBuffersParams {
     OMX_U32 nSize;
     OMX_VERSIONTYPE nVersion;
@@ -75,16 +75,6 @@
     OMX_BOOL bStoreMetaData;
 };
 
-// Color formats in the range [OMX_COLOR_FormatAndroidPrivateStart,
-// OMX_COLOR_FormatAndroidPrivateEnd) will be converted to a gralloc pixel
-// format when used to allocate Android native buffers via gralloc.  The
-// conversion is done by subtracting OMX_COLOR_FormatAndroidPrivateStart from
-// the color format reported by the codec.
-enum {
-    OMX_COLOR_FormatAndroidPrivateStart = 0xA0000000,
-    OMX_COLOR_FormatAndroidPrivateEnd = 0xB0000000,
-};
-
 // A pointer to this struct is passed to OMX_SetParameter when the extension
 // index for the 'OMX.google.android.index.useAndroidNativeBuffer' extension is
 // given.  This call will only be performed if a prior call was made with the
diff --git a/include/ui/KeycodeLabels.h b/include/ui/KeycodeLabels.h
index ef2b6b3..73f5863 100755
--- a/include/ui/KeycodeLabels.h
+++ b/include/ui/KeycodeLabels.h
@@ -188,6 +188,7 @@
     { "NUMPAD_EQUALS", 161 },
     { "NUMPAD_LEFT_PAREN", 162 },
     { "NUMPAD_RIGHT_PAREN", 163 },
+    { "VOLUME_MUTE", 164 },
 
     // NOTE: If you add a new keycode here you must also add it to several other files.
     //       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index d661f7b..29158e5 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -38,7 +38,7 @@
 
 	LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER
 	LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-	LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia
+	LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui
 	LOCAL_MODULE := libhwui
 	LOCAL_MODULE_TAGS := optional
 	LOCAL_PRELINK_MODULE := false
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index 0994d82..93c5b34 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -46,18 +46,21 @@
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
 
     mCurrentBuffer = meshBuffer;
+    mRegionMesh = NULL;
 }
 
-/**
- * Binds the VBO used to render simple textured quads.
- */
+Caches::~Caches() {
+    delete[] mRegionMesh;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// VBO
+///////////////////////////////////////////////////////////////////////////////
+
 void Caches::bindMeshBuffer() {
     bindMeshBuffer(meshBuffer);
 }
 
-/**
- * Binds the specified VBO.
- */
 void Caches::bindMeshBuffer(const GLuint buffer) {
     if (mCurrentBuffer != buffer) {
         glBindBuffer(GL_ARRAY_BUFFER, buffer);
@@ -65,9 +68,6 @@
     }
 }
 
-/**
- * Unbinds the VBO used to render simple textured quads.
- */
 void Caches::unbindMeshBuffer() {
     if (mCurrentBuffer) {
         glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -75,5 +75,35 @@
     }
 }
 
+TextureVertex* Caches::getRegionMesh() {
+    // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
+    if (!mRegionMesh) {
+        mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4];
+
+        uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6];
+        for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) {
+            uint16_t quad = i * 4;
+            int index = i * 6;
+            regionIndices[index    ] = quad;       // top-left
+            regionIndices[index + 1] = quad + 1;   // top-right
+            regionIndices[index + 2] = quad + 2;   // bottom-left
+            regionIndices[index + 3] = quad + 2;   // bottom-left
+            regionIndices[index + 4] = quad + 1;   // top-right
+            regionIndices[index + 5] = quad + 3;   // bottom-right
+        }
+
+        glGenBuffers(1, &mRegionMeshIndices);
+        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices);
+        glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
+                regionIndices, GL_STATIC_DRAW);
+
+        delete[] regionIndices;
+    } else {
+        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices);
+    }
+
+    return mRegionMesh;
+}
+
 }; // namespace uirenderer
 }; // namespace android
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index ca22867..c019fd1 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_CACHES_H
-#define ANDROID_UI_CACHES_H
+#ifndef ANDROID_HWUI_CACHES_H
+#define ANDROID_HWUI_CACHES_H
 
 #ifndef LOG_TAG
     #define LOG_TAG "OpenGLRenderer"
@@ -46,6 +46,8 @@
 
 #define REQUIRED_TEXTURE_UNITS_COUNT 3
 
+#define REGION_MESH_QUAD_COUNT 512
+
 // Generates simple and textured vertices
 #define FV(x, y, u, v) { { x, y }, { u, v } }
 
@@ -77,6 +79,7 @@
 
 class Caches: public Singleton<Caches> {
     Caches();
+    ~Caches();
 
     friend class Singleton<Caches>;
 
@@ -84,11 +87,33 @@
 
     GLuint mCurrentBuffer;
 
+    // Used to render layers
+    TextureVertex* mRegionMesh;
+    GLuint mRegionMeshIndices;
+
 public:
+    /**
+     * Binds the VBO used to render simple textured quads.
+     */
     void bindMeshBuffer();
+
+    /**
+     * Binds the specified VBO if needed.
+     */
     void bindMeshBuffer(const GLuint buffer);
+
+    /**
+     * Unbinds the VBO used to render simple textured quads.
+     */
     void unbindMeshBuffer();
 
+    /**
+     * Returns the mesh used to draw regions. Calling this method will
+     * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
+     * indices for the region mesh.
+     */
+    TextureVertex* getRegionMesh();
+
     bool blend;
     GLenum lastSrcMode;
     GLenum lastDstMode;
@@ -118,7 +143,6 @@
 }; // class Caches
 
 }; // namespace uirenderer
-
 }; // namespace android
 
-#endif // ANDROID_UI_CACHES_H
+#endif // ANDROID_HWUI_CACHES_H
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 0dd9c5a..23ccef6 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -169,7 +169,8 @@
     int saveCount = renderer.getSaveCount() - 1;
 
     while (!mReader.eof()) {
-        switch (mReader.readInt()) {
+        int op = mReader.readInt();
+        switch (op) {
             case AcquireContext: {
                 renderer.acquireContext();
             }
@@ -195,6 +196,11 @@
                         getPaint(), getInt());
             }
             break;
+            case SaveLayerAlpha: {
+                renderer.saveLayerAlpha(getFloat(), getFloat(), getFloat(), getFloat(),
+                        getInt(), getInt());
+            }
+            break;
             case Translate: {
                 renderer.translate(getFloat(), getFloat());
             }
@@ -400,6 +406,15 @@
     return OpenGLRenderer::save(flags);
 }
 
+int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
+        int alpha, int flags) {
+    addOp(DisplayList::SaveLayerAlpha);
+    addBounds(left, top, right, bottom);
+    addInt(alpha);
+    addInt(flags);
+    return OpenGLRenderer::save(flags);
+}
+
 void DisplayListRenderer::translate(float dx, float dy) {
     addOp(DisplayList::Translate);
     addPoint(dx, dy);
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 6636de6..fd69fab 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_DISPLAY_LIST_RENDERER_H
-#define ANDROID_UI_DISPLAY_LIST_RENDERER_H
+#ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
+#define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
 
 #include <SkChunkAlloc.h>
 #include <SkFlattenable.h>
@@ -85,6 +85,7 @@
         Restore,
         RestoreToCount,
         SaveLayer,
+        SaveLayerAlpha,
         Translate,
         Rotate,
         Scale,
@@ -222,6 +223,8 @@
 
     int saveLayer(float left, float top, float right, float bottom,
             SkPaint* p, int flags);
+    int saveLayerAlpha(float left, float top, float right, float bottom,
+                int alpha, int flags);
 
     void translate(float dx, float dy);
     void rotate(float degrees);
@@ -411,4 +414,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_DISPLAY_LIST_RENDERER_H
+#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
diff --git a/libs/hwui/Extensions.h b/libs/hwui/Extensions.h
index d50d36e..eceb5c1c 100644
--- a/libs/hwui/Extensions.h
+++ b/libs/hwui/Extensions.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_EXTENSIONS_H
-#define ANDROID_UI_EXTENSIONS_H
+#ifndef ANDROID_HWUI_EXTENSIONS_H
+#define ANDROID_HWUI_EXTENSIONS_H
 
 #include <utils/SortedVector.h>
 #include <utils/String8.h>
@@ -93,4 +93,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_EXTENSIONS_H
+#endif // ANDROID_HWUI_EXTENSIONS_H
diff --git a/libs/hwui/FboCache.h b/libs/hwui/FboCache.h
index ec4afe9..ad6cc3e 100644
--- a/libs/hwui/FboCache.h
+++ b/libs/hwui/FboCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_FBO_CACHE_H
-#define ANDROID_UI_FBO_CACHE_H
+#ifndef ANDROID_HWUI_FBO_CACHE_H
+#define ANDROID_HWUI_FBO_CACHE_H
 
 #include <GLES2/gl2.h>
 
@@ -76,4 +76,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_FBO_CACHE_H
+#endif // ANDROID_HWUI_FBO_CACHE_H
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index e1a236c..5224689 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -556,6 +556,8 @@
 
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferID);
     glDrawElements(GL_TRIANGLES, mCurrentQuadIndex * 6, GL_UNSIGNED_SHORT, NULL);
+
+    mDrawn = true;
 }
 
 void FontRenderer::appendMeshQuad(float x1, float y1, float z1, float u1, float v1, float x2,
@@ -595,6 +597,13 @@
 
     mCurrentQuadIndex++;
 
+    if (mBounds) {
+        mBounds->left = fmin(mBounds->left, x1);
+        mBounds->top = fmin(mBounds->top, y3);
+        mBounds->right = fmax(mBounds->right, x3);
+        mBounds->bottom = fmax(mBounds->bottom, y1);
+    }
+
     if (mCurrentQuadIndex == mMaxNumberOfQuads) {
         issueDrawCommand();
         mCurrentQuadIndex = 0;
@@ -674,22 +683,27 @@
     return image;
 }
 
-void FontRenderer::renderText(SkPaint* paint, const Rect* clip, const char *text,
-        uint32_t startIndex, uint32_t len, int numGlyphs, int x, int y) {
+bool FontRenderer::renderText(SkPaint* paint, const Rect* clip, const char *text,
+        uint32_t startIndex, uint32_t len, int numGlyphs, int x, int y, Rect* bounds) {
     checkInit();
 
     if (!mCurrentFont) {
         LOGE("No font set");
-        return;
+        return false;
     }
 
+    mDrawn = false;
+    mBounds = bounds;
     mClip = clip;
     mCurrentFont->renderUTF(paint, text, startIndex, len, numGlyphs, x, y);
+    mBounds = NULL;
 
     if (mCurrentQuadIndex != 0) {
         issueDrawCommand();
         mCurrentQuadIndex = 0;
     }
+
+    return mDrawn;
 }
 
 void FontRenderer::computeGaussianWeights(float* weights, int32_t radius) {
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index f10efad..a76cb86 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_FONT_RENDERER_H
-#define ANDROID_UI_FONT_RENDERER_H
+#ifndef ANDROID_HWUI_FONT_RENDERER_H
+#define ANDROID_HWUI_FONT_RENDERER_H
 
 #include <utils/String8.h>
 #include <utils/String16.h>
@@ -132,8 +132,8 @@
     }
 
     void setFont(SkPaint* paint, uint32_t fontId, float fontSize);
-    void renderText(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
-            uint32_t len, int numGlyphs, int x, int y);
+    bool renderText(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
+            uint32_t len, int numGlyphs, int x, int y, Rect* bounds);
 
     struct DropShadow {
         DropShadow() { };
@@ -257,6 +257,8 @@
     uint32_t mIndexBufferID;
 
     const Rect* mClip;
+    Rect* mBounds;
+    bool mDrawn;
 
     bool mInitialized;
 
@@ -273,4 +275,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_FONT_RENDERER_H
+#endif // ANDROID_HWUI_FONT_RENDERER_H
diff --git a/libs/hwui/GammaFontRenderer.h b/libs/hwui/GammaFontRenderer.h
index 5fa45cf..b59ae81 100644
--- a/libs/hwui/GammaFontRenderer.h
+++ b/libs/hwui/GammaFontRenderer.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_GAMMA_FONT_RENDERER_H
-#define ANDROID_UI_GAMMA_FONT_RENDERER_H
+#ifndef ANDROID_HWUI_GAMMA_FONT_RENDERER_H
+#define ANDROID_HWUI_GAMMA_FONT_RENDERER_H
 
 #include <SkPaint.h>
 
@@ -45,4 +45,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_GAMMA_FONT_RENDERER_H
+#endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H
diff --git a/libs/hwui/GradientCache.h b/libs/hwui/GradientCache.h
index 48877f6..c9553f4 100644
--- a/libs/hwui/GradientCache.h
+++ b/libs/hwui/GradientCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_GRADIENT_CACHE_H
-#define ANDROID_UI_GRADIENT_CACHE_H
+#ifndef ANDROID_HWUI_GRADIENT_CACHE_H
+#define ANDROID_HWUI_GRADIENT_CACHE_H
 
 #include <SkShader.h>
 
@@ -93,4 +93,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_GRADIENT_CACHE_H
+#endif // ANDROID_HWUI_GRADIENT_CACHE_H
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index 2afe2fa..a780183 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -14,13 +14,15 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_LAYER_H
-#define ANDROID_UI_LAYER_H
+#ifndef ANDROID_HWUI_LAYER_H
+#define ANDROID_HWUI_LAYER_H
 
 #include <sys/types.h>
 
 #include <GLES2/gl2.h>
 
+#include <ui/Region.h>
+
 #include <SkXfermode.h>
 
 #include "Rect.h"
@@ -85,9 +87,15 @@
      * Height of the layer texture.
      */
     uint32_t height;
+
+    /**
+     * Dirty region indicating what parts of the layer
+     * have been drawn.
+     */
+    Region region;
 }; // struct Layer
 
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_LAYER_H
+#endif // ANDROID_HWUI_LAYER_H
diff --git a/libs/hwui/LayerCache.h b/libs/hwui/LayerCache.h
index ae792ab..4df8ab3 100644
--- a/libs/hwui/LayerCache.h
+++ b/libs/hwui/LayerCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_LAYER_CACHE_H
-#define ANDROID_UI_LAYER_CACHE_H
+#ifndef ANDROID_HWUI_LAYER_CACHE_H
+#define ANDROID_HWUI_LAYER_CACHE_H
 
 #include "Layer.h"
 #include "utils/SortedList.h"
@@ -138,4 +138,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_LAYER_CACHE_H
+#endif // ANDROID_HWUI_LAYER_CACHE_H
diff --git a/libs/hwui/Line.h b/libs/hwui/Line.h
index c529354..5c6f3d8 100644
--- a/libs/hwui/Line.h
+++ b/libs/hwui/Line.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_LINE_H
-#define ANDROID_UI_LINE_H
+#ifndef ANDROID_HWUI_LINE_H
+#define ANDROID_HWUI_LINE_H
 
 #include <GLES2/gl2.h>
 
@@ -123,4 +123,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_LINE_H
+#endif // ANDROID_HWUI_LINE_H
diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp
index 83ea615..7462d5b 100644
--- a/libs/hwui/Matrix.cpp
+++ b/libs/hwui/Matrix.cpp
@@ -271,6 +271,19 @@
         MUL_ADD_STORE(r.right, data[kScaleX], data[kTranslateX]);
         MUL_ADD_STORE(r.top, data[kScaleY], data[kTranslateY]);
         MUL_ADD_STORE(r.bottom, data[kScaleY], data[kTranslateY]);
+
+        if (r.left > r.right) {
+            float x = r.left;
+            r.left = r.right;
+            r.right = x;
+        }
+
+        if (r.top > r.bottom) {
+            float y = r.top;
+            r.top = r.bottom;
+            r.bottom = y;
+        }
+
         return;
     }
 
diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h
index fe81159..d678bd0 100644
--- a/libs/hwui/Matrix.h
+++ b/libs/hwui/Matrix.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_MATRIX_H
-#define ANDROID_UI_MATRIX_H
+#ifndef ANDROID_HWUI_MATRIX_H
+#define ANDROID_HWUI_MATRIX_H
 
 #include <SkMatrix.h>
 
@@ -137,4 +137,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_MATRIX_H
+#endif // ANDROID_HWUI_MATRIX_H
diff --git a/libs/hwui/OpenGLDebugRenderer.h b/libs/hwui/OpenGLDebugRenderer.h
index ce6a4aa..7787ff1 100644
--- a/libs/hwui/OpenGLDebugRenderer.h
+++ b/libs/hwui/OpenGLDebugRenderer.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_OPENGL_DEBUG_RENDERER_H
-#define ANDROID_UI_OPENGL_DEBUG_RENDERER_H
+#ifndef ANDROID_HWUI_OPENGL_DEBUG_RENDERER_H
+#define ANDROID_HWUI_OPENGL_DEBUG_RENDERER_H
 
 #include "OpenGLRenderer.h"
 
@@ -66,4 +66,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_OPENGL_DEBUG_RENDERER_H
+#endif // ANDROID_HWUI_OPENGL_DEBUG_RENDERER_H
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index b167131..855a4e0 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -26,6 +26,8 @@
 #include <utils/Log.h>
 #include <utils/StopWatch.h>
 
+#include <ui/Rect.h>
+
 #include "OpenGLRenderer.h"
 
 namespace android {
@@ -238,14 +240,14 @@
     mSaveCount--;
     mSnapshot = previous;
 
-    if (restoreLayer) {
-        composeLayer(current, previous);
-    }
-
     if (restoreClip) {
         dirtyClip();
     }
 
+    if (restoreLayer) {
+        composeLayer(current, previous);
+    }
+
     return restoreClip;
 }
 
@@ -285,7 +287,7 @@
 
 int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
         int alpha, int flags) {
-    if (alpha == 0xff) {
+    if (alpha >= 255 - ALPHA_THRESHOLD) {
         return saveLayer(left, top, right, bottom, NULL, flags);
     } else {
         SkPaint paint;
@@ -377,7 +379,6 @@
             bounds.getHeight() > mCaches.maxTextureSize) {
         snapshot->invisible = true;
     } else {
-        // TODO: Should take the mode into account
         snapshot->invisible = snapshot->previous->invisible ||
                 (alpha <= ALPHA_THRESHOLD && fboLayer);
     }
@@ -387,8 +388,7 @@
         return false;
     }
 
-    glActiveTexture(GL_TEXTURE0);
-
+    glActiveTexture(gTextureUnits[0]);
     Layer* layer = mCaches.layerCache.get(bounds.getWidth(), bounds.getHeight());
     if (!layer) {
         return false;
@@ -405,56 +405,7 @@
     snapshot->layer = layer;
 
     if (fboLayer) {
-        layer->fbo = mCaches.fboCache.get();
-
-        snapshot->flags |= Snapshot::kFlagIsFboLayer;
-        snapshot->fbo = layer->fbo;
-        snapshot->resetTransform(-bounds.left, -bounds.top, 0.0f);
-        snapshot->resetClip(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight());
-        snapshot->viewport.set(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight());
-        snapshot->height = bounds.getHeight();
-        snapshot->flags |= Snapshot::kFlagDirtyOrtho;
-        snapshot->orthoMatrix.load(mOrthoMatrix);
-
-        // Bind texture to FBO
-        glBindFramebuffer(GL_FRAMEBUFFER, layer->fbo);
-        glBindTexture(GL_TEXTURE_2D, layer->texture);
-
-        // Initialize the texture if needed
-        if (layer->empty) {
-            layer->empty = false;
-            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, layer->width, layer->height, 0,
-                    GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-        }
-
-        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
-                layer->texture, 0);
-
-#if DEBUG_LAYERS
-        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-        if (status != GL_FRAMEBUFFER_COMPLETE) {
-            LOGE("Framebuffer incomplete (GL error code 0x%x)", status);
-
-            glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
-            glDeleteTextures(1, &layer->texture);
-            mCaches.fboCache.put(layer->fbo);
-
-            delete layer;
-
-            return false;
-        }
-#endif
-
-        // Clear the FBO
-        glScissor(0.0f, 0.0f, bounds.getWidth() + 1.0f, bounds.getHeight() + 1.0f);
-        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-        glClear(GL_COLOR_BUFFER_BIT);
-
-        dirtyClip();
-
-        // Change the ortho projection
-        glViewport(0, 0, bounds.getWidth(), bounds.getHeight());
-        mOrthoMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f);
+        return createFboLayer(layer, bounds, snapshot, previousFbo);
     } else {
         // Copy the framebuffer into the layer
         glBindTexture(GL_TEXTURE_2D, layer->texture);
@@ -475,6 +426,83 @@
     return true;
 }
 
+bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
+        GLuint previousFbo) {
+    layer->fbo = mCaches.fboCache.get();
+
+#if RENDER_LAYERS_AS_REGIONS
+    snapshot->region = &snapshot->layer->region;
+    snapshot->flags |= Snapshot::kFlagFboTarget;
+#endif
+
+    Rect clip(bounds);
+    snapshot->transform->mapRect(clip);
+    clip.intersect(*snapshot->clipRect);
+    clip.snapToPixelBoundaries();
+    clip.intersect(snapshot->previous->viewport);
+
+    mat4 inverse;
+    inverse.loadInverse(*mSnapshot->transform);
+
+    inverse.mapRect(clip);
+    clip.snapToPixelBoundaries();
+    clip.intersect(bounds);
+    clip.translate(-bounds.left, -bounds.top);
+
+    snapshot->flags |= Snapshot::kFlagIsFboLayer;
+    snapshot->fbo = layer->fbo;
+    snapshot->resetTransform(-bounds.left, -bounds.top, 0.0f);
+    //snapshot->resetClip(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight());
+    snapshot->resetClip(clip.left, clip.top, clip.right, clip.bottom);
+    snapshot->viewport.set(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight());
+    snapshot->height = bounds.getHeight();
+    snapshot->flags |= Snapshot::kFlagDirtyOrtho;
+    snapshot->orthoMatrix.load(mOrthoMatrix);
+
+    // Bind texture to FBO
+    glBindFramebuffer(GL_FRAMEBUFFER, layer->fbo);
+    glBindTexture(GL_TEXTURE_2D, layer->texture);
+
+    // Initialize the texture if needed
+    if (layer->empty) {
+        layer->empty = false;
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, layer->width, layer->height, 0,
+                GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+    }
+
+    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
+            layer->texture, 0);
+
+#if DEBUG_LAYERS_AS_REGIONS
+    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+    if (status != GL_FRAMEBUFFER_COMPLETE) {
+        LOGE("Framebuffer incomplete (GL error code 0x%x)", status);
+
+        glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
+        glDeleteTextures(1, &layer->texture);
+        mCaches.fboCache.put(layer->fbo);
+
+        delete layer;
+
+        return false;
+    }
+#endif
+
+    // Clear the FBO, expand the clear region by 1 to get nice bilinear filtering
+    glScissor(clip.left - 1.0f, bounds.getHeight() - clip.bottom - 1.0f,
+            clip.getWidth() + 2.0f, clip.getHeight() + 2.0f);
+    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    dirtyClip();
+
+    // Change the ortho projection
+    glViewport(0, 0, bounds.getWidth(), bounds.getHeight());
+    mOrthoMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f);
+
+    return true;
+}
+
 /**
  * Read the documentation of createLayer() before doing anything in this method.
  */
@@ -484,42 +512,36 @@
         return;
     }
 
-    const bool fboLayer = current->flags & SkCanvas::kClipToLayer_SaveFlag;
+    const bool fboLayer = current->flags & Snapshot::kFlagIsFboLayer;
 
     if (fboLayer) {
         // Unbind current FBO and restore previous one
         glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
     }
 
-    // Restore the clip from the previous snapshot
-    Rect& clip(*previous->clipRect);
-    clip.snapToPixelBoundaries();
-    glScissor(clip.left, previous->height - clip.bottom, clip.getWidth(), clip.getHeight());
-
     Layer* layer = current->layer;
     const Rect& rect = layer->layer;
 
     if (!fboLayer && layer->alpha < 255) {
         drawColorRect(rect.left, rect.top, rect.right, rect.bottom,
                 layer->alpha << 24, SkXfermode::kDstIn_Mode, true);
+        // Required below, composeLayerRect() will divide by 255
+        layer->alpha = 255;
     }
 
-    const Rect& texCoords = layer->texCoords;
     mCaches.unbindMeshBuffer();
-    resetDrawTextureTexCoords(texCoords.left, texCoords.top, texCoords.right, texCoords.bottom);
 
     glActiveTexture(gTextureUnits[0]);
-    if (fboLayer) {
-        drawTextureMesh(rect.left, rect.top, rect.right, rect.bottom, layer->texture,
-                layer->alpha / 255.0f, layer->mode, layer->blend, &mMeshVertices[0].position[0],
-                &mMeshVertices[0].texture[0], GL_TRIANGLE_STRIP, gMeshCount);
-    } else {
-        drawTextureMesh(rect.left, rect.top, rect.right, rect.bottom, layer->texture,
-                1.0f, layer->mode, layer->blend, &mMeshVertices[0].position[0],
-                &mMeshVertices[0].texture[0], GL_TRIANGLE_STRIP, gMeshCount, true, true);
-    }
 
-    resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
+    // When the layer is stored in an FBO, we can save a bit of fillrate by
+    // drawing only the dirty region
+    if (fboLayer) {
+        dirtyLayer(rect.left, rect.top, rect.right, rect.bottom, *previous->transform);
+        composeLayerRegion(layer, rect);
+    } else {
+        dirtyLayer(rect.left, rect.top, rect.right, rect.bottom);
+        composeLayerRect(layer, rect, true);
+    }
 
     if (fboLayer) {
         // Detach the texture from the FBO
@@ -541,6 +563,159 @@
     }
 }
 
+void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) {
+    const Rect& texCoords = layer->texCoords;
+    resetDrawTextureTexCoords(texCoords.left, texCoords.top, texCoords.right, texCoords.bottom);
+
+    drawTextureMesh(rect.left, rect.top, rect.right, rect.bottom, layer->texture,
+            layer->alpha / 255.0f, layer->mode, layer->blend, &mMeshVertices[0].position[0],
+            &mMeshVertices[0].texture[0], GL_TRIANGLE_STRIP, gMeshCount, swap, swap);
+
+    resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
+}
+
+void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) {
+#if RENDER_LAYERS_AS_REGIONS
+    if (layer->region.isRect()) {
+        composeLayerRect(layer, rect);
+        layer->region.clear();
+        return;
+    }
+
+    if (!layer->region.isEmpty()) {
+        size_t count;
+        const android::Rect* rects = layer->region.getArray(&count);
+
+        setupDraw();
+
+        ProgramDescription description;
+        description.hasTexture = true;
+
+        const float alpha = layer->alpha / 255.0f;
+        const bool setColor = description.setColor(alpha, alpha, alpha, alpha);
+        chooseBlending(layer->blend || layer->alpha < 255, layer->mode, description, false);
+
+        useProgram(mCaches.programCache.get(description));
+
+        // Texture
+        bindTexture(layer->texture);
+        glUniform1i(mCaches.currentProgram->getUniform("sampler"), 0);
+
+        // Always premultiplied
+        if (setColor) {
+            mCaches.currentProgram->setColor(alpha, alpha, alpha, alpha);
+        }
+
+        // Mesh
+        int texCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
+        glEnableVertexAttribArray(texCoordsSlot);
+
+        mModelView.loadIdentity();
+        mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
+
+        const float texX = 1.0f / float(layer->width);
+        const float texY = 1.0f / float(layer->height);
+
+        TextureVertex* mesh = mCaches.getRegionMesh();
+        GLsizei numQuads = 0;
+
+        glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
+                gMeshStride, &mesh[0].position[0]);
+        glVertexAttribPointer(texCoordsSlot, 2, GL_FLOAT, GL_FALSE,
+                gMeshStride, &mesh[0].texture[0]);
+
+        for (size_t i = 0; i < count; i++) {
+            const android::Rect* r = &rects[i];
+
+            const float u1 = r->left * texX;
+            const float v1 = (rect.getHeight() - r->top) * texY;
+            const float u2 = r->right * texX;
+            const float v2 = (rect.getHeight() - r->bottom) * texY;
+
+            // TODO: Reject quads outside of the clip
+            TextureVertex::set(mesh++, r->left, r->top, u1, v1);
+            TextureVertex::set(mesh++, r->right, r->top, u2, v1);
+            TextureVertex::set(mesh++, r->left, r->bottom, u1, v2);
+            TextureVertex::set(mesh++, r->right, r->bottom, u2, v2);
+
+            numQuads++;
+
+            if (numQuads >= REGION_MESH_QUAD_COUNT) {
+                glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL);
+                numQuads = 0;
+                mesh = mCaches.getRegionMesh();
+            }
+        }
+
+        if (numQuads > 0) {
+            glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL);
+        }
+
+        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+        glDisableVertexAttribArray(texCoordsSlot);
+
+#if DEBUG_LAYERS_AS_REGIONS
+        uint32_t colors[] = {
+                0x7fff0000, 0x7f00ff00,
+                0x7f0000ff, 0x7fff00ff,
+        };
+
+        int offset = 0;
+        int32_t top = rects[0].top;
+        int i = 0;
+
+        for (size_t i = 0; i < count; i++) {
+            if (top != rects[i].top) {
+                offset ^= 0x2;
+                top = rects[i].top;
+            }
+
+            Rect r(rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
+            drawColorRect(r.left, r.top, r.right, r.bottom, colors[offset + (i & 0x1)],
+                    SkXfermode::kSrcOver_Mode);
+        }
+#endif
+
+        layer->region.clear();
+    }
+#else
+    composeLayerRect(layer, rect);
+#endif
+}
+
+void OpenGLRenderer::dirtyLayer(const float left, const float top,
+        const float right, const float bottom, const mat4 transform) {
+#if RENDER_LAYERS_AS_REGIONS
+    if ((mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region) {
+        Rect bounds(left, top, right, bottom);
+        transform.mapRect(bounds);
+        bounds.intersect(*mSnapshot->clipRect);
+        bounds.snapToPixelBoundaries();
+
+        android::Rect dirty(bounds.left, bounds.top, bounds.right, bounds.bottom);
+        if (!dirty.isEmpty()) {
+            mSnapshot->region->orSelf(dirty);
+        }
+    }
+#endif
+}
+
+void OpenGLRenderer::dirtyLayer(const float left, const float top,
+        const float right, const float bottom) {
+#if RENDER_LAYERS_AS_REGIONS
+    if ((mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region) {
+        Rect bounds(left, top, right, bottom);
+        bounds.intersect(*mSnapshot->clipRect);
+        bounds.snapToPixelBoundaries();
+
+        android::Rect dirty(bounds.left, bounds.top, bounds.right, bounds.bottom);
+        if (!dirty.isEmpty()) {
+            mSnapshot->region->orSelf(dirty);
+        }
+    }
+#endif
+}
+
 void OpenGLRenderer::setupDraw() {
     clearLayerRegions();
     if (mDirtyClip) {
@@ -551,21 +726,26 @@
 void OpenGLRenderer::clearLayerRegions() {
     if (mLayers.size() == 0 || mSnapshot->invisible) return;
 
+    Rect clipRect(*mSnapshot->clipRect);
+    clipRect.snapToPixelBoundaries();
+
     for (uint32_t i = 0; i < mLayers.size(); i++) {
         Rect* bounds = mLayers.itemAt(i);
+        if (clipRect.intersects(*bounds)) {
+            // Clear the framebuffer where the layer will draw
+            glScissor(bounds->left, mSnapshot->height - bounds->bottom,
+                    bounds->getWidth(), bounds->getHeight());
+            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+            glClear(GL_COLOR_BUFFER_BIT);
 
-        // Clear the framebuffer where the layer will draw
-        glScissor(bounds->left, mSnapshot->height - bounds->bottom,
-                bounds->getWidth(), bounds->getHeight());
-        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-        glClear(GL_COLOR_BUFFER_BIT);
+            // Restore the clip
+            dirtyClip();
+        }
 
         delete bounds;
     }
-    mLayers.clear();
 
-    // Restore the clip
-    dirtyClip();
+    mLayers.clear();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -678,7 +858,12 @@
     if (!texture) return;
     const AutoTexture autoCleanup(texture);
 
-    drawTextureRect(r.left, r.top, r.right, r.bottom, texture, paint);
+    // This could be done in a cheaper way, all we need is pass the matrix
+    // to the vertex shader. The save/restore is a bit overkill.
+    save(SkCanvas::kMatrix_SaveFlag);
+    concatMatrix(matrix);
+    drawTextureRect(0.0f, 0.0f, bitmap->width(), bitmap->height(), texture, paint);
+    restore();
 }
 
 void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
@@ -738,11 +923,21 @@
             right - left, bottom - top, xDivs, yDivs, colors, width, height, numColors);
 
     if (mesh) {
-        // Specify right and bottom as +1.0f from left/top to prevent scaling since the
-        // patch mesh already defines the final size
-        drawTextureMesh(left, top, left + 1.0f, top + 1.0f, texture->id, alpha / 255.0f,
+        // Mark the current layer dirty where we are going to draw the patch
+        if ((mSnapshot->flags & Snapshot::kFlagFboTarget) &&
+                mSnapshot->region && mesh->hasEmptyQuads) {
+            const size_t count = mesh->quads.size();
+            for (size_t i = 0; i < count; i++) {
+                Rect bounds = mesh->quads.itemAt(i);
+                dirtyLayer(bounds.left, bounds.top, bounds.right, bounds.bottom,
+                        *mSnapshot->transform);
+            }
+        }
+
+        drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f,
                 mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset,
-                GL_TRIANGLES, mesh->verticesCount, false, false, mesh->meshBuffer);
+                GL_TRIANGLES, mesh->verticesCount, false, false, mesh->meshBuffer,
+                true, !mesh->hasEmptyQuads);
     }
 }
 
@@ -801,6 +996,7 @@
             mModelView.scale(length, strokeWidth, 1.0f);
         }
         mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
+        // TODO: Add bounds to the layer's region
 
         if (mShader) {
             mShader->updateTransforms(mCaches.currentProgram, mModelView, *mSnapshot);
@@ -904,13 +1100,34 @@
 
     // Assume that the modelView matrix does not force scales, rotates, etc.
     const bool linearFilter = mSnapshot->transform->changesBounds();
+
+    // Dimensions are set to (0,0), the layer (if any) won't be dirtied
     setupTextureAlpha8(fontRenderer.getTexture(linearFilter), 0, 0, textureUnit,
             x, y, r, g, b, a, mode, false, true, NULL, NULL);
 
     const Rect& clip = mSnapshot->getLocalClip();
+    Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f);
+
+#if RENDER_LAYERS_AS_REGIONS
+    bool hasLayer = (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
+#else
+    bool hasLayer = false;
+#endif
 
     mCaches.unbindMeshBuffer();
-    fontRenderer.renderText(paint, &clip, text, 0, bytesCount, count, x, y);
+    if (fontRenderer.renderText(paint, &clip, text, 0, bytesCount, count, x, y,
+            hasLayer ? &bounds : NULL)) {
+#if RENDER_LAYERS_AS_REGIONS
+        if (hasLayer) {
+            mSnapshot->transform->mapRect(bounds);
+            bounds.intersect(*mSnapshot->clipRect);
+            bounds.snapToPixelBoundaries();
+
+            android::Rect dirty(bounds.left, bounds.top, bounds.right, bounds.bottom);
+            mSnapshot->region->orSelf(dirty);
+        }
+#endif
+    }
 
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
     glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
@@ -1081,7 +1298,12 @@
      } else {
          mModelView.loadIdentity();
      }
+
      mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
+     if (width > 0 && height > 0) {
+         dirtyLayer(x, y, x + width, y + height, *mSnapshot->transform);
+     }
+
      if (setColor) {
          mCaches.currentProgram->setColor(r, g, b, a);
      }
@@ -1214,9 +1436,11 @@
     mModelView.scale(right - left, bottom - top, 1.0f);
     if (!ignoreTransform) {
         mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
+        dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
     } else {
         mat4 identity;
         mCaches.currentProgram->set(mOrthoMatrix, mModelView, identity);
+        dirtyLayer(left, top, right, bottom);
     }
     mCaches.currentProgram->setColor(r, g, b, a);
 
@@ -1251,7 +1475,7 @@
 void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom,
         GLuint texture, float alpha, SkXfermode::Mode mode, bool blend,
         GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
-        bool swapSrcDst, bool ignoreTransform, GLuint vbo) {
+        bool swapSrcDst, bool ignoreTransform, GLuint vbo, bool ignoreScale, bool dirty) {
     setupDraw();
 
     ProgramDescription description;
@@ -1262,16 +1486,20 @@
     }
 
     mModelView.loadTranslate(left, top, 0.0f);
-    mModelView.scale(right - left, bottom - top, 1.0f);
+    if (!ignoreScale) {
+        mModelView.scale(right - left, bottom - top, 1.0f);
+    }
 
     chooseBlending(blend || alpha < 1.0f, mode, description, swapSrcDst);
 
     useProgram(mCaches.programCache.get(description));
     if (!ignoreTransform) {
         mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
+        if (dirty) dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
     } else {
-        mat4 m;
-        mCaches.currentProgram->set(mOrthoMatrix, mModelView, m);
+        mat4 identity;
+        mCaches.currentProgram->set(mOrthoMatrix, mModelView, identity);
+        if (dirty) dirtyLayer(left, top, right, bottom);
     }
 
     // Texture
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 3492d2c..2d612d4 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_OPENGL_RENDERER_H
-#define ANDROID_UI_OPENGL_RENDERER_H
+#ifndef ANDROID_HWUI_OPENGL_RENDERER_H
+#define ANDROID_HWUI_OPENGL_RENDERER_H
 
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
@@ -50,6 +50,10 @@
 // Debug
 #define DEBUG_OPENGL 1
 
+// If turned on, layers drawn inside FBOs are optimized with regions
+#define RENDER_LAYERS_AS_REGIONS 0
+#define DEBUG_LAYERS_AS_REGIONS 0
+
 ///////////////////////////////////////////////////////////////////////////////
 // Renderer
 ///////////////////////////////////////////////////////////////////////////////
@@ -176,6 +180,34 @@
             int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
 
     /**
+     * Creates a new layer stored in the specified snapshot as an FBO.
+     *
+     * @param layer The layer to store as an FBO
+     * @param snapshot The snapshot associated with the new layer
+     * @param bounds The bounds of the layer
+     * @param previousFbo The name of the current framebuffer
+     */
+    bool createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
+            GLuint previousFbo);
+
+    /**
+     * Compose the specified layer as a region.
+     *
+     * @param layer The layer to compose
+     * @param rect The layer's bounds
+     */
+    void composeLayerRegion(Layer* layer, const Rect& rect);
+
+    /**
+     * Compose the specified layer as a simple rectangle.
+     *
+     * @param layer The layer to compose
+     * @param rect The layer's bounds
+     * @param swap If true, the source and destination are swapped
+     */
+    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
+
+    /**
      * Clears all the regions corresponding to the current list of layers.
      * This method MUST be invoked before any drawing operation.
      */
@@ -192,7 +224,7 @@
      * @param color The rectangle's ARGB color, defined as a packed 32 bits word
      * @param mode The Skia xfermode to use
      * @param ignoreTransform True if the current transform should be ignored
-     * @paran ignoreBlending True if the blending is set by the caller
+     * @param ignoreBlending True if the blending is set by the caller
      */
     void drawColorRect(float left, float top, float right, float bottom,
             int color, SkXfermode::Mode mode, bool ignoreTransform = false);
@@ -252,11 +284,14 @@
      * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
      * @param ignoreTransform True if the current transform should be ignored
      * @param vbo The VBO used to draw the mesh
+     * @param ignoreScale True if the model view matrix should not be scaled
+     * @param dirty True if calling this method should dirty the current layer
      */
     void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
             float alpha, SkXfermode::Mode mode, bool blend,
             GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
-            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0);
+            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
+            bool ignoreScale = false, bool dirty = true);
 
     /**
      * Prepares the renderer to draw the specified shadow. The active texture
@@ -411,6 +446,18 @@
         mDirtyClip = true;
     }
 
+    /**
+     * Mark the layer as dirty at the specified coordinates. The coordinates
+     * are transformed with the supplied matrix.
+     */
+    void dirtyLayer(const float left, const float top, const float right, const float bottom,
+            const mat4 transform);
+
+    /**
+     * Mark the layer as dirty at the specified coordinates.
+     */
+    void dirtyLayer(const float left, const float top, const float right, const float bottom);
+
     // Dimensions of the drawing surface
     int mWidth, mHeight;
 
@@ -462,4 +509,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_OPENGL_RENDERER_H
+#endif // ANDROID_HWUI_OPENGL_RENDERER_H
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index 3d21431..9b2d476 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -34,6 +34,7 @@
     // 2 triangles per patch, 3 vertices per triangle
     verticesCount = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3;
     mVertices = new TextureVertex[verticesCount];
+    hasEmptyQuads = emptyQuads > 0;
 
     glGenBuffers(1, &meshBuffer);
 }
@@ -51,6 +52,8 @@
         float left, float top, float right, float bottom,
         const int32_t* xDivs, const int32_t* yDivs,
         const uint32_t width, const uint32_t height, const uint32_t colorKey) {
+    if (hasEmptyQuads) quads.clear();
+
     const uint32_t xStretchCount = (width + 1) >> 1;
     const uint32_t yStretchCount = (height + 1) >> 1;
 
@@ -118,7 +121,7 @@
                 mVertices, GL_STATIC_DRAW);
 }
 
-inline void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, float v2,
+void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, float v2,
         const int32_t xDivs[], uint32_t xCount, float stretchX, float width, float bitmapWidth,
         uint32_t& quadCount, const uint32_t colorKey) {
     float previousStepX = 0.0f;
@@ -150,12 +153,17 @@
     generateQuad(vertex, x1, y1, width, y2, u1, v1, 1.0f, v2, quadCount, colorKey);
 }
 
-inline void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
+void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
             float u1, float v1, float u2, float v2, uint32_t& quadCount, const uint32_t colorKey) {
     if (((colorKey >> quadCount++) & 0x1) == 1) {
         return;
     }
 
+    if (hasEmptyQuads) {
+        Rect bounds(x1, y1, x2, y2);
+        quads.add(bounds);
+    }
+
     // Left triangle
     TextureVertex::set(vertex++, x1, y1, u1, v1);
     TextureVertex::set(vertex++, x2, y1, u2, v1);
diff --git a/libs/hwui/Patch.h b/libs/hwui/Patch.h
index ce898937..1e78b2f 100644
--- a/libs/hwui/Patch.h
+++ b/libs/hwui/Patch.h
@@ -14,13 +14,16 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_PATCH_H
-#define ANDROID_UI_PATCH_H
+#ifndef ANDROID_HWUI_PATCH_H
+#define ANDROID_HWUI_PATCH_H
 
 #include <sys/types.h>
 
 #include <GLES2/gl2.h>
 
+#include <utils/Vector.h>
+
+#include "Rect.h"
 #include "Vertex.h"
 #include "utils/Compare.h"
 
@@ -96,15 +99,17 @@
 
     GLuint meshBuffer;
     uint32_t verticesCount;
+    Vector<Rect> quads;
+    bool hasEmptyQuads;
 
 private:
     TextureVertex* mVertices;
 
-    static inline void generateRow(TextureVertex*& vertex, float y1, float y2,
+    void generateRow(TextureVertex*& vertex, float y1, float y2,
             float v1, float v2, const int32_t xDivs[], uint32_t xCount,
             float stretchX, float width, float bitmapWidth,
             uint32_t& quadCount, const uint32_t colorKey);
-    static inline void generateQuad(TextureVertex*& vertex,
+    void generateQuad(TextureVertex*& vertex,
             float x1, float y1, float x2, float y2,
             float u1, float v1, float u2, float v2,
             uint32_t& quadCount, const uint32_t colorKey);
@@ -113,4 +118,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_PATCH_H
+#endif // ANDROID_HWUI_PATCH_H
diff --git a/libs/hwui/PatchCache.h b/libs/hwui/PatchCache.h
index f4eeb09..deba40d 100644
--- a/libs/hwui/PatchCache.h
+++ b/libs/hwui/PatchCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_PATCH_CACHE_H
-#define ANDROID_UI_PATCH_CACHE_H
+#ifndef ANDROID_HWUI_PATCH_CACHE_H
+#define ANDROID_HWUI_PATCH_CACHE_H
 
 #include <utils/KeyedVector.h>
 
@@ -62,4 +62,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_PATCH_CACHE_H
+#endif // ANDROID_HWUI_PATCH_CACHE_H
diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h
index 9a5fc45..db5ce08 100644
--- a/libs/hwui/PathCache.h
+++ b/libs/hwui/PathCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_PATH_CACHE_H
-#define ANDROID_UI_PATH_CACHE_H
+#ifndef ANDROID_HWUI_PATH_CACHE_H
+#define ANDROID_HWUI_PATH_CACHE_H
 
 #include <SkBitmap.h>
 #include <SkPaint.h>
@@ -170,4 +170,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_PATH_CACHE_H
+#endif // ANDROID_HWUI_PATH_CACHE_H
diff --git a/libs/hwui/Program.cpp b/libs/hwui/Program.cpp
index 25674c6..baed5fd7 100644
--- a/libs/hwui/Program.cpp
+++ b/libs/hwui/Program.cpp
@@ -22,12 +22,6 @@
 namespace uirenderer {
 
 ///////////////////////////////////////////////////////////////////////////////
-// Shaders
-///////////////////////////////////////////////////////////////////////////////
-
-#define SHADER_SOURCE(name, source) const char* name = #source
-
-///////////////////////////////////////////////////////////////////////////////
 // Base program
 ///////////////////////////////////////////////////////////////////////////////
 
diff --git a/libs/hwui/Program.h b/libs/hwui/Program.h
index 026097c..5981662 100644
--- a/libs/hwui/Program.h
+++ b/libs/hwui/Program.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_PROGRAM_H
-#define ANDROID_UI_PROGRAM_H
+#ifndef ANDROID_HWUI_PROGRAM_H
+#define ANDROID_HWUI_PROGRAM_H
 
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
@@ -131,4 +131,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_PROGRAM_H
+#endif // ANDROID_HWUI_PROGRAM_H
diff --git a/libs/hwui/ProgramCache.h b/libs/hwui/ProgramCache.h
index 9cb13b3..186e869 100644
--- a/libs/hwui/ProgramCache.h
+++ b/libs/hwui/ProgramCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_PROGRAM_CACHE_H
-#define ANDROID_UI_PROGRAM_CACHE_H
+#ifndef ANDROID_HWUI_PROGRAM_CACHE_H
+#define ANDROID_HWUI_PROGRAM_CACHE_H
 
 #include <utils/KeyedVector.h>
 #include <utils/Log.h>
@@ -258,4 +258,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_PROGRAM_CACHE_H
+#endif // ANDROID_HWUI_PROGRAM_CACHE_H
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index db3cb4d..813392b 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_PROPERTIES_H
-#define ANDROID_UI_PROPERTIES_H
+#ifndef ANDROID_HWUI_PROPERTIES_H
+#define ANDROID_HWUI_PROPERTIES_H
 
 #include <cutils/properties.h>
 
@@ -45,15 +45,15 @@
 #define MB(s) s * 1024 * 1024
 
 #define DEFAULT_TEXTURE_CACHE_SIZE 20.0f
-#define DEFAULT_LAYER_CACHE_SIZE 6.0f
+#define DEFAULT_LAYER_CACHE_SIZE 8.0f
 #define DEFAULT_PATH_CACHE_SIZE 4.0f
 #define DEFAULT_PATCH_CACHE_SIZE 512
 #define DEFAULT_GRADIENT_CACHE_SIZE 0.5f
 #define DEFAULT_DROP_SHADOW_CACHE_SIZE 2.0f
-#define DEFAULT_FBO_CACHE_SIZE 25
+#define DEFAULT_FBO_CACHE_SIZE 12
 
 #define DEFAULT_TEXT_GAMMA 1.4f
 #define DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD 64
 #define DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD 192
 
-#endif // ANDROID_UI_PROPERTIES_H
+#endif // ANDROID_HWUI_PROPERTIES_H
diff --git a/libs/hwui/Rect.h b/libs/hwui/Rect.h
index 8f3655c..71951b7 100644
--- a/libs/hwui/Rect.h
+++ b/libs/hwui/Rect.h
@@ -14,8 +14,10 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_RECT_H
-#define ANDROID_UI_RECT_H
+#ifndef ANDROID_HWUI_RECT_H
+#define ANDROID_HWUI_RECT_H
+
+#include <cmath>
 
 #include <utils/Log.h>
 
@@ -32,25 +34,35 @@
     float right;
     float bottom;
 
-    Rect():
+    // Used by Region
+    typedef float value_type;
+
+    inline Rect():
             left(0),
             top(0),
             right(0),
             bottom(0) {
     }
 
-    Rect(float left, float top, float right, float bottom):
+    inline Rect(float left, float top, float right, float bottom):
             left(left),
             top(top),
             right(right),
             bottom(bottom) {
     }
 
-    Rect(const Rect& r) {
+    inline Rect(float width, float height):
+            left(0.0f),
+            top(0.0f),
+            right(width),
+            bottom(height) {
+    }
+
+    inline Rect(const Rect& r) {
         set(r);
     }
 
-    Rect(Rect& r) {
+    inline Rect(Rect& r) {
         set(r);
     }
 
@@ -72,22 +84,26 @@
         return memcmp(&a, &b, sizeof(a));
     }
 
-    bool isEmpty() const {
+    inline void clear() {
+        left = top = right = bottom = 0.0f;
+    }
+
+    inline bool isEmpty() const {
         return left >= right || top >= bottom;
     }
 
-    void setEmpty() {
-        memset(this, 0, sizeof(*this));
+    inline void setEmpty() {
+        left = top = right = bottom = 0.0f;
     }
 
-    void set(float left, float top, float right, float bottom) {
+    inline void set(float left, float top, float right, float bottom) {
         this->left = left;
         this->right = right;
         this->top = top;
         this->bottom = bottom;
     }
 
-    void set(const Rect& r) {
+    inline void set(const Rect& r) {
         set(r.left, r.top, r.right, r.bottom);
     }
 
@@ -148,6 +164,13 @@
         return false;
     }
 
+    void translate(float dx, float dy) {
+        left += dx;
+        right += dx;
+        top += dy;
+        bottom += dy;
+    }
+
     void snapToPixelBoundaries() {
         left = floorf(left + 0.5f);
         top = floorf(top + 0.5f);
@@ -164,4 +187,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_RECT_H
+#endif // ANDROID_HWUI_RECT_H
diff --git a/libs/hwui/ResourceCache.h b/libs/hwui/ResourceCache.h
index d9b3718..2256fd1 100644
--- a/libs/hwui/ResourceCache.h
+++ b/libs/hwui/ResourceCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_RESOURCE_CACHE_H
-#define ANDROID_UI_RESOURCE_CACHE_H
+#ifndef ANDROID_HWUI_RESOURCE_CACHE_H
+#define ANDROID_HWUI_RESOURCE_CACHE_H
 
 #include <SkBitmap.h>
 #include <SkiaColorFilter.h>
@@ -75,4 +75,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_RESOURCE_CACHE_H
+#endif // ANDROID_HWUI_RESOURCE_CACHE_H
diff --git a/libs/hwui/SkiaColorFilter.h b/libs/hwui/SkiaColorFilter.h
index 17f49f9..bf45e13 100644
--- a/libs/hwui/SkiaColorFilter.h
+++ b/libs/hwui/SkiaColorFilter.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_SKIA_COLOR_FILTER_H
-#define ANDROID_UI_SKIA_COLOR_FILTER_H
+#ifndef ANDROID_HWUI_SKIA_COLOR_FILTER_H
+#define ANDROID_HWUI_SKIA_COLOR_FILTER_H
 
 #include <GLES2/gl2.h>
 #include <SkColorFilter.h>
@@ -123,4 +123,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_SKIA_COLOR_FILTER_H
+#endif // ANDROID_HWUI_SKIA_COLOR_FILTER_H
diff --git a/libs/hwui/SkiaShader.h b/libs/hwui/SkiaShader.h
index 4cd1b8b..1d884ab 100644
--- a/libs/hwui/SkiaShader.h
+++ b/libs/hwui/SkiaShader.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_SKIA_SHADER_H
-#define ANDROID_UI_SKIA_SHADER_H
+#ifndef ANDROID_HWUI_SKIA_SHADER_H
+#define ANDROID_HWUI_SKIA_SHADER_H
 
 #include <SkShader.h>
 #include <SkXfermode.h>
@@ -216,4 +216,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_SKIA_SHADER_H
+#endif // ANDROID_HWUI_SKIA_SHADER_H
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index 2da1950..9f78063 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -14,16 +14,16 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_SNAPSHOT_H
-#define ANDROID_UI_SNAPSHOT_H
+#ifndef ANDROID_HWUI_SNAPSHOT_H
+#define ANDROID_HWUI_SNAPSHOT_H
 
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
 #include <utils/RefBase.h>
+#include <ui/Region.h>
 
 #include <SkCanvas.h>
-#include <SkRegion.h>
 
 #include "Layer.h"
 #include "Matrix.h"
@@ -46,6 +46,7 @@
     Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false) {
         transform = &mTransformRoot;
         clipRect = &mClipRectRoot;
+        region = NULL;
     }
 
     /**
@@ -75,6 +76,13 @@
         } else {
             flags |= Snapshot::kFlagDirtyLocalClip;
         }
+
+        if (s->flags & Snapshot::kFlagFboTarget) {
+            flags |= Snapshot::kFlagFboTarget;
+            region = s->region;
+        } else {
+            region = NULL;
+        }
     }
 
     /**
@@ -105,6 +113,11 @@
          * Indicates that this snapshot has changed the ortho matrix.
          */
         kFlagDirtyOrtho = 0x10,
+        /**
+         * Indicates that this snapshot or an ancestor snapshot is
+         * an FBO layer.
+         */
+        kFlagFboTarget = 0x20
     };
 
     /**
@@ -243,6 +256,11 @@
      */
     Rect* clipRect;
 
+    /**
+     * The ancestor layer's dirty region..
+     */
+    Region* region;
+
 private:
     mat4 mTransformRoot;
     Rect mClipRectRoot;
@@ -253,4 +271,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_SNAPSHOT_H
+#endif // ANDROID_HWUI_SNAPSHOT_H
diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h
index 16e2814..adf09e2 100644
--- a/libs/hwui/TextDropShadowCache.h
+++ b/libs/hwui/TextDropShadowCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_TEXT_DROP_SHADOW_CACHE_H
-#define ANDROID_UI_TEXT_DROP_SHADOW_CACHE_H
+#ifndef ANDROID_HWUI_TEXT_DROP_SHADOW_CACHE_H
+#define ANDROID_HWUI_TEXT_DROP_SHADOW_CACHE_H
 
 #include <GLES2/gl2.h>
 
@@ -148,4 +148,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_TEXT_DROP_SHADOW_CACHE_H
+#endif // ANDROID_HWUI_TEXT_DROP_SHADOW_CACHE_H
diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h
index 755074d..4922bb3 100644
--- a/libs/hwui/Texture.h
+++ b/libs/hwui/Texture.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_TEXTURE_H
-#define ANDROID_UI_TEXTURE_H
+#ifndef ANDROID_HWUI_TEXTURE_H
+#define ANDROID_HWUI_TEXTURE_H
 
 #include <GLES2/gl2.h>
 
@@ -86,4 +86,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_TEXTURE_H
+#endif // ANDROID_HWUI_TEXTURE_H
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index d860953..0c7948f 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -200,9 +200,13 @@
         texture->blend = !bitmap->isOpaque();
         break;
     case SkBitmap::kIndex8_Config:
-        uploadPalettedTexture(resize, bitmap, texture->width, texture->height);
+        uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
         texture->blend = false;
         break;
+    case SkBitmap::kARGB_4444_Config:
+        uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
+        texture->blend = true;
+        break;
     default:
         LOGW("Unsupported bitmap config: %d", bitmap->getConfig());
         break;
@@ -215,7 +219,7 @@
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 }
 
-void TextureCache::uploadPalettedTexture(bool resize, SkBitmap* bitmap,
+void TextureCache::uploadLoFiTexture(bool resize, SkBitmap* bitmap,
         uint32_t width, uint32_t height) {
     SkBitmap rgbaBitmap;
     rgbaBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h
index 6718597..d9d2387 100644
--- a/libs/hwui/TextureCache.h
+++ b/libs/hwui/TextureCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_TEXTURE_CACHE_H
-#define ANDROID_UI_TEXTURE_CACHE_H
+#ifndef ANDROID_HWUI_TEXTURE_CACHE_H
+#define ANDROID_HWUI_TEXTURE_CACHE_H
 
 #include <SkBitmap.h>
 
@@ -93,7 +93,7 @@
      */
     void generateTexture(SkBitmap* bitmap, Texture* texture, bool regenerate = false);
 
-    void uploadPalettedTexture(bool resize, SkBitmap* bitmap, uint32_t width, uint32_t height);
+    void uploadLoFiTexture(bool resize, SkBitmap* bitmap, uint32_t width, uint32_t height);
     void uploadToTexture(bool resize, GLenum format, GLsizei width, GLsizei height,
             GLenum type, const GLvoid * data);
 
@@ -115,4 +115,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_TEXTURE_CACHE_H
+#endif // ANDROID_HWUI_TEXTURE_CACHE_H
diff --git a/libs/hwui/Vertex.h b/libs/hwui/Vertex.h
index 1f54086..bbf4d4a 100644
--- a/libs/hwui/Vertex.h
+++ b/libs/hwui/Vertex.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_VERTEX_H
-#define ANDROID_UI_VERTEX_H
+#ifndef ANDROID_HWUI_VERTEX_H
+#define ANDROID_HWUI_VERTEX_H
 
 namespace android {
 namespace uirenderer {
@@ -43,4 +43,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_VERTEX_H
+#endif // ANDROID_HWUI_VERTEX_H
diff --git a/libs/hwui/utils/Compare.h b/libs/hwui/utils/Compare.h
index 5ea0fc9..6531e78 100644
--- a/libs/hwui/utils/Compare.h
+++ b/libs/hwui/utils/Compare.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_COMPARE_H
-#define ANDROID_UI_COMPARE_H
+#ifndef ANDROID_HWUI_COMPARE_H
+#define ANDROID_HWUI_COMPARE_H
 
 #include <cmath>
 
@@ -37,4 +37,4 @@
     if (a < rhs.a) return true; \
     if (a == rhs.a)
 
-#endif // ANDROID_UI_COMPARE_H
+#endif // ANDROID_HWUI_COMPARE_H
diff --git a/libs/hwui/utils/GenerationCache.h b/libs/hwui/utils/GenerationCache.h
index 5cea30f..2e76236 100644
--- a/libs/hwui/utils/GenerationCache.h
+++ b/libs/hwui/utils/GenerationCache.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_GENERATION_CACHE_H
-#define ANDROID_UI_GENERATION_CACHE_H
+#ifndef ANDROID_HWUI_GENERATION_CACHE_H
+#define ANDROID_HWUI_GENERATION_CACHE_H
 
 #include <utils/KeyedVector.h>
 #include <utils/RefBase.h>
@@ -242,4 +242,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_GENERATION_CACHE_H
+#endif // ANDROID_HWUI_GENERATION_CACHE_H
diff --git a/libs/hwui/utils/SortedList.h b/libs/hwui/utils/SortedList.h
index 68f5e9d..2fa890a 100644
--- a/libs/hwui/utils/SortedList.h
+++ b/libs/hwui/utils/SortedList.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_SORTED_LIST_H
-#define ANDROID_UI_SORTED_LIST_H
+#ifndef ANDROID_HWUI_SORTED_LIST_H
+#define ANDROID_HWUI_SORTED_LIST_H
 
 #include <stdint.h>
 #include <sys/types.h>
@@ -239,4 +239,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_SORTED_LIST_H
+#endif // ANDROID_HWUI_SORTED_LIST_H
diff --git a/libs/hwui/utils/SortedListImpl.h b/libs/hwui/utils/SortedListImpl.h
index 7da09ef..dc385b5 100644
--- a/libs/hwui/utils/SortedListImpl.h
+++ b/libs/hwui/utils/SortedListImpl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_UI_SORTED_LIST_IMPL_H
-#define ANDROID_UI_SORTED_LIST_IMPL_H
+#ifndef ANDROID_HWUI_SORTED_LIST_IMPL_H
+#define ANDROID_HWUI_SORTED_LIST_IMPL_H
 
 #include <utils/VectorImpl.h>
 
@@ -62,4 +62,4 @@
 }; // namespace uirenderer
 }; // namespace android
 
-#endif // ANDROID_UI_SORTED_LIST_IMPL_H
+#endif // ANDROID_HWUI_SORTED_LIST_IMPL_H
diff --git a/libs/rs/java/Balls/src/com/android/balls/balls.rs b/libs/rs/java/Balls/src/com/android/balls/balls.rs
index 9d3f30b..493633b 100644
--- a/libs/rs/java/Balls/src/com/android/balls/balls.rs
+++ b/libs/rs/java/Balls/src/com/android/balls/balls.rs
@@ -56,16 +56,16 @@
 int root() {
     rsgClearColor(0.f, 0.f, 0.f, 1.f);
 
-    BallControl_t bc;
+    BallControl_t bc = {0};
     Ball_t *bout;
 
     if (frame & 1) {
-        bc.ain = rsGetAllocation(balls2);
-        bc.aout = rsGetAllocation(balls1);
+        rsSetObject(&bc.ain, rsGetAllocation(balls2));
+        rsSetObject(&bc.aout, rsGetAllocation(balls1));
         bout = balls2;
     } else {
-        bc.ain = rsGetAllocation(balls1);
-        bc.aout = rsGetAllocation(balls2);
+        rsSetObject(&bc.ain, rsGetAllocation(balls1));
+        rsSetObject(&bc.aout, rsGetAllocation(balls2));
         bout = balls1;
     }
 
@@ -99,6 +99,8 @@
     rsgBindProgramStore(gPS);
     rsgDrawMesh(arcMesh, 0, 0, arcIdx);
     rsgDrawMesh(partMesh);
+    rsClearObject(&bc.ain);
+    rsClearObject(&bc.aout);
     return 1;
 }
 
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/threshold.rs b/libs/rs/java/ImageProcessing/src/com/android/rs/image/threshold.rs
index 4f46810..d05ed6f 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/threshold.rs
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/threshold.rs
@@ -64,7 +64,8 @@
 
 
 static void copyInput() {
-    rs_allocation ain = rsGetAllocation(InPixel);
+    rs_allocation ain = {0};
+    rsSetObject(&ain,rsGetAllocation(InPixel));
     uint32_t dimx = rsAllocationGetDimX(ain);
     uint32_t dimy = rsAllocationGetDimY(ain);
     for(uint32_t y = 0; y < dimy; y++) {
@@ -72,6 +73,7 @@
             ScratchPixel1[x + y * dimx] = convert_float4(InPixel[x + y * dimx]);
         }
     }
+    rsClearObject(&ain);
 }
 
 void filter() {
diff --git a/libs/rs/java/Samples/src/com/android/samples/rslist.rs b/libs/rs/java/Samples/src/com/android/samples/rslist.rs
index f760ad0..01b37ab 100644
--- a/libs/rs/java/Samples/src/com/android/samples/rslist.rs
+++ b/libs/rs/java/Samples/src/com/android/samples/rslist.rs
@@ -46,7 +46,8 @@
     rsgBindFont(gItalic);
     color(0.2, 0.2, 0.2, 0);
 
-    rs_allocation listAlloc = rsGetAllocation(gList);
+    rs_allocation listAlloc = {0};
+    rsSetObject(&listAlloc, rsGetAllocation(gList));
     int allocSize = rsAllocationGetDimX(listAlloc);
 
     int width = rsgGetWidth();
@@ -66,6 +67,7 @@
         }
         currentYPos += itemHeight;
     }
+    rsClearObject(&listAlloc);
 
     return 10;
 }
diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
index 789fa4d..acce886 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
@@ -63,6 +63,7 @@
 
         unitTests.add(new UT_primitives(this, mRes));
         unitTests.add(new UT_rsdebug(this, mRes));
+        unitTests.add(new UT_rstypes(this, mRes));
         unitTests.add(new UT_fp_mad(this, mRes));
         /*
         unitTests.add(new UnitTest(null, "<Pass>", 1));
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java b/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java
new file mode 100644
index 0000000..55f3746
--- /dev/null
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.android.rs.test;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+
+public class UT_rstypes extends UnitTest {
+    private Resources mRes;
+
+    protected UT_rstypes(RSTestCore rstc, Resources res) {
+        super(rstc, "rsTypes");
+        mRes = res;
+    }
+
+    public void run() {
+        RenderScript pRS = RenderScript.create();
+        ScriptC_rstypes s = new ScriptC_rstypes(pRS, mRes, R.raw.rstypes, true);
+        pRS.mMessageCallback = mRsMessage;
+        s.invoke_test_rstypes(0, 0);
+        pRS.finish();
+        waitForMessage();
+        pRS.destroy();
+    }
+}
+
diff --git a/libs/rs/java/tests/src/com/android/rs/test/rslist.rs b/libs/rs/java/tests/src/com/android/rs/test/rslist.rs
index b2d06fe..d1fde57 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/rslist.rs
+++ b/libs/rs/java/tests/src/com/android/rs/test/rslist.rs
@@ -47,7 +47,8 @@
     rsgBindFont(gFont);
     color(0.2, 0.2, 0.2, 0);
 
-    rs_allocation listAlloc = rsGetAllocation(gList);
+    rs_allocation listAlloc = {0};
+    rsSetObject(&listAlloc, rsGetAllocation(gList));
     int allocSize = rsAllocationGetDimX(listAlloc);
 
     int width = rsgGetWidth();
@@ -102,6 +103,7 @@
         }
         currentYPos += itemHeight;
     }
+    rsClearObject(&listAlloc);
 
     return 10;
 }
diff --git a/libs/rs/java/tests/src/com/android/rs/test/rstypes.rs b/libs/rs/java/tests/src/com/android/rs/test/rstypes.rs
new file mode 100644
index 0000000..cb0c577
--- /dev/null
+++ b/libs/rs/java/tests/src/com/android/rs/test/rstypes.rs
@@ -0,0 +1,81 @@
+#include "shared.rsh"
+#include "rs_graphics.rsh"
+
+#pragma rs export_func(test_rstypes)
+
+rs_element elementTest;
+rs_type typeTest;
+rs_allocation allocationTest;
+rs_sampler samplerTest;
+rs_script scriptTest;
+rs_mesh meshTest;
+rs_program_fragment program_fragmentTest;
+rs_program_vertex program_vertexTest;
+rs_program_raster program_rasterTest;
+rs_program_store program_storeTest;
+rs_font fontTest;
+
+rs_matrix4x4 matrix4x4Test;
+rs_matrix3x3 matrix3x3Test;
+rs_matrix2x2 matrix2x2Test;
+
+struct my_struct {
+    int i;
+    rs_font fontTestStruct;
+};
+
+static bool basic_test(uint32_t index) {
+    bool failed = false;
+
+    rs_matrix4x4 matrix4x4TestLocal;
+    rs_matrix3x3 matrix3x3TestLocal;
+    rs_matrix2x2 matrix2x2TestLocal;
+
+    // This test focuses primarily on compilation-time, not run-time.
+    rs_element elementTestLocal;
+    rs_type typeTestLocal;
+    rs_allocation allocationTestLocal;
+    rs_sampler samplerTestLocal;
+    rs_script scriptTestLocal;
+    rs_mesh meshTestLocal;
+    rs_program_fragment program_fragmentTestLocal;
+    rs_program_vertex program_vertexTestLocal;
+    rs_program_raster program_rasterTestLocal;
+    rs_program_store program_storeTestLocal;
+    rs_font fontTestLocal;
+
+    rs_font fontTestLocalArray[4];
+
+    rs_font fontTestLocalPreInit = fontTest;
+
+    struct my_struct structTest;
+
+    rsSetObject(&fontTestLocal, fontTest);
+    //allocationTestLocal = allocationTest;
+
+    rsSetObject(&fontTest, fontTestLocal);
+    //allocationTest = allocationTestLocal;
+
+    /*for (int i = 0; i < 4; i++) {
+        rsSetObject(&fontTestLocalArray[i], fontTestLocal);
+    }*/
+
+    /*rsSetObject(&fontTest, fontTestLocalArray[3]);*/
+
+    return failed;
+}
+
+void test_rstypes(uint32_t index, int test_num) {
+    bool failed = false;
+    failed |= basic_test(index);
+
+    if (failed) {
+        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+        rsDebug("rstypes_test FAILED", -1);
+    }
+    else {
+        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+        rsDebug("rstypes_test PASSED", 0);
+    }
+}
+
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 0241455..678d327 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -107,7 +107,7 @@
 }
 
 
-void Context::initGLThread()
+bool Context::initGLThread()
 {
     pthread_mutex_lock(&gInitMutex);
     LOGV("initGLThread start %p", this);
@@ -169,7 +169,9 @@
     mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2);
     checkEglError("eglCreateContext");
     if (mEGL.mContext == EGL_NO_CONTEXT) {
+        pthread_mutex_unlock(&gInitMutex);
         LOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", this);
+        return false;
     }
     gGLContextCount++;
 
@@ -179,10 +181,19 @@
     checkEglError("eglCreatePbufferSurface");
     if (mEGL.mSurfaceDefault == EGL_NO_SURFACE) {
         LOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
+        pthread_mutex_unlock(&gInitMutex);
+        deinitEGL();
+        return false;
     }
 
     EGLBoolean ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurfaceDefault, mEGL.mSurfaceDefault, mEGL.mContext);
-    checkEglError("eglMakeCurrent", ret);
+    if (ret == EGL_FALSE) {
+        LOGE("eglMakeCurrent returned EGL_FALSE");
+        checkEglError("eglMakeCurrent", ret);
+        pthread_mutex_unlock(&gInitMutex);
+        deinitEGL();
+        return false;
+    }
 
     mGL.mVersion = glGetString(GL_VERSION);
     mGL.mVendor = glGetString(GL_VENDOR);
@@ -207,6 +218,9 @@
 
     if (!verptr) {
         LOGE("Error, OpenGL ES Lite not supported");
+        pthread_mutex_unlock(&gInitMutex);
+        deinitEGL();
+        return false;
     } else {
         sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
     }
@@ -231,15 +245,18 @@
 
     LOGV("initGLThread end %p", this);
     pthread_mutex_unlock(&gInitMutex);
+    return true;
 }
 
 void Context::deinitEGL()
 {
     LOGV("%p, deinitEGL", this);
 
-    eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, mEGL.mContext);
-    eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
-    checkEglError("eglDestroyContext");
+    if (mEGL.mContext != EGL_NO_CONTEXT) {
+        eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, mEGL.mContext);
+        eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
+        checkEglError("eglDestroyContext");
+    }
 
     gGLContextCount--;
     if (!gGLContextCount) {
@@ -421,6 +438,7 @@
      rsc->mTlsStruct = new ScriptTLSStruct;
      if (!rsc->mTlsStruct) {
          LOGE("Error allocating tls storage");
+         rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed allocation for TLS");
          return NULL;
      }
      rsc->mTlsStruct->mContext = rsc;
@@ -430,7 +448,10 @@
          LOGE("pthread_setspecific %i", status);
      }
 
-     rsc->initGLThread();
+     if (!rsc->initGLThread()) {
+         rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL");
+         return NULL;
+     }
 
      rsc->mScriptC.init(rsc);
      if (rsc->mIsGraphicsContext) {
@@ -580,18 +601,33 @@
 #endif
 }
 
-Context::Context(Device *dev, const RsSurfaceConfig *sc)
+Context::Context()
 {
-    pthread_mutex_lock(&gInitMutex);
-
-    dev->addContext(this);
-    mDev = dev;
+    mDev = NULL;
     mRunning = false;
     mExit = false;
     mPaused = false;
     mObjHead = NULL;
     mError = RS_ERROR_NONE;
     mErrorMsg = NULL;
+}
+
+Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc)
+{
+    Context * rsc = new Context();
+    if (!rsc->initContext(dev, sc)) {
+        delete rsc;
+        return NULL;
+    }
+    return rsc;
+}
+
+bool Context::initContext(Device *dev, const RsSurfaceConfig *sc)
+{
+    pthread_mutex_lock(&gInitMutex);
+
+    dev->addContext(this);
+    mDev = dev;
     if (sc) {
         mUserSurfaceConfig = *sc;
     } else {
@@ -610,7 +646,7 @@
         if (status) {
             LOGE("Failed to init thread tls key.");
             pthread_mutex_unlock(&gInitMutex);
-            return;
+            return false;
         }
     }
     gThreadTLSKeyCount++;
@@ -622,7 +658,7 @@
     status = pthread_attr_init(&threadAttr);
     if (status) {
         LOGE("Failed to init thread attribute.");
-        return;
+        return false;
     }
 
     mWndSurface = NULL;
@@ -642,12 +678,16 @@
     status = pthread_create(&mThreadId, &threadAttr, threadProc, this);
     if (status) {
         LOGE("Failed to start rs context thread.");
-        return;
+        return false;
     }
-    while(!mRunning) {
+    while(!mRunning && (mError == RS_ERROR_NONE)) {
         usleep(100);
     }
 
+    if (mError != RS_ERROR_NONE) {
+        return false;
+    }
+
     mWorkers.mCompleteSignal.init();
     mWorkers.mRunningCount = 0;
     mWorkers.mLaunchCount = 0;
@@ -660,6 +700,7 @@
         }
     }
     pthread_attr_destroy(&threadAttr);
+    return true;
 }
 
 Context::~Context()
@@ -1020,7 +1061,7 @@
 {
     LOGV("rsContextCreate %p", vdev);
     Device * dev = static_cast<Device *>(vdev);
-    Context *rsc = new Context(dev, NULL);
+    Context *rsc = Context::createContext(dev, NULL);
     return rsc;
 }
 
@@ -1028,7 +1069,7 @@
 {
     LOGV("rsContextCreateGL %p", vdev);
     Device * dev = static_cast<Device *>(vdev);
-    Context *rsc = new Context(dev, &sc);
+    Context *rsc = Context::createContext(dev, &sc);
     LOGV("rsContextCreateGL ret %p ", rsc);
     return rsc;
 }
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index e269d4e..2017ceb7 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -69,7 +69,7 @@
 class Context
 {
 public:
-    Context(Device *, const RsSurfaceConfig *sc);
+    static Context * createContext(Device *, const RsSurfaceConfig *sc);
     ~Context();
 
     static pthread_key_t gThreadTLSKey;
@@ -276,9 +276,10 @@
 
 private:
     Context();
+    bool initContext(Device *, const RsSurfaceConfig *sc);
 
-    void initEGL();
-    void initGLThread();
+
+    bool initGLThread();
     void deinitEGL();
 
     uint32_t runRootScript();
diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp
index 811edaf..944a79b 100644
--- a/libs/ui/Input.cpp
+++ b/libs/ui/Input.cpp
@@ -33,6 +33,7 @@
         case AKEYCODE_ENDCALL:
         case AKEYCODE_VOLUME_UP:
         case AKEYCODE_VOLUME_DOWN:
+        case AKEYCODE_VOLUME_MUTE:
         case AKEYCODE_POWER:
         case AKEYCODE_CAMERA:
         case AKEYCODE_HEADSETHOOK:
@@ -40,11 +41,14 @@
         case AKEYCODE_NOTIFICATION:
         case AKEYCODE_FOCUS:
         case AKEYCODE_SEARCH:
+        case AKEYCODE_MEDIA_PLAY:
+        case AKEYCODE_MEDIA_PAUSE:
         case AKEYCODE_MEDIA_PLAY_PAUSE:
         case AKEYCODE_MEDIA_STOP:
         case AKEYCODE_MEDIA_NEXT:
         case AKEYCODE_MEDIA_PREVIOUS:
         case AKEYCODE_MEDIA_REWIND:
+        case AKEYCODE_MEDIA_RECORD:
         case AKEYCODE_MEDIA_FAST_FORWARD:
         case AKEYCODE_MUTE:
             return true;
@@ -67,14 +71,18 @@
         case AKEYCODE_ENDCALL:
         case AKEYCODE_VOLUME_UP:
         case AKEYCODE_VOLUME_DOWN:
+        case AKEYCODE_VOLUME_MUTE:
         case AKEYCODE_MUTE:
         case AKEYCODE_POWER:
         case AKEYCODE_HEADSETHOOK:
+        case AKEYCODE_MEDIA_PLAY:
+        case AKEYCODE_MEDIA_PAUSE:
         case AKEYCODE_MEDIA_PLAY_PAUSE:
         case AKEYCODE_MEDIA_STOP:
         case AKEYCODE_MEDIA_NEXT:
         case AKEYCODE_MEDIA_PREVIOUS:
         case AKEYCODE_MEDIA_REWIND:
+        case AKEYCODE_MEDIA_RECORD:
         case AKEYCODE_MEDIA_FAST_FORWARD:
         case AKEYCODE_CAMERA:
         case AKEYCODE_FOCUS:
diff --git a/libs/ui/InputDispatcher.cpp b/libs/ui/InputDispatcher.cpp
index 58d4c56..f9c0b91 100644
--- a/libs/ui/InputDispatcher.cpp
+++ b/libs/ui/InputDispatcher.cpp
@@ -51,8 +51,8 @@
 
 namespace android {
 
-// Delay between reporting long touch events to the power manager.
-const nsecs_t EVENT_IGNORE_DURATION = 300 * 1000000LL; // 300 ms
+// Delay before reporting long touch events to the power manager.
+const nsecs_t LONG_TOUCH_DELAY = 300 * 1000000LL; // 300 ms
 
 // Default input dispatching timeout if there is no focused application or paused window
 // from which to determine an appropriate dispatching timeout.
@@ -619,6 +619,38 @@
 bool InputDispatcher::dispatchKeyLocked(
         nsecs_t currentTime, KeyEntry* entry, nsecs_t keyRepeatTimeout,
         DropReason* dropReason, nsecs_t* nextWakeupTime) {
+    // Preprocessing.
+    if (! entry->dispatchInProgress) {
+        if (entry->repeatCount == 0
+                && entry->action == AKEY_EVENT_ACTION_DOWN
+                && (entry->policyFlags & POLICY_FLAG_TRUSTED)
+                && !entry->isInjected()) {
+            if (mKeyRepeatState.lastKeyEntry
+                    && mKeyRepeatState.lastKeyEntry->keyCode == entry->keyCode) {
+                // We have seen two identical key downs in a row which indicates that the device
+                // driver is automatically generating key repeats itself.  We take note of the
+                // repeat here, but we disable our own next key repeat timer since it is clear that
+                // we will not need to synthesize key repeats ourselves.
+                entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1;
+                resetKeyRepeatLocked();
+                mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves
+            } else {
+                // Not a repeat.  Save key down state in case we do see a repeat later.
+                resetKeyRepeatLocked();
+                mKeyRepeatState.nextRepeatTime = entry->eventTime + keyRepeatTimeout;
+            }
+            mKeyRepeatState.lastKeyEntry = entry;
+            entry->refCount += 1;
+        } else if (! entry->syntheticRepeat) {
+            resetKeyRepeatLocked();
+        }
+
+        entry->dispatchInProgress = true;
+        resetTargetsLocked();
+
+        logOutboundKeyDetailsLocked("dispatchKey - ", entry);
+    }
+
     // Give the policy a chance to intercept the key.
     if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN) {
         if (entry->policyFlags & POLICY_FLAG_PASS_TO_USER) {
@@ -647,38 +679,6 @@
         return true;
     }
 
-    // Preprocessing.
-    if (! entry->dispatchInProgress) {
-        logOutboundKeyDetailsLocked("dispatchKey - ", entry);
-
-        if (entry->repeatCount == 0
-                && entry->action == AKEY_EVENT_ACTION_DOWN
-                && (entry->policyFlags & POLICY_FLAG_TRUSTED)
-                && !entry->isInjected()) {
-            if (mKeyRepeatState.lastKeyEntry
-                    && mKeyRepeatState.lastKeyEntry->keyCode == entry->keyCode) {
-                // We have seen two identical key downs in a row which indicates that the device
-                // driver is automatically generating key repeats itself.  We take note of the
-                // repeat here, but we disable our own next key repeat timer since it is clear that
-                // we will not need to synthesize key repeats ourselves.
-                entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1;
-                resetKeyRepeatLocked();
-                mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves
-            } else {
-                // Not a repeat.  Save key down state in case we do see a repeat later.
-                resetKeyRepeatLocked();
-                mKeyRepeatState.nextRepeatTime = entry->eventTime + keyRepeatTimeout;
-            }
-            mKeyRepeatState.lastKeyEntry = entry;
-            entry->refCount += 1;
-        } else if (! entry->syntheticRepeat) {
-            resetKeyRepeatLocked();
-        }
-
-        entry->dispatchInProgress = true;
-        resetTargetsLocked();
-    }
-
     // Identify targets.
     if (! mCurrentInputTargetsValid) {
         int32_t injectionResult = findFocusedWindowTargetsLocked(currentTime,
@@ -705,16 +705,24 @@
 #if DEBUG_OUTBOUND_EVENT_DETAILS
     LOGD("%seventTime=%lld, deviceId=0x%x, source=0x%x, policyFlags=0x%x, "
             "action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, "
-            "downTime=%lld",
+            "repeatCount=%d, downTime=%lld",
             prefix,
             entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
             entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState,
-            entry->downTime);
+            entry->repeatCount, entry->downTime);
 #endif
 }
 
 bool InputDispatcher::dispatchMotionLocked(
         nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) {
+    // Preprocessing.
+    if (! entry->dispatchInProgress) {
+        entry->dispatchInProgress = true;
+        resetTargetsLocked();
+
+        logOutboundMotionDetailsLocked("dispatchMotion - ", entry);
+    }
+
     // Clean up if dropping the event.
     if (*dropReason != DROP_REASON_NOT_DROPPED) {
         resetTargetsLocked();
@@ -723,14 +731,6 @@
         return true;
     }
 
-    // Preprocessing.
-    if (! entry->dispatchInProgress) {
-        logOutboundMotionDetailsLocked("dispatchMotion - ", entry);
-
-        entry->dispatchInProgress = true;
-        resetTargetsLocked();
-    }
-
     bool isPointerEvent = entry->source & AINPUT_SOURCE_CLASS_POINTER;
 
     // Identify targets.
@@ -1424,7 +1424,7 @@
                 eventType = POWER_MANAGER_TOUCH_UP_EVENT;
                 break;
             default:
-                if (motionEntry->eventTime - motionEntry->downTime >= EVENT_IGNORE_DURATION) {
+                if (motionEntry->eventTime - motionEntry->downTime < LONG_TOUCH_DELAY) {
                     eventType = POWER_MANAGER_TOUCH_EVENT;
                 } else {
                     eventType = POWER_MANAGER_LONG_TOUCH_EVENT;
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
index 12db908..1994f6a 100644
--- a/libs/ui/Region.cpp
+++ b/libs/ui/Region.cpp
@@ -289,7 +289,7 @@
     void flushSpan() {
         bool merge = false;
         if (tail-head == ssize_t(span.size())) {
-            Rect const* p = cur;
+            Rect const* p = span.editArray();
             Rect const* q = head;
             if (p->top == q->bottom) {
                 merge = true;
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index 03d2e21..f287298 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -1949,7 +1949,7 @@
         desiredConfig = overrideConfig;
     }
 
-    ssize_t rc = BAD_INDEX;
+    ssize_t rc = BAD_VALUE;
     size_t ip = grp->packages.size();
     while (ip > 0) {
         ip--;
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 23f34d2..3bee906 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -307,10 +307,14 @@
         // Register for device connection intent broadcasts.
         IntentFilter intentFilter =
                 new IntentFilter(Intent.ACTION_HEADSET_PLUG);
+
         intentFilter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
         intentFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
         intentFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
         intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
+        intentFilter.addAction(Intent.ACTION_USB_ANLG_HEADSET_PLUG);
+        intentFilter.addAction(Intent.ACTION_USB_DGTL_HEADSET_PLUG);
+        intentFilter.addAction(Intent.ACTION_HDMI_AUDIO_PLUG);
         context.registerReceiver(mReceiver, intentFilter);
 
         // Register for media button intent broadcasts.
@@ -1816,6 +1820,12 @@
                     case Intent.EXTRA_DOCK_STATE_CAR:
                         config = AudioSystem.FORCE_BT_CAR_DOCK;
                         break;
+                    case Intent.EXTRA_DOCK_STATE_LE_DESK:
+                        config = AudioSystem.FORCE_ANALOG_DOCK;
+                        break;
+                    case Intent.EXTRA_DOCK_STATE_HE_DESK:
+                        config = AudioSystem.FORCE_DIGITAL_DOCK;
+                        break;
                     case Intent.EXTRA_DOCK_STATE_UNDOCKED:
                     default:
                         config = AudioSystem.FORCE_NONE;
@@ -1927,6 +1937,33 @@
                         mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE), "");
                     }
                 }
+            } else if (action.equals(Intent.ACTION_USB_ANLG_HEADSET_PLUG)) {
+                int state = intent.getIntExtra("state", 0);
+                Log.v(TAG, "Broadcast Receiver: Got ACTION_USB_ANLG_HEADSET_PLUG, state = "+state);
+                boolean isConnected = mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET);
+                if (state == 0 && isConnected) {
+                    AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET,
+                                                         AudioSystem.DEVICE_STATE_UNAVAILABLE, "");
+                    mConnectedDevices.remove(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET);
+                } else if (state == 1 && !isConnected)  {
+                    AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET,
+                                                         AudioSystem.DEVICE_STATE_AVAILABLE, "");
+                    mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET), "");
+                }
+            } else if ( (action.equals(Intent.ACTION_USB_DGTL_HEADSET_PLUG)) ||
+                        (action.equals(Intent.ACTION_HDMI_AUDIO_PLUG)) ) {
+                int state = intent.getIntExtra("state", 0);
+                Log.v(TAG, "Broadcast Receiver: Got ACTION_USB_DGTL_HEADSET_PLUG, state = "+state);
+                boolean isConnected = mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET);
+                if (state == 0 && isConnected) {
+                    AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET,
+                                                         AudioSystem.DEVICE_STATE_UNAVAILABLE, "");
+                    mConnectedDevices.remove(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET);
+                } else if (state == 1 && !isConnected)  {
+                    AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET,
+                                                         AudioSystem.DEVICE_STATE_AVAILABLE, "");
+                    mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET), "");
+                }
             } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
                 int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
                 synchronized (mScoClients) {
@@ -1938,6 +1975,10 @@
                         case BluetoothHeadset.STATE_AUDIO_DISCONNECTED:
                             state = AudioManager.SCO_AUDIO_STATE_DISCONNECTED;
                             break;
+                        case BluetoothHeadset.STATE_AUDIO_CONNECTING:
+                            // Todo(): Handle this, ignore for now as a public
+                            // API will break.
+                            break;
                         default:
                             state = AudioManager.SCO_AUDIO_STATE_ERROR;
                             break;
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index a4818ff..5442791 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -243,6 +243,8 @@
     public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100;
     public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200;
     public static final int DEVICE_OUT_AUX_DIGITAL = 0x400;
+    public static final int DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800;
+    public static final int DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000;
     public static final int DEVICE_OUT_DEFAULT = 0x8000;
     // input devices
     public static final int DEVICE_IN_COMMUNICATION = 0x10000;
@@ -273,6 +275,8 @@
     public static final int FORCE_WIRED_ACCESSORY = 5;
     public static final int FORCE_BT_CAR_DOCK = 6;
     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;
     public static final int FORCE_DEFAULT = FORCE_NONE;
 
     // usage for serForceUse
diff --git a/media/java/android/media/MediaFile.java b/media/java/android/media/MediaFile.java
index 381b77a..532a2df 100644
--- a/media/java/android/media/MediaFile.java
+++ b/media/java/android/media/MediaFile.java
@@ -83,6 +83,11 @@
     private static final int FIRST_PLAYLIST_FILE_TYPE = FILE_TYPE_M3U;
     private static final int LAST_PLAYLIST_FILE_TYPE = FILE_TYPE_WPL;
 
+    // Drm file types
+    public static final int FILE_TYPE_FL      = 51;
+    private static final int FIRST_DRM_FILE_TYPE = FILE_TYPE_FL;
+    private static final int LAST_DRM_FILE_TYPE = FILE_TYPE_FL;
+
     // Other popular file types
     public static final int FILE_TYPE_TEXT          = 100;
     public static final int FILE_TYPE_HTML          = 101;
@@ -189,6 +194,8 @@
         addFileType("PLS", FILE_TYPE_PLS, "audio/x-scpls", MtpConstants.FORMAT_PLS_PLAYLIST);
         addFileType("WPL", FILE_TYPE_WPL, "application/vnd.ms-wpl", MtpConstants.FORMAT_WPL_PLAYLIST);
 
+        addFileType("FL", FILE_TYPE_FL, "application/x-android-drm-fl");
+
         addFileType("TXT", FILE_TYPE_TEXT, "text/plain", MtpConstants.FORMAT_TEXT);
         addFileType("HTM", FILE_TYPE_HTML, "text/html", MtpConstants.FORMAT_HTML);
         addFileType("HTML", FILE_TYPE_HTML, "text/html", MtpConstants.FORMAT_HTML);
@@ -222,6 +229,11 @@
                 fileType <= LAST_PLAYLIST_FILE_TYPE);
     }
 
+    public static boolean isDrmFileType(int fileType) {
+        return (fileType >= FIRST_DRM_FILE_TYPE &&
+                fileType <= LAST_DRM_FILE_TYPE);
+    }
+
     public static MediaFileType getFileType(String path) {
         int lastDot = path.lastIndexOf(".");
         if (lastDot < 0)
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index e5fa0f8..3f6b7a2 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -26,6 +26,7 @@
 import android.content.IContentProvider;
 import android.database.Cursor;
 import android.database.SQLException;
+import android.drm.DrmManagerClient;
 import android.graphics.BitmapFactory;
 import android.net.Uri;
 import android.os.Process;
@@ -360,6 +361,7 @@
     private ArrayList<FileCacheEntry> mPlayLists;
     private HashMap<String, Uri> mGenreCache;
 
+    private DrmManagerClient mDrmManagerClient = null;
 
     public MediaScanner(Context c) {
         native_setup();
@@ -381,6 +383,11 @@
 
     private MyMediaScannerClient mClient = new MyMediaScannerClient();
 
+    private boolean isDrmEnabled() {
+        String prop = SystemProperties.get("drm.service.enabled");
+        return prop != null && prop.equals("true");
+    }
+    
     private class MyMediaScannerClient implements MediaScannerClient {
 
         private String mArtist;
@@ -447,6 +454,10 @@
                 }
             }
 
+            if (isDrmEnabled() && MediaFile.isDrmFileType(mFileType)) {
+                mFileType = getFileTypeFromDrm(path);
+            }
+
             String key = path;
             if (mCaseInsensitivePaths) {
                 key = path.toLowerCase();
@@ -874,6 +885,27 @@
             }
         }
 
+        private int getFileTypeFromDrm(String path) {
+            if (!isDrmEnabled()) {
+                return 0;
+            }
+
+            int resultFileType = 0;
+
+            if (mDrmManagerClient == null) {
+                mDrmManagerClient = new DrmManagerClient(mContext);
+            }
+
+            if (mDrmManagerClient.canHandle(path, null)) {
+                String drmMimetype = mDrmManagerClient.getOriginalMimeType(path);
+                if (drmMimetype != null) {
+                    mMimeType = drmMimetype;
+                    resultFileType = MediaFile.getFileTypeForMimeType(drmMimetype);
+                }
+            }
+            return resultFileType;
+        }
+
     }; // end of anonymous MediaScannerClient instance
 
     private void prescan(String filePath, boolean prescanFiles) throws RemoteException {
diff --git a/media/java/android/media/MtpDatabase.java b/media/java/android/media/MtpDatabase.java
index 51647434..57ab3a1 100644
--- a/media/java/android/media/MtpDatabase.java
+++ b/media/java/android/media/MtpDatabase.java
@@ -23,6 +23,7 @@
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.net.Uri;
+import android.os.Environment;
 import android.os.RemoteException;
 import android.provider.MediaStore.Audio;
 import android.provider.MediaStore.Files;
@@ -45,6 +46,7 @@
     private final String mVolumeName;
     private final Uri mObjectsUri;
     private final String mMediaStoragePath;
+    private final String mExternalStoragePath;
 
     // true if the database has been modified in the current MTP session
     private boolean mDatabaseModified;
@@ -77,7 +79,6 @@
             Files.FileColumns.DATE_MODIFIED, // 5
     };
     private static final String ID_WHERE = Files.FileColumns._ID + "=?";
-    private static final String PATH_WHERE = Files.FileColumns.DATA + "=?";
     private static final String PARENT_WHERE = Files.FileColumns.PARENT + "=?";
     private static final String PARENT_FORMAT_WHERE = PARENT_WHERE + " AND "
                                             + Files.FileColumns.FORMAT + "=?";
@@ -98,6 +99,7 @@
         mMediaProvider = context.getContentResolver().acquireProvider("media");
         mVolumeName = volumeName;
         mMediaStoragePath = storagePath;
+        mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
         mObjectsUri = Files.getMtpObjectsUri(volumeName);
         mMediaScanner = new MediaScanner(context);
         openDevicePropertiesDatabase(context);
@@ -112,6 +114,16 @@
         }
     }
 
+    private String externalToMediaPath(String path) {
+        // convert external storage path to media path
+        if (path != null && mMediaStoragePath != null
+                && mExternalStoragePath != null
+                && path.startsWith(mExternalStoragePath)) {
+            path = mMediaStoragePath + path.substring(mExternalStoragePath.length());
+        }
+        return path;
+    }
+
     private void openDevicePropertiesDatabase(Context context) {
         mDevicePropDb = context.openOrCreateDatabase("device-properties", Context.MODE_PRIVATE, null);
         int version = mDevicePropDb.getVersion();
@@ -482,7 +494,7 @@
         try {
             c = mMediaProvider.query(mObjectsUri, PATH_PROJECTION, ID_WHERE, whereArgs, null);
             if (c != null && c.moveToNext()) {
-                path = c.getString(1);
+                path = externalToMediaPath(c.getString(1));
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException in getObjectFilePath", e);
@@ -763,7 +775,7 @@
                 return true;
             }
         } catch (RemoteException e) {
-            Log.e(TAG, "RemoteException in getObjectProperty", e);
+            Log.e(TAG, "RemoteException in getObjectInfo", e);
         } finally {
             if (c != null) {
                 c.close();
@@ -786,7 +798,7 @@
             c = mMediaProvider.query(mObjectsUri, PATH_SIZE_PROJECTION,
                             ID_WHERE, new String[] {  Integer.toString(handle) }, null);
             if (c != null && c.moveToNext()) {
-                String path = c.getString(1);
+                String path = externalToMediaPath(c.getString(1));
                 path.getChars(0, path.length(), outFilePath, 0);
                 outFilePath[path.length()] = 0;
                 outFileLength[0] = c.getLong(2);
diff --git a/media/java/android/media/videoeditor/AudioTrack.java b/media/java/android/media/videoeditor/AudioTrack.java
index 573208a..d02709e 100755
--- a/media/java/android/media/videoeditor/AudioTrack.java
+++ b/media/java/android/media/videoeditor/AudioTrack.java
@@ -17,6 +17,7 @@
 package android.media.videoeditor;

 

 import java.io.IOException;

+import java.lang.ref.SoftReference;

 

 /**

  * This class allows to handle an audio track. This audio file is mixed with the

@@ -49,7 +50,7 @@
     // The audio waveform filename

     private String mAudioWaveformFilename;

     // The audio waveform data

-    private WaveformData mWaveformData;

+    private SoftReference<WaveformData> mWaveformData;

 

     /**

      * An object of this type cannot be instantiated by using the default

@@ -165,7 +166,8 @@
 

         mAudioWaveformFilename = audioWaveformFilename;

         if (audioWaveformFilename != null) {

-            mWaveformData = new WaveformData(audioWaveformFilename);

+            mWaveformData =

+                new SoftReference<WaveformData>(new WaveformData(audioWaveformFilename));

         } else {

             mWaveformData = null;

         }

@@ -424,7 +426,7 @@
             throws IOException {

         // TODO: Set mAudioWaveformFilename at the end once the extract is

         // complete

-        mWaveformData = new WaveformData(mAudioWaveformFilename);

+        mWaveformData = new SoftReference<WaveformData>(new WaveformData(mAudioWaveformFilename));

     }

 

     /**

@@ -448,7 +450,20 @@
      * @return The waveform data

      */

     public WaveformData getWaveformData() {

-        return mWaveformData;

+        if (mWaveformData == null) {

+            return null;

+        }

+

+        WaveformData waveformData = mWaveformData.get();

+        if (waveformData != null) {

+            return waveformData;

+        } else if (mAudioWaveformFilename != null) {

+            waveformData = new WaveformData(mAudioWaveformFilename);

+            mWaveformData = new SoftReference<WaveformData>(waveformData);

+            return waveformData;

+        } else {

+            return null;

+        }

     }

 

     /*

diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java
index 1fa98e7..c1abf78 100755
--- a/media/java/android/media/videoeditor/MediaVideoItem.java
+++ b/media/java/android/media/videoeditor/MediaVideoItem.java
@@ -17,6 +17,7 @@
 package android.media.videoeditor;

 

 import java.io.IOException;

+import java.lang.ref.SoftReference;

 

 import android.graphics.Bitmap;

 import android.view.SurfaceHolder;

@@ -47,7 +48,7 @@
     private boolean mMuted;

     private String mAudioWaveformFilename;

     // The audio waveform data

-    private WaveformData mWaveformData;

+    private SoftReference<WaveformData> mWaveformData;

 

     /**

      * An object of this type cannot be instantiated with a default constructor

@@ -118,7 +119,8 @@
         mMuted = muted;

         mAudioWaveformFilename = audioWaveformFilename;

         if (audioWaveformFilename != null) {

-            mWaveformData = new WaveformData(audioWaveformFilename);

+            mWaveformData =

+                new SoftReference<WaveformData>(new WaveformData(audioWaveformFilename));

         } else {

             mWaveformData = null;

         }

@@ -293,7 +295,7 @@
     public void extractAudioWaveform(ExtractAudioWaveformProgressListener listener)

             throws IOException {

         // TODO: Set mAudioWaveformFilename at the end once the export is complete

-        mWaveformData = new WaveformData(mAudioWaveformFilename);

+        mWaveformData = new SoftReference<WaveformData>(new WaveformData(mAudioWaveformFilename));

     }

 

     /**

@@ -315,7 +317,20 @@
      * @return The waveform data

      */

     public WaveformData getWaveformData() {

-        return mWaveformData;

+        if (mWaveformData == null) {

+            return null;

+        }

+

+        WaveformData waveformData = mWaveformData.get();

+        if (waveformData != null) {

+            return waveformData;

+        } else if (mAudioWaveformFilename != null) {

+            waveformData = new WaveformData(mAudioWaveformFilename);

+            mWaveformData = new SoftReference<WaveformData>(waveformData);

+            return waveformData;

+        } else {

+            return null;

+        }

     }

 

     /**

diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 6954e36..ca90c0c 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -333,14 +333,9 @@
     }
 
     dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
-    if (mDecryptHandle != NULL) {
-        if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {
-            if (DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) {
-                mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
-            }
-        } else {
-            notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
-        }
+    if (mDecryptHandle != NULL
+            && RightsStatus::RIGHTS_VALID != mDecryptHandle->status) {
+        notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
     }
 
     return setDataSource_l(extractor);
@@ -408,11 +403,6 @@
     }
 
     mExtractorFlags = extractor->flags();
-    if (mDecryptHandle != NULL) {
-        if (DecryptApiType::ELEMENTARY_STREAM_BASED == mDecryptHandle->decryptApiType) {
-            mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
-        }
-    }
 
     return OK;
 }
@@ -426,8 +416,6 @@
     if (mDecryptHandle != NULL) {
             mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
                     Playback::STOP, 0);
-            mDrmManagerClient->consumeRights(mDecryptHandle,
-                    Action::PLAY, false);
             mDecryptHandle = NULL;
             mDrmManagerClient = NULL;
     }
@@ -1679,14 +1667,9 @@
     }
 
     dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
-    if (mDecryptHandle != NULL) {
-        if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {
-            if (DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) {
-                mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
-            }
-        } else {
-            notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
-        }
+    if (mDecryptHandle != NULL
+            && RightsStatus::RIGHTS_VALID != mDecryptHandle->status) {
+        notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
     }
 
     return setDataSource_l(extractor);
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 0d8abe2..3c3bd93 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -167,13 +167,13 @@
     { MEDIA_MIMETYPE_AUDIO_AAC, "AACDecoder" },
     { MEDIA_MIMETYPE_AUDIO_G711_ALAW, "G711Decoder" },
     { MEDIA_MIMETYPE_AUDIO_G711_MLAW, "G711Decoder" },
-//    { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.Nvidia.mp4.decode" },
+    { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.Nvidia.mp4.decode" },
     { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.qcom.7x30.video.decoder.mpeg4" },
     { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.qcom.video.decoder.mpeg4" },
     { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.TI.Video.Decoder" },
     { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.SEC.MPEG4.Decoder" },
     { MEDIA_MIMETYPE_VIDEO_MPEG4, "M4vH263Decoder" },
-//    { MEDIA_MIMETYPE_VIDEO_H263, "OMX.Nvidia.h263.decode" },
+    { MEDIA_MIMETYPE_VIDEO_H263, "OMX.Nvidia.h263.decode" },
     { MEDIA_MIMETYPE_VIDEO_H263, "OMX.qcom.7x30.video.decoder.h263" },
     { MEDIA_MIMETYPE_VIDEO_H263, "OMX.qcom.video.decoder.h263" },
     { MEDIA_MIMETYPE_VIDEO_H263, "OMX.SEC.H263.Decoder" },
@@ -1710,16 +1710,11 @@
         return err;
     }
 
-    // Check that the color format is in the correct range.
-    CHECK(OMX_COLOR_FormatAndroidPrivateStart <= def.format.video.eColorFormat);
-    CHECK(def.format.video.eColorFormat < OMX_COLOR_FormatAndroidPrivateEnd);
-
     err = native_window_set_buffers_geometry(
             mNativeWindow.get(),
             def.format.video.nFrameWidth,
             def.format.video.nFrameHeight,
-            def.format.video.eColorFormat
-                - OMX_COLOR_FormatAndroidPrivateStart);
+            def.format.video.eColorFormat);
 
     if (err != 0) {
         LOGE("native_window_set_buffers_geometry failed: %s (%d)",
@@ -2109,6 +2104,17 @@
                     CODEC_LOGV(
                             "output crop (%ld, %ld, %ld, %ld)",
                             rect.nLeft, rect.nTop, rect.nWidth, rect.nHeight);
+
+                    if (mNativeWindow != NULL) {
+                        android_native_rect_t crop;
+                        crop.left = rect.nLeft;
+                        crop.top = rect.nTop;
+                        crop.right = crop.left + rect.nWidth - 1;
+                        crop.bottom = crop.top + rect.nHeight - 1;
+
+                        CHECK_EQ(0, native_window_set_crop(
+                                    mNativeWindow.get(), &crop));
+                    }
                 } else {
                     CODEC_LOGE("getConfig(OMX_IndexConfigCommonOutputCrop) "
                                "returned error 0x%08x", err);
diff --git a/media/libstagefright/StagefrightMediaScanner.cpp b/media/libstagefright/StagefrightMediaScanner.cpp
index 1629e9f..6c05e03 100644
--- a/media/libstagefright/StagefrightMediaScanner.cpp
+++ b/media/libstagefright/StagefrightMediaScanner.cpp
@@ -39,7 +39,7 @@
         ".mp3", ".mp4", ".m4a", ".3gp", ".3gpp", ".3g2", ".3gpp2",
         ".mpeg", ".ogg", ".mid", ".smf", ".imy", ".wma", ".aac",
         ".wav", ".amr", ".midi", ".xmf", ".rtttl", ".rtx", ".ota",
-        ".mkv", ".mka", ".webm", ".ts"
+        ".mkv", ".mka", ".webm", ".ts", ".fl"
     };
     static const size_t kNumValidExtensions =
         sizeof(kValidExtensions) / sizeof(kValidExtensions[0]);
diff --git a/native/include/android/keycodes.h b/native/include/android/keycodes.h
index 3fcf977..11142537 100644
--- a/native/include/android/keycodes.h
+++ b/native/include/android/keycodes.h
@@ -207,7 +207,7 @@
     AKEYCODE_NUMPAD_EQUALS   = 161,
     AKEYCODE_NUMPAD_LEFT_PAREN = 162,
     AKEYCODE_NUMPAD_RIGHT_PAREN = 163,
-
+    AKEYCODE_VOLUME_MUTE     = 164,
 
     // NOTE: If you add a new keycode here you must also add it to several other files.
     //       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
diff --git a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back.png b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back.png
new file mode 100644
index 0000000..6baf5ea
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back.png
Binary files differ
diff --git a/packages/SystemUI/res/layout-xlarge/status_bar.xml b/packages/SystemUI/res/layout-xlarge/status_bar.xml
index dbe4167..590132f 100644
--- a/packages/SystemUI/res/layout-xlarge/status_bar.xml
+++ b/packages/SystemUI/res/layout-xlarge/status_bar.xml
@@ -133,7 +133,7 @@
                 android:layout_height="match_parent"
                 android:paddingLeft="15dip"
                 android:paddingRight="15dip"
-                android:src="@drawable/status_bar_back"
+                android:src="@drawable/ic_sysbar_back"
                 android:background="@drawable/ic_sysbar_icon_bg"
                 systemui:keyCode="4"
                 />
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
index c416ff4..a025d63 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
@@ -16,10 +16,7 @@
 
 package com.android.systemui.statusbar.tablet;
 
-import android.content.BroadcastReceiver;
 import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.os.Handler;
@@ -36,13 +33,12 @@
 import com.android.server.InputMethodManagerService;
 import com.android.systemui.R;
 
-import java.util.Calendar;
 import java.util.List;
-import java.util.TimeZone;
 
 public class InputMethodButton extends ImageView {
 
     private static final String  TAG = "StatusBar/InputMethodButton";
+    private static final boolean DEBUG = false;
 
     private boolean mKeyboardShown;
     private ImageView mIcon;
@@ -94,6 +90,9 @@
         InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype();
         Drawable icon = null;
         if (imi != null) {
+            if (DEBUG) {
+                Log.d(TAG, "--- Update icons of IME: " + imi.getPackageName() + "," + subtype);
+            }
             if (subtype != null) {
                 return pm.getDrawable(imi.getPackageName(), subtype.getIconResId(),
                         imi.getServiceInfo().applicationInfo);
diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
index 47ed7da..7dff549 100644
--- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
+++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
@@ -23,6 +23,8 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
 import android.os.storage.StorageEventListener;
 import android.os.storage.StorageManager;
 import android.provider.Settings;
@@ -60,6 +62,8 @@
     private boolean        mUmsAvailable;
     private StorageManager mStorageManager;
 
+    private Handler        mAsyncEventHandler;
+
     public StorageNotification(Context context) {
         mContext = context;
 
@@ -67,6 +71,11 @@
         final boolean connected = mStorageManager.isUsbMassStorageConnected();
         Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable,
                 Environment.getExternalStorageState()));
+        
+        HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
+        thr.start();
+        mAsyncEventHandler = new Handler(thr.getLooper());
+
         onUsbMassStorageConnectionChanged(connected);
     }
 
@@ -74,7 +83,16 @@
      * @override com.android.os.storage.StorageEventListener
      */
     @Override
-    public void onUsbMassStorageConnectionChanged(boolean connected) {
+    public void onUsbMassStorageConnectionChanged(final boolean connected) {
+        mAsyncEventHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                onUsbMassStorageConnectionChangedAsync(connected);
+            }
+        });
+    }
+
+    private void onUsbMassStorageConnectionChangedAsync(boolean connected) {
         mUmsAvailable = connected;
         /*
          * Even though we may have a UMS host connected, we the SD card
@@ -98,7 +116,16 @@
      * @override com.android.os.storage.StorageEventListener
      */
     @Override
-    public void onStorageStateChanged(String path, String oldState, String newState) {
+    public void onStorageStateChanged(final String path, final String oldState, final String newState) {
+        mAsyncEventHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                onStorageStateChangedAsync(path, oldState, newState);
+            }
+        });
+    }
+
+    private void onStorageStateChangedAsync(String path, String oldState, String newState) {
         Slog.i(TAG, String.format(
                 "Media {%s} state changed from {%s} -> {%s}", path, oldState, newState));
         if (newState.equals(Environment.MEDIA_SHARED)) {
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
index 0f1aa4e..34dbace 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
@@ -170,7 +170,8 @@
                 }
 
                 case KeyEvent.KEYCODE_VOLUME_UP:
-                case KeyEvent.KEYCODE_VOLUME_DOWN: {
+                case KeyEvent.KEYCODE_VOLUME_DOWN:
+                case KeyEvent.KEYCODE_VOLUME_MUTE: {
                     synchronized (this) {
                         if (mAudioManager == null) {
                             mAudioManager = (AudioManager) getContext().getSystemService(
@@ -179,6 +180,7 @@
                     }
                     // Volume buttons should only function for music.
                     if (mAudioManager.isMusicActive()) {
+                        // TODO: Actually handle MUTE.
                         mAudioManager.adjustStreamVolume(
                                     AudioManager.STREAM_MUSIC,
                                     keyCode == KeyEvent.KEYCODE_VOLUME_UP
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
index c870503..42b73b9 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -786,6 +786,7 @@
         switch (keyCode) {
             case KeyEvent.KEYCODE_VOLUME_UP:
             case KeyEvent.KEYCODE_VOLUME_DOWN:
+            case KeyEvent.KEYCODE_VOLUME_MUTE:
             case KeyEvent.KEYCODE_MUTE:
             case KeyEvent.KEYCODE_HEADSETHOOK:
             case KeyEvent.KEYCODE_MEDIA_PLAY:
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index e944f9d..cd88821 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -1230,7 +1230,8 @@
         
         switch (keyCode) {
             case KeyEvent.KEYCODE_VOLUME_UP:
-            case KeyEvent.KEYCODE_VOLUME_DOWN: {
+            case KeyEvent.KEYCODE_VOLUME_DOWN:
+            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                 AudioManager audioManager = (AudioManager) getContext().getSystemService(
                         Context.AUDIO_SERVICE);
                 if (audioManager != null) {
@@ -1238,6 +1239,7 @@
                      * Adjust the volume in on key down since it is more
                      * responsive to the user.
                      */
+                    // TODO: Actually handle MUTE.
                     audioManager.adjustSuggestedStreamVolume(
                             keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                     ? AudioManager.ADJUST_RAISE
@@ -1405,7 +1407,8 @@
         
         switch (keyCode) {
             case KeyEvent.KEYCODE_VOLUME_UP:
-            case KeyEvent.KEYCODE_VOLUME_DOWN: {
+            case KeyEvent.KEYCODE_VOLUME_DOWN:
+            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                 if (!event.isCanceled()) {
                     AudioManager audioManager = (AudioManager) getContext().getSystemService(
                             Context.AUDIO_SERVICE);
@@ -1414,6 +1417,7 @@
                          * Play a sound. This is done on key up since we don't want the
                          * sound to play when a user holds down volume down to mute.
                          */
+                        // TODO: Actually handle MUTE.
                         audioManager.adjustSuggestedStreamVolume(
                                 AudioManager.ADJUST_SAME,
                                 mVolumeControlStreamType,
@@ -1720,6 +1724,7 @@
              * cancel the sound
              */
             if (keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP
+                    && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
                     && mVolumeKeyUpTime + VolumePanel.PLAY_SOUND_DELAY
                             > SystemClock.uptimeMillis()) {
                 /*
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index e950ae5..af1bf59 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1877,6 +1877,7 @@
             // since audio is playing, we shouldn't have to hold a wake lock
             // during the call, but we do it as a precaution for the rare possibility
             // that the music stops right before we call this
+            // TODO: Actually handle MUTE.
             mBroadcastWakeLock.acquire();
             audioService.adjustStreamVolume(stream,
                 keycode == KeyEvent.KEYCODE_VOLUME_UP
@@ -1949,7 +1950,8 @@
         // Handle special keys.
         switch (keyCode) {
             case KeyEvent.KEYCODE_VOLUME_DOWN:
-            case KeyEvent.KEYCODE_VOLUME_UP: {
+            case KeyEvent.KEYCODE_VOLUME_UP:
+            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                 if (down) {
                     ITelephony telephonyService = getTelephonyService();
                     if (telephonyService != null) {
diff --git a/services/audioflinger/AudioPolicyManagerBase.cpp b/services/audioflinger/AudioPolicyManagerBase.cpp
index 65d9ef7..86d4c9f 100644
--- a/services/audioflinger/AudioPolicyManagerBase.cpp
+++ b/services/audioflinger/AudioPolicyManagerBase.cpp
@@ -356,7 +356,9 @@
         break;
     case AudioSystem::FOR_MEDIA:
         if (config != AudioSystem::FORCE_HEADPHONES && config != AudioSystem::FORCE_BT_A2DP &&
-            config != AudioSystem::FORCE_WIRED_ACCESSORY && config != AudioSystem::FORCE_NONE) {
+            config != AudioSystem::FORCE_WIRED_ACCESSORY &&
+            config != AudioSystem::FORCE_ANALOG_DOCK &&
+            config != AudioSystem::FORCE_DIGITAL_DOCK && config != AudioSystem::FORCE_NONE) {
             LOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
             return;
         }
@@ -372,7 +374,10 @@
         break;
     case AudioSystem::FOR_DOCK:
         if (config != AudioSystem::FORCE_NONE && config != AudioSystem::FORCE_BT_CAR_DOCK &&
-            config != AudioSystem::FORCE_BT_DESK_DOCK && config != AudioSystem::FORCE_WIRED_ACCESSORY) {
+            config != AudioSystem::FORCE_BT_DESK_DOCK &&
+            config != AudioSystem::FORCE_WIRED_ACCESSORY &&
+            config != AudioSystem::FORCE_ANALOG_DOCK &&
+            config != AudioSystem::FORCE_DIGITAL_DOCK) {
             LOGW("setForceUse() invalid config %d for FOR_DOCK", config);
         }
         forceVolumeReeval = true;
@@ -1366,6 +1371,7 @@
 
 void AudioPolicyManagerBase::closeA2dpOutputs()
 {
+
     LOGV("setDeviceConnectionState() closing A2DP and duplicated output!");
 
     if (mDuplicatedOutput != 0) {
@@ -1558,6 +1564,8 @@
             if (device) break;
             device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
             if (device) break;
+            device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET;
+            if (device) break;
 #ifdef WITH_A2DP
             // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
             if (mPhoneState != AudioSystem::MODE_IN_CALL) {
@@ -1617,6 +1625,12 @@
         if (device2 == 0) {
             device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
         }
+        if (device2 == 0) {
+            device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET;
+        }
+        if (device2 == 0) {
+            device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
+        }
 #ifdef WITH_A2DP
         if (mA2dpOutput != 0) {
             if (strategy == STRATEGY_SONIFICATION && !a2dpUsedForSonification()) {
@@ -1797,7 +1811,9 @@
         (AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP |
         AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
         AudioSystem::DEVICE_OUT_WIRED_HEADSET |
-        AudioSystem::DEVICE_OUT_WIRED_HEADPHONE)) &&
+        AudioSystem::DEVICE_OUT_WIRED_HEADPHONE |
+        AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET |
+        AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) &&
         (getStrategy((AudioSystem::stream_type)stream) == STRATEGY_SONIFICATION) &&
         streamDesc.mCanBeMuted) {
         volume *= SONIFICATION_HEADSET_VOLUME_FACTOR;
diff --git a/services/java/com/android/server/DockObserver.java b/services/java/com/android/server/DockObserver.java
index bee8872..f993093 100644
--- a/services/java/com/android/server/DockObserver.java
+++ b/services/java/com/android/server/DockObserver.java
@@ -103,7 +103,6 @@
             FileReader file = new FileReader(DOCK_STATE_PATH);
             int len = file.read(buffer, 0, 1024);
             mPreviousDockState = mDockState = Integer.valueOf((new String(buffer, 0, len)).trim());
-
         } catch (FileNotFoundException e) {
             Slog.w(TAG, "This kernel does not have dock station support");
         } catch (Exception e) {
@@ -158,13 +157,17 @@
                         {
                             String whichSound = null;
                             if (mDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
-                                if (mPreviousDockState == Intent.EXTRA_DOCK_STATE_DESK) {
+                                if ((mPreviousDockState == Intent.EXTRA_DOCK_STATE_DESK) ||
+                                    (mPreviousDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) ||
+                                    (mPreviousDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                                     whichSound = Settings.System.DESK_UNDOCK_SOUND;
                                 } else if (mPreviousDockState == Intent.EXTRA_DOCK_STATE_CAR) {
                                     whichSound = Settings.System.CAR_UNDOCK_SOUND;
                                 }
                             } else {
-                                if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
+                                if ((mDockState == Intent.EXTRA_DOCK_STATE_DESK) ||
+                                    (mDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) ||
+                                    (mDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                                     whichSound = Settings.System.DESK_DOCK_SOUND;
                                 } else if (mDockState == Intent.EXTRA_DOCK_STATE_CAR) {
                                     whichSound = Settings.System.CAR_DOCK_SOUND;
diff --git a/services/java/com/android/server/HeadsetObserver.java b/services/java/com/android/server/HeadsetObserver.java
deleted file mode 100644
index 6f0a91d..0000000
--- a/services/java/com/android/server/HeadsetObserver.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package com.android.server;
-
-import android.app.ActivityManagerNative;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Handler;
-import android.os.Message;
-import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
-import android.os.UEventObserver;
-import android.util.Slog;
-import android.media.AudioManager;
-
-import java.io.FileReader;
-import java.io.FileNotFoundException;
-
-/**
- * <p>HeadsetObserver monitors for a wired headset.
- */
-class HeadsetObserver extends UEventObserver {
-    private static final String TAG = HeadsetObserver.class.getSimpleName();
-    private static final boolean LOG = true;
-
-    private static final String HEADSET_UEVENT_MATCH = "DEVPATH=/devices/virtual/switch/h2w";
-    private static final String HEADSET_STATE_PATH = "/sys/class/switch/h2w/state";
-    private static final String HEADSET_NAME_PATH = "/sys/class/switch/h2w/name";
-
-    private static final int BIT_HEADSET = (1 << 0);
-    private static final int BIT_HEADSET_NO_MIC = (1 << 1);
-    private static final int SUPPORTED_HEADSETS = (BIT_HEADSET|BIT_HEADSET_NO_MIC);
-    private static final int HEADSETS_WITH_MIC = BIT_HEADSET;
-
-    private int mHeadsetState;
-    private int mPrevHeadsetState;
-    private String mHeadsetName;
-
-    private final Context mContext;
-    private final WakeLock mWakeLock;  // held while there is a pending route change
-
-    public HeadsetObserver(Context context) {
-        mContext = context;
-        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
-        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "HeadsetObserver");
-        mWakeLock.setReferenceCounted(false);
-
-        startObserving(HEADSET_UEVENT_MATCH);
-
-        init();  // set initial status
-    }
-
-    @Override
-    public void onUEvent(UEventObserver.UEvent event) {
-        if (LOG) Slog.v(TAG, "Headset UEVENT: " + event.toString());
-
-        try {
-            update(event.get("SWITCH_NAME"), Integer.parseInt(event.get("SWITCH_STATE")));
-        } catch (NumberFormatException e) {
-            Slog.e(TAG, "Could not parse switch state from event " + event);
-        }
-    }
-
-    private synchronized final void init() {
-        char[] buffer = new char[1024];
-
-        String newName = mHeadsetName;
-        int newState = mHeadsetState;
-        mPrevHeadsetState = mHeadsetState;
-        try {
-            FileReader file = new FileReader(HEADSET_STATE_PATH);
-            int len = file.read(buffer, 0, 1024);
-            newState = Integer.valueOf((new String(buffer, 0, len)).trim());
-
-            file = new FileReader(HEADSET_NAME_PATH);
-            len = file.read(buffer, 0, 1024);
-            newName = new String(buffer, 0, len).trim();
-
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "This kernel does not have wired headset support");
-        } catch (Exception e) {
-            Slog.e(TAG, "" , e);
-        }
-
-        update(newName, newState);
-    }
-
-    private synchronized final void update(String newName, int newState) {
-        // Retain only relevant bits
-        int headsetState = newState & SUPPORTED_HEADSETS;
-        int newOrOld = headsetState | mHeadsetState;
-        int delay = 0;
-        // reject all suspect transitions: only accept state changes from:
-        // - a: 0 heaset to 1 headset
-        // - b: 1 headset to 0 headset
-        if (mHeadsetState == headsetState || ((newOrOld & (newOrOld - 1)) != 0)) {
-            return;
-        }
-
-        mHeadsetName = newName;
-        mPrevHeadsetState = mHeadsetState;
-        mHeadsetState = headsetState;
-
-        if (headsetState == 0) {
-            Intent intent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
-            mContext.sendBroadcast(intent);
-            // It can take hundreds of ms flush the audio pipeline after
-            // apps pause audio playback, but audio route changes are
-            // immediate, so delay the route change by 1000ms.
-            // This could be improved once the audio sub-system provides an
-            // interface to clear the audio pipeline.
-            delay = 1000;
-        } else {
-            // Insert the same delay for headset connection so that the connection event is not
-            // broadcast before the disconnection event in case of fast removal/insertion
-            if (mHandler.hasMessages(0)) {
-                delay = 1000;
-            }
-        }
-        mWakeLock.acquire();
-        mHandler.sendMessageDelayed(mHandler.obtainMessage(0,
-                                                           mHeadsetState,
-                                                           mPrevHeadsetState,
-                                                           mHeadsetName),
-                                    delay);
-    }
-
-    private synchronized final void sendIntents(int headsetState, int prevHeadsetState, String headsetName) {
-        int allHeadsets = SUPPORTED_HEADSETS;
-        for (int curHeadset = 1; allHeadsets != 0; curHeadset <<= 1) {
-            if ((curHeadset & allHeadsets) != 0) {
-                sendIntent(curHeadset, headsetState, prevHeadsetState, headsetName);
-                allHeadsets &= ~curHeadset;
-            }
-        }
-    }
-
-    private final void sendIntent(int headset, int headsetState, int prevHeadsetState, String headsetName) {
-        if ((headsetState & headset) != (prevHeadsetState & headset)) {
-            //  Pack up the values and broadcast them to everyone
-            Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
-            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-            int state = 0;
-            int microphone = 0;
-
-            if ((headset & HEADSETS_WITH_MIC) != 0) {
-                microphone = 1;
-            }
-            if ((headsetState & headset) != 0) {
-                state = 1;
-            }
-            intent.putExtra("state", state);
-            intent.putExtra("name", headsetName);
-            intent.putExtra("microphone", microphone);
-
-            if (LOG) Slog.v(TAG, "Intent.ACTION_HEADSET_PLUG: state: "+state+" name: "+headsetName+" mic: "+microphone);
-            // TODO: Should we require a permission?
-            ActivityManagerNative.broadcastStickyIntent(intent, null);
-        }
-    }
-
-    private final Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            sendIntents(msg.arg1, msg.arg2, (String)msg.obj);
-            mWakeLock.release();
-        }
-    };
-}
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 07da0fa..155c397 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -993,6 +993,13 @@
                         if (mCurMethod != null) {
                             try {
                                 putSelectedInputMethodSubtype(info, subtypeId);
+                                mCurrentSubtype = subtype;
+                                if (mInputShown) {
+                                    // If mInputShown is false, there is no IME button on the
+                                    // system bar.
+                                    // Thus there is no need to make it invisible explicitly.
+                                    mStatusBar.setIMEButtonVisible(true);
+                                }
                                 mCurMethod.changeInputMethodSubtype(subtype);
                             } catch (RemoteException e) {
                                 return;
@@ -1881,11 +1888,10 @@
             String id = pair.first;
             ArrayList<String> subtypes = pair.second;
             builder.append(id);
-            if (subtypes.size() > 0) {
-                builder.append(subtypes.get(0));
-                for (int i = 1; i < subtypes.size(); ++i) {
-                    builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypes.get(i));
-                }
+            // Inputmethod and subtypes are saved in the settings as follows:
+            // ime0;subtype0;subtype1:ime1;subtype0:ime2:ime3;subtype0;subtype1
+            for (String subtypeId: subtypes) {
+                builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypeId);
             }
         }
 
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 5cf013f..e9a2ebf 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -2219,9 +2219,9 @@
             int eventType, boolean force) {
 
         if (((mPokey & POKE_LOCK_IGNORE_CHEEK_EVENTS) != 0)
-                && (eventType == CHEEK_EVENT || eventType == TOUCH_EVENT)) {
+                && (eventType == CHEEK_EVENT)) {
             if (false) {
-                Slog.d(TAG, "dropping cheek or short event mPokey=0x" + Integer.toHexString(mPokey));
+                Slog.d(TAG, "dropping cheek event mPokey=0x" + Integer.toHexString(mPokey));
             }
             return;
         }
diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java
index 0eeef38..596db57 100644
--- a/services/java/com/android/server/StatusBarManagerService.java
+++ b/services/java/com/android/server/StatusBarManagerService.java
@@ -263,19 +263,20 @@
         if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " IME Button");
 
         synchronized(mLock) {
-            if (mIMEButtonVisible != visible) {
-                mIMEButtonVisible = visible;
-                mHandler.post(new Runnable() {
-                    public void run() {
-                        if (mBar != null) {
-                            try {
-                                mBar.setIMEButtonVisible(visible);
-                            } catch (RemoteException ex) {
-                            }
+            // In case of IME change, we need to call up setIMEButtonVisible() regardless of
+            // mIMEButtonVisible because mIMEButtonVisible may not have been set to false when the
+            // previous IME was destroyed.
+            mIMEButtonVisible = visible;
+            mHandler.post(new Runnable() {
+                public void run() {
+                    if (mBar != null) {
+                        try {
+                            mBar.setIMEButtonVisible(visible);
+                        } catch (RemoteException ex) {
                         }
                     }
-                });
-            }
+                }
+            });
         }
     }
 
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 237ab80..54f7441 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -121,7 +121,7 @@
         WindowManagerService wm = null;
         BluetoothService bluetooth = null;
         BluetoothA2dpService bluetoothA2dp = null;
-        HeadsetObserver headset = null;
+        WiredAccessoryObserver wiredAccessory = null;
         DockObserver dock = null;
         UsbObserver usb = null;
         UiModeManagerService uiMode = null;
@@ -388,14 +388,6 @@
             }
 
             try {
-                Slog.i(TAG, "Headset Observer");
-                // Listen for wired headset changes
-                headset = new HeadsetObserver(context);
-            } catch (Throwable e) {
-                Slog.e(TAG, "Failure starting HeadsetObserver", e);
-            }
-
-            try {
                 Slog.i(TAG, "Dock Observer");
                 // Listen for dock station changes
                 dock = new DockObserver(context, power);
@@ -404,6 +396,14 @@
             }
 
             try {
+                Slog.i(TAG, "Wired Accessory Observer");
+                // Listen for wired headset changes
+                wiredAccessory = new WiredAccessoryObserver(context);
+            } catch (Throwable e) {
+                Slog.e(TAG, "Failure starting WiredAccessoryObserver", e);
+            }
+
+            try {
                 Slog.i(TAG, "USB Observer");
                 // Listen for USB changes
                 usb = new UsbObserver(context);
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 2008215..9687aa7 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -134,12 +134,6 @@
      */
     private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
 
-    /**
-     * Number of allowed radio frequency channels in various regulatory domains.
-     * This list is sufficient for 802.11b/g networks (2.4GHz range).
-     */
-    private static int[] sValidRegulatoryChannelCounts = new int[] {11, 13, 14};
-
     private static final String ACTION_DEVICE_IDLE =
             "com.android.server.WifiManager.action.DEVICE_IDLE";
 
@@ -423,7 +417,12 @@
      */
     public boolean pingSupplicant() {
         enforceAccessPermission();
-        return mWifiStateMachine.syncPingSupplicant();
+        if (mChannel != null) {
+            return mWifiStateMachine.syncPingSupplicant(mChannel);
+        } else {
+            Slog.e(TAG, "mChannel is not initialized");
+            return false;
+        }
     }
 
     /**
@@ -634,7 +633,12 @@
      */
     public int addOrUpdateNetwork(WifiConfiguration config) {
         enforceChangePermission();
-        return mWifiStateMachine.syncAddOrUpdateNetwork(config);
+        if (mChannel != null) {
+            return mWifiStateMachine.syncAddOrUpdateNetwork(mChannel, config);
+        } else {
+            Slog.e(TAG, "mChannel is not initialized");
+            return -1;
+        }
     }
 
      /**
@@ -662,7 +666,12 @@
      */
     public boolean enableNetwork(int netId, boolean disableOthers) {
         enforceChangePermission();
-        return mWifiStateMachine.syncEnableNetwork(netId, disableOthers);
+        if (mChannel != null) {
+            return mWifiStateMachine.syncEnableNetwork(mChannel, netId, disableOthers);
+        } else {
+            Slog.e(TAG, "mChannel is not initialized");
+            return false;
+        }
     }
 
     /**
@@ -673,7 +682,12 @@
      */
     public boolean disableNetwork(int netId) {
         enforceChangePermission();
-        return mWifiStateMachine.syncDisableNetwork(netId);
+        if (mChannel != null) {
+            return mWifiStateMachine.syncDisableNetwork(mChannel, netId);
+        } else {
+            Slog.e(TAG, "mChannel is not initialized");
+            return false;
+        }
     }
 
     /**
@@ -708,86 +722,28 @@
     public boolean saveConfiguration() {
         boolean result = true;
         enforceChangePermission();
-        return mWifiStateMachine.syncSaveConfig();
-    }
-
-    /**
-     * Set the number of radio frequency channels that are allowed to be used
-     * in the current regulatory domain. This method should be used only
-     * if the correct number of channels cannot be determined automatically
-     * for some reason. If the operation is successful, the new value may be
-     * persisted as a Secure setting.
-     * @param numChannels the number of allowed channels. Must be greater than 0
-     * and less than or equal to 16.
-     * @param persist {@code true} if the setting should be remembered.
-     * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g.,
-     * {@code numChannels} is outside the valid range.
-     */
-    public synchronized boolean setNumAllowedChannels(int numChannels, boolean persist) {
-        Slog.i(TAG, "WifiService trying to setNumAllowed to "+numChannels+
-                " with persist set to "+persist);
-        enforceChangePermission();
-
-        /*
-         * Validate the argument. We'd like to let the Wi-Fi driver do this,
-         * but if Wi-Fi isn't currently enabled, that's not possible, and
-         * we want to persist the setting anyway,so that it will take
-         * effect when Wi-Fi does become enabled.
-         */
-        boolean found = false;
-        for (int validChan : sValidRegulatoryChannelCounts) {
-            if (validChan == numChannels) {
-                found = true;
-                break;
-            }
-        }
-        if (!found) {
+        if (mChannel != null) {
+            return mWifiStateMachine.syncSaveConfig(mChannel);
+        } else {
+            Slog.e(TAG, "mChannel is not initialized");
             return false;
         }
-
-        if (persist) {
-            Settings.Secure.putInt(mContext.getContentResolver(),
-                    Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS,
-                    numChannels);
-        }
-
-        mWifiStateMachine.setNumAllowedChannels(numChannels);
-
-        return true;
     }
 
     /**
-     * Return the number of frequency channels that are allowed
-     * to be used in the current regulatory domain.
-     * @return the number of allowed channels, or {@code -1} if an error occurs
+     * Set the country code
+     * @param countryCode ISO 3166 country code.
+     * @param persist {@code true} if the setting should be remembered.
+     *
+     * The persist behavior exists so that wifi can fall back to the last
+     * persisted country code on a restart, when the locale information is
+     * not available from telephony.
      */
-    public int getNumAllowedChannels() {
-        int numChannels;
-
-        enforceAccessPermission();
-
-        /*
-         * If we can't get the value from the driver (e.g., because
-         * Wi-Fi is not currently enabled), get the value from
-         * Settings.
-         */
-        numChannels = mWifiStateMachine.getNumAllowedChannels();
-        if (numChannels < 0) {
-            numChannels = Settings.Secure.getInt(mContext.getContentResolver(),
-                    Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS,
-                    -1);
-        }
-        return numChannels;
-    }
-
-    /**
-     * Return the list of valid values for the number of allowed radio channels
-     * for various regulatory domains.
-     * @return the list of channel counts
-     */
-    public int[] getValidChannelCounts() {
-        enforceAccessPermission();
-        return sValidRegulatoryChannelCounts;
+    public void setCountryCode(String countryCode, boolean persist) {
+        Slog.i(TAG, "WifiService trying to set country code to " + countryCode +
+                " with persist set to " + persist);
+        enforceChangePermission();
+        mWifiStateMachine.setCountryCode(countryCode, persist);
     }
 
     /**
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 55ebded..1cbc8324 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -687,7 +687,7 @@
                     }
                 }
                 if (touchedWin != null) {
-                    if (DEBUG_DRAG) {
+                    if (false && DEBUG_DRAG) {
                         Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
                     }
                     DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
diff --git a/services/java/com/android/server/WiredAccessoryObserver.java b/services/java/com/android/server/WiredAccessoryObserver.java
new file mode 100644
index 0000000..2046473
--- /dev/null
+++ b/services/java/com/android/server/WiredAccessoryObserver.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+package com.android.server;
+
+import android.app.ActivityManagerNative;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+import android.os.UEventObserver;
+import android.util.Slog;
+import android.media.AudioManager;
+import android.util.Log;
+
+import java.io.FileReader;
+import java.io.FileNotFoundException;
+
+/**
+ * <p>WiredAccessoryObserver monitors for a wired headset on the main board or dock.
+ */
+class WiredAccessoryObserver extends UEventObserver {
+    private static final String TAG = WiredAccessoryObserver.class.getSimpleName();
+    private static final boolean LOG = true;
+    private static final int MAX_AUDIO_PORTS = 3; /* h2w, USB Audio & hdmi */
+    private static final String uEventInfo[][] = { {"DEVPATH=/devices/virtual/switch/h2w",
+                                                    "/sys/class/switch/h2w/state",
+                                                    "/sys/class/switch/h2w/name"},
+                                                   {"DEVPATH=/devices/virtual/switch/usb_audio",
+                                                    "/sys/class/switch/usb_audio/state",
+                                                    "/sys/class/switch/usb_audio/name"},
+                                                   {"DEVPATH=/devices/virtual/switch/hdmi",
+                                                    "/sys/class/switch/hdmi/state",
+                                                    "/sys/class/switch/hdmi/name"} };
+
+    private static final int BIT_HEADSET = (1 << 0);
+    private static final int BIT_HEADSET_NO_MIC = (1 << 1);
+    private static final int BIT_USB_HEADSET_ANLG = (1 << 2);
+    private static final int BIT_USB_HEADSET_DGTL = (1 << 3);
+    private static final int BIT_HDMI_AUDIO = (1 << 4);
+    private static final int SUPPORTED_HEADSETS = (BIT_HEADSET|BIT_HEADSET_NO_MIC|
+                                                   BIT_USB_HEADSET_ANLG|BIT_USB_HEADSET_DGTL|
+                                                   BIT_HDMI_AUDIO);
+    private static final int HEADSETS_WITH_MIC = BIT_HEADSET;
+
+    private int mHeadsetState;
+    private int mPrevHeadsetState;
+    private String mHeadsetName;
+    private int switchState;
+
+    private final Context mContext;
+    private final WakeLock mWakeLock;  // held while there is a pending route change
+
+    public WiredAccessoryObserver(Context context) {
+        mContext = context;
+        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WiredAccessoryObserver");
+        mWakeLock.setReferenceCounted(false);
+
+        // At any given time both headsets could be inserted
+        // one on the board and one on the dock
+        // observe two UEVENTs
+        for (int i = 0; i <= MAX_AUDIO_PORTS; i++) {
+            startObserving(uEventInfo[i][0]);
+        }
+        init();  // set initial status
+    }
+
+    @Override
+    public void onUEvent(UEventObserver.UEvent event) {
+        if (LOG) Slog.v(TAG, "Headset UEVENT: " + event.toString());
+
+        try {
+            if ((event.get("SWITCH_NAME")).equals("usb_audio")) {
+                if (Integer.parseInt(event.get("SWITCH_STATE")) == 1) {
+                    switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|
+                                                     BIT_USB_HEADSET_DGTL)) |
+                                   (Integer.parseInt(event.get("SWITCH_STATE")) << 2));
+                } else if (Integer.parseInt(event.get("SWITCH_STATE")) == 2) {
+                    switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|
+                                                     BIT_USB_HEADSET_ANLG)) |
+                                   (Integer.parseInt(event.get("SWITCH_STATE")) << 3));
+                }
+                else switchState = (mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC));
+            }
+            else if ((event.get("SWITCH_NAME")).equals("hdmi")) {
+                switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|
+                                                 BIT_USB_HEADSET_DGTL|BIT_USB_HEADSET_ANLG)) |
+                               (Integer.parseInt(event.get("SWITCH_STATE")) << 4));
+            }
+            else {
+                switchState = ((mHeadsetState & (BIT_USB_HEADSET_ANLG|BIT_USB_HEADSET_DGTL)) |
+                              (Integer.parseInt(event.get("SWITCH_STATE"))));
+            }
+            update(event.get("SWITCH_NAME"), switchState);
+        } catch (NumberFormatException e) {
+            Slog.e(TAG, "Could not parse switch state from event " + event);
+        }
+    }
+
+    private synchronized final void init() {
+        char[] buffer = new char[1024];
+
+        String newName = mHeadsetName;
+        int newState = mHeadsetState;
+        mPrevHeadsetState = mHeadsetState;
+
+        for (int i = 0; i <= MAX_AUDIO_PORTS; i++) {
+            try {
+                FileReader file = new FileReader(uEventInfo[i][1]);
+                int len = file.read(buffer, 0, 1024);
+                newState = Integer.valueOf((new String(buffer, 0, len)).trim());
+
+                file = new FileReader(uEventInfo[i][2]);
+                len = file.read(buffer, 0, 1024);
+                newName = new String(buffer, 0, len).trim();
+
+            } catch (FileNotFoundException e) {
+                Slog.w(TAG, "This kernel does not have wired headset support");
+            } catch (Exception e) {
+                Slog.e(TAG, "" , e);
+            }
+
+            update(newName, newState);
+        }
+    }
+
+    private synchronized final void update(String newName, int newState) {
+        // Retain only relevant bits
+        int headsetState = newState & SUPPORTED_HEADSETS;
+        int newOrOld = headsetState | mHeadsetState;
+        int delay = 0;
+        int usb_headset_anlg = headsetState & BIT_USB_HEADSET_ANLG;
+        int usb_headset_dgtl = headsetState & BIT_USB_HEADSET_DGTL;
+        int h2w_headset = headsetState & (BIT_HEADSET | BIT_HEADSET_NO_MIC);
+        boolean h2wStateChange = true;
+        boolean usbStateChange = true;
+        // reject all suspect transitions: only accept state changes from:
+        // - a: 0 heaset to 1 headset
+        // - b: 1 headset to 0 headset
+        Log.v(TAG, "newState = "+newState+", headsetState = "+headsetState+", mHeadsetState = "+mHeadsetState);
+        if (mHeadsetState == headsetState || ((h2w_headset & (h2w_headset - 1)) != 0)) {
+            Log.e(TAG, "unsetting h2w flag");
+            h2wStateChange = false;
+        }
+        // - c: 0 usb headset to 1 usb headset
+        // - d: 1 usb headset to 0 usb headset
+        if ((usb_headset_anlg >> 2) == 1 && (usb_headset_dgtl >> 3) == 1) {
+            Log.e(TAG, "unsetting usb flag");
+            usbStateChange = false;
+        }
+        if (!h2wStateChange && !usbStateChange) {
+            Log.e(TAG, "invalid transition, returning ...");
+            return;
+        }
+
+        mHeadsetName = newName;
+        mPrevHeadsetState = mHeadsetState;
+        mHeadsetState = headsetState;
+
+        if (headsetState == 0) {
+            Intent intent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
+            mContext.sendBroadcast(intent);
+            // It can take hundreds of ms flush the audio pipeline after
+            // apps pause audio playback, but audio route changes are
+            // immediate, so delay the route change by 1000ms.
+            // This could be improved once the audio sub-system provides an
+            // interface to clear the audio pipeline.
+            delay = 1000;
+        } else {
+            // Insert the same delay for headset connection so that the connection event is not
+            // broadcast before the disconnection event in case of fast removal/insertion
+            if (mHandler.hasMessages(0)) {
+                delay = 1000;
+            }
+        }
+        mWakeLock.acquire();
+        mHandler.sendMessageDelayed(mHandler.obtainMessage(0,
+                                                           mHeadsetState,
+                                                           mPrevHeadsetState,
+                                                           mHeadsetName),
+                                    delay);
+    }
+
+    private synchronized final void sendIntents(int headsetState, int prevHeadsetState, String headsetName) {
+        int allHeadsets = SUPPORTED_HEADSETS;
+        for (int curHeadset = 1; allHeadsets != 0; curHeadset <<= 1) {
+            if ((curHeadset & allHeadsets) != 0) {
+                sendIntent(curHeadset, headsetState, prevHeadsetState, headsetName);
+                allHeadsets &= ~curHeadset;
+            }
+        }
+    }
+
+    private final void sendIntent(int headset, int headsetState, int prevHeadsetState, String headsetName) {
+        if ((headsetState & headset) != (prevHeadsetState & headset)) {
+
+            int state = 0;
+            if ((headsetState & headset) != 0) {
+                state = 1;
+            }
+            if((headset == BIT_USB_HEADSET_ANLG) || (headset == BIT_USB_HEADSET_DGTL) ||
+               (headset == BIT_HDMI_AUDIO)) {
+                Intent intent;
+
+                //  Pack up the values and broadcast them to everyone
+                if (headset == BIT_USB_HEADSET_ANLG) {
+                    intent = new Intent(Intent.ACTION_USB_ANLG_HEADSET_PLUG);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                    intent.putExtra("state", state);
+                    intent.putExtra("name", headsetName);
+                    ActivityManagerNative.broadcastStickyIntent(intent, null);
+                } else if (headset == BIT_USB_HEADSET_DGTL) {
+                    intent = new Intent(Intent.ACTION_USB_DGTL_HEADSET_PLUG);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                    intent.putExtra("state", state);
+                    intent.putExtra("name", headsetName);
+                    ActivityManagerNative.broadcastStickyIntent(intent, null);
+                } else if (headset == BIT_HDMI_AUDIO) {
+                    intent = new Intent(Intent.ACTION_HDMI_AUDIO_PLUG);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                    intent.putExtra("state", state);
+                    intent.putExtra("name", headsetName);
+                    ActivityManagerNative.broadcastStickyIntent(intent, null);
+                }
+
+                if (LOG) Slog.v(TAG, "Intent.ACTION_USB_HEADSET_PLUG: state: "+state+" name: "+headsetName);
+                // TODO: Should we require a permission?
+            }
+            if((headset == BIT_HEADSET) || (headset == BIT_HEADSET_NO_MIC)) {
+
+                //  Pack up the values and broadcast them to everyone
+                Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                //int state = 0;
+                int microphone = 0;
+
+                if ((headset & HEADSETS_WITH_MIC) != 0) {
+                    microphone = 1;
+                }
+
+                intent.putExtra("state", state);
+                intent.putExtra("name", headsetName);
+                intent.putExtra("microphone", microphone);
+
+                if (LOG) Slog.v(TAG, "Intent.ACTION_HEADSET_PLUG: state: "+state+" name: "+headsetName+" mic: "+microphone);
+                // TODO: Should we require a permission?
+                ActivityManagerNative.broadcastStickyIntent(intent, null);
+            }
+        }
+    }
+
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            sendIntents(msg.arg1, msg.arg2, (String)msg.obj);
+            mWakeLock.release();
+        }
+    };
+}
diff --git a/telephony/java/com/android/internal/telephony/MccTable.java b/telephony/java/com/android/internal/telephony/MccTable.java
index 9b0aa3c..c0bf7ec 100644
--- a/telephony/java/com/android/internal/telephony/MccTable.java
+++ b/telephony/java/com/android/internal/telephony/MccTable.java
@@ -48,22 +48,16 @@
         String iso;
         int smallestDigitsMnc;
         String language;
-        int wifiChannels;
 
         MccEntry(int mnc, String iso, int smallestDigitsMCC) {
             this(mnc, iso, smallestDigitsMCC, null);
         }
 
         MccEntry(int mnc, String iso, int smallestDigitsMCC, String language) {
-            this(mnc, iso, smallestDigitsMCC, language, 0);
-        }
-
-        MccEntry(int mnc, String iso, int smallestDigitsMCC, String language, int wifiChannels) {
             this.mcc = mnc;
             this.iso = iso;
             this.smallestDigitsMnc = smallestDigitsMCC;
             this.language = language;
-            this.wifiChannels = wifiChannels;
         }
 
 
@@ -171,23 +165,6 @@
     }
 
     /**
-     * Given a GSM Mobile Country Code, returns the number of wifi
-     * channels allowed in that country.  Returns 0 if unavailable.
-     */
-    public static int
-    wifiChannelsForMcc(int mcc) {
-        MccEntry entry;
-
-        entry = entryForMcc(mcc);
-
-        if (entry == null) {
-            return 0;
-        } else {
-            return entry.wifiChannels;
-        }
-    }
-
-    /**
      * Updates MCC and MNC device configuration information for application retrieving
      * correct version of resources.  If either MCC or MNC is 0, they will be ignored (not set).
      * @param phone PhoneBae to act on.
@@ -210,7 +187,7 @@
             if (mcc != 0) {
                 setTimezoneFromMccIfNeeded(phone, mcc);
                 setLocaleFromMccIfNeeded(phone, mcc);
-                setWifiChannelsFromMcc(phone, mcc);
+                setWifiCountryCodeFromMcc(phone, mcc);
             }
             try {
                 Configuration config = ActivityManagerNative.getDefault().getConfiguration();
@@ -266,14 +243,14 @@
      * @param phone PhoneBase to act on (get context from).
      * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
      */
-    private static void setWifiChannelsFromMcc(PhoneBase phone, int mcc) {
-        int wifiChannels = MccTable.wifiChannelsForMcc(mcc);
-        if (wifiChannels != 0) {
+    private static void setWifiCountryCodeFromMcc(PhoneBase phone, int mcc) {
+        String country = MccTable.countryCodeForMcc(mcc);
+        if (!country.isEmpty()) {
             Context context = phone.getContext();
-            Log.d(LOG_TAG, "WIFI_NUM_ALLOWED_CHANNELS set to " + wifiChannels);
+            Log.d(LOG_TAG, "WIFI_COUNTRY_CODE set to " + country);
             WifiManager wM = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
             //persist
-            wM.setNumAllowedChannels(wifiChannels, true);
+            wM.setCountryCode(country, true);
         }
     }
 
@@ -297,7 +274,7 @@
          */
 
 		table.add(new MccEntry(202,"gr",2));	//Greece
-		table.add(new MccEntry(204,"nl",2,"nl",13));	//Netherlands (Kingdom of the)
+		table.add(new MccEntry(204,"nl",2,"nl"));	//Netherlands (Kingdom of the)
 		table.add(new MccEntry(206,"be",2));	//Belgium
 		table.add(new MccEntry(208,"fr",2,"fr"));	//France
 		table.add(new MccEntry(212,"mc",2));	//Monaco (Principality of)
@@ -311,11 +288,11 @@
 		table.add(new MccEntry(225,"va",2,"it"));	//Vatican City State
 		table.add(new MccEntry(226,"ro",2));	//Romania
 		table.add(new MccEntry(228,"ch",2,"de"));	//Switzerland (Confederation of)
-		table.add(new MccEntry(230,"cz",2,"cs",13));	//Czech Republic
+		table.add(new MccEntry(230,"cz",2,"cs"));	//Czech Republic
 		table.add(new MccEntry(231,"sk",2));	//Slovak Republic
-		table.add(new MccEntry(232,"at",2,"de",13));	//Austria
-		table.add(new MccEntry(234,"gb",2,"en",13));	//United Kingdom of Great Britain and Northern Ireland
-		table.add(new MccEntry(235,"gb",2,"en",13));	//United Kingdom of Great Britain and Northern Ireland
+		table.add(new MccEntry(232,"at",2,"de"));	//Austria
+		table.add(new MccEntry(234,"gb",2,"en"));	//United Kingdom of Great Britain and Northern Ireland
+		table.add(new MccEntry(235,"gb",2,"en"));	//United Kingdom of Great Britain and Northern Ireland
 		table.add(new MccEntry(238,"dk",2));	//Denmark
 		table.add(new MccEntry(240,"se",2));	//Sweden
 		table.add(new MccEntry(242,"no",2));	//Norway
@@ -328,7 +305,7 @@
 		table.add(new MccEntry(257,"by",2));	//Belarus (Republic of)
 		table.add(new MccEntry(259,"md",2));	//Moldova (Republic of)
 		table.add(new MccEntry(260,"pl",2));	//Poland (Republic of)
-		table.add(new MccEntry(262,"de",2,"de",13));	//Germany (Federal Republic of)
+		table.add(new MccEntry(262,"de",2,"de"));	//Germany (Federal Republic of)
 		table.add(new MccEntry(266,"gi",2));	//Gibraltar
 		table.add(new MccEntry(268,"pt",2));	//Portugal
 		table.add(new MccEntry(270,"lu",2));	//Luxembourg
@@ -349,15 +326,15 @@
                 table.add(new MccEntry(294,"mk",2));   //The Former Yugoslav Republic of Macedonia
 		table.add(new MccEntry(295,"li",2));	//Liechtenstein (Principality of)
                 table.add(new MccEntry(297,"me",2));    //Montenegro (Republic of)
-		table.add(new MccEntry(302,"ca",3,"",11));	//Canada
+		table.add(new MccEntry(302,"ca",3,""));	//Canada
 		table.add(new MccEntry(308,"pm",2));	//Saint Pierre and Miquelon (Collectivit territoriale de la Rpublique franaise)
-		table.add(new MccEntry(310,"us",3,"en",11));	//United States of America
-		table.add(new MccEntry(311,"us",3,"en",11));	//United States of America
-		table.add(new MccEntry(312,"us",3,"en",11));	//United States of America
-		table.add(new MccEntry(313,"us",3,"en",11));	//United States of America
-		table.add(new MccEntry(314,"us",3,"en",11));	//United States of America
-		table.add(new MccEntry(315,"us",3,"en",11));	//United States of America
-		table.add(new MccEntry(316,"us",3,"en",11));	//United States of America
+		table.add(new MccEntry(310,"us",3,"en"));	//United States of America
+		table.add(new MccEntry(311,"us",3,"en"));	//United States of America
+		table.add(new MccEntry(312,"us",3,"en"));	//United States of America
+		table.add(new MccEntry(313,"us",3,"en"));	//United States of America
+		table.add(new MccEntry(314,"us",3,"en"));	//United States of America
+		table.add(new MccEntry(315,"us",3,"en"));	//United States of America
+		table.add(new MccEntry(316,"us",3,"en"));	//United States of America
 		table.add(new MccEntry(330,"pr",2));	//Puerto Rico
 		table.add(new MccEntry(332,"vi",2));	//United States Virgin Islands
 		table.add(new MccEntry(334,"mx",3));	//Mexico
@@ -414,27 +391,27 @@
 		table.add(new MccEntry(436,"tj",2));	//Tajikistan (Republic of)
 		table.add(new MccEntry(437,"kg",2));	//Kyrgyz Republic
 		table.add(new MccEntry(438,"tm",2));	//Turkmenistan
-		table.add(new MccEntry(440,"jp",2,"ja",14));	//Japan
-		table.add(new MccEntry(441,"jp",2,"ja",14));	//Japan
-		table.add(new MccEntry(450,"kr",2,"ko",13));	//Korea (Republic of)
+		table.add(new MccEntry(440,"jp",2,"ja"));	//Japan
+		table.add(new MccEntry(441,"jp",2,"ja"));	//Japan
+		table.add(new MccEntry(450,"kr",2,"ko"));	//Korea (Republic of)
 		table.add(new MccEntry(452,"vn",2));	//Viet Nam (Socialist Republic of)
 		table.add(new MccEntry(454,"hk",2));	//"Hong Kong, China"
 		table.add(new MccEntry(455,"mo",2));	//"Macao, China"
 		table.add(new MccEntry(456,"kh",2));	//Cambodia (Kingdom of)
 		table.add(new MccEntry(457,"la",2));	//Lao People's Democratic Republic
-		table.add(new MccEntry(460,"cn",2,"zh",13));	//China (People's Republic of)
-		table.add(new MccEntry(461,"cn",2,"zh",13));	//China (People's Republic of)
+		table.add(new MccEntry(460,"cn",2,"zh"));	//China (People's Republic of)
+		table.add(new MccEntry(461,"cn",2,"zh"));	//China (People's Republic of)
 		table.add(new MccEntry(466,"tw",2));	//"Taiwan, China"
 		table.add(new MccEntry(467,"kp",2));	//Democratic People's Republic of Korea
 		table.add(new MccEntry(470,"bd",2));	//Bangladesh (People's Republic of)
 		table.add(new MccEntry(472,"mv",2));	//Maldives (Republic of)
 		table.add(new MccEntry(502,"my",2));	//Malaysia
-		table.add(new MccEntry(505,"au",2,"en",11));	//Australia
+		table.add(new MccEntry(505,"au",2,"en"));	//Australia
 		table.add(new MccEntry(510,"id",2));	//Indonesia (Republic of)
 		table.add(new MccEntry(514,"tl",2));	//Democratic Republic of Timor-Leste
 		table.add(new MccEntry(515,"ph",2));	//Philippines (Republic of the)
 		table.add(new MccEntry(520,"th",2));	//Thailand
-		table.add(new MccEntry(525,"sg",2,"en",11));	//Singapore (Republic of)
+		table.add(new MccEntry(525,"sg",2,"en"));	//Singapore (Republic of)
 		table.add(new MccEntry(528,"bn",2));	//Brunei Darussalam
 		table.add(new MccEntry(530,"nz",2, "en"));	//New Zealand
 		table.add(new MccEntry(534,"mp",2));	//Northern Mariana Islands (Commonwealth of the)
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index 554a7ba..dddb493 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -558,11 +558,6 @@
             String c = carrierLocales[i].toString();
             if (carrier.equals(c)) {
                 String l = carrierLocales[i+1].toString();
-                int wifiChannels = 0;
-                try {
-                    wifiChannels = Integer.parseInt(
-                            carrierLocales[i+2].toString());
-                } catch (NumberFormatException e) { }
 
                 String language = l.substring(0, 2);
                 String country = "";
@@ -571,15 +566,15 @@
                 }
                 setSystemLocale(language, country);
 
-                if (wifiChannels != 0) {
+                if (!country.isEmpty()) {
                     try {
                         Settings.Secure.getInt(mContext.getContentResolver(),
-                                Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS);
+                                Settings.Secure.WIFI_COUNTRY_CODE);
                     } catch (Settings.SettingNotFoundException e) {
                         // note this is not persisting
                         WifiManager wM = (WifiManager)
                                 mContext.getSystemService(Context.WIFI_SERVICE);
-                        wM.setNumAllowedChannels(wifiChannels, false);
+                        wM.setCountryCode(country, false);
                     }
                 }
                 return;
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java
index 7eb3df8..868c76d 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java
@@ -72,16 +72,4 @@
         assertEquals(MccTable.smallestDigitsMccForMnc(0), 2);    // mcc not defined, hence default
         assertEquals(MccTable.smallestDigitsMccForMnc(2000), 2); // mcc not defined, hence default
     }
-
-    @SmallTest
-    public void testWifi() throws Exception {
-        assertEquals(MccTable.wifiChannelsForMcc(262), 13);
-        assertEquals(MccTable.wifiChannelsForMcc(234), 13);
-        assertEquals(MccTable.wifiChannelsForMcc(505), 11);
-        assertEquals(MccTable.wifiChannelsForMcc(313), 11);
-        assertEquals(MccTable.wifiChannelsForMcc(330), 0);  // wifi not defined, hence default
-        assertEquals(MccTable.wifiChannelsForMcc(0), 0);    // mcc not defined, hence default
-        assertEquals(MccTable.wifiChannelsForMcc(2000), 0); // mcc not defined, hence default
-
-    }
 }
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 196b0eb..7f3a968 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -17,6 +17,8 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.test.hwui">
 
+    <uses-permission android:name="android.permission.INTERNET" />    
+    
     <application
         android:label="HwUi"
         android:hardwareAccelerated="true">
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapShader.java b/tools/layoutlib/bridge/src/android/graphics/BitmapShader.java
deleted file mode 100644
index ad3974c..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/BitmapShader.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package android.graphics;
-
-import java.awt.Paint;
-
-public class BitmapShader extends Shader {
-
-    // we hold on just for the GC, since our native counterpart is using it
-    private final Bitmap mBitmap;
-
-    /**
-     * Call this to create a new shader that will draw with a bitmap.
-     *
-     * @param bitmap            The bitmap to use inside the shader
-     * @param tileX             The tiling mode for x to draw the bitmap in.
-     * @param tileY             The tiling mode for y to draw the bitmap in.
-     */
-    public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) {
-        mBitmap = bitmap;
-    }
-
-    //---------- Custom methods
-
-    public Bitmap getBitmap() {
-        return mBitmap;
-    }
-
-    @Override
-    Paint getJavaPaint() {
-        return null;
-    }
-}
-
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index 24fba72..e97b1e6 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -60,6 +60,20 @@
     // ---- Public Helper methods ----
 
     /**
+     * Returns the native delegate associated to a given {@link Bitmap_Delegate} object.
+     */
+    public static Bitmap_Delegate getDelegate(Bitmap bitmap) {
+        return sManager.getDelegate(bitmap.mNativeBitmap);
+    }
+
+    /**
+     * Returns the native delegate associated to a given an int referencing a {@link Bitmap} object.
+     */
+    public static Bitmap_Delegate getDelegate(int native_bitmap) {
+        return sManager.getDelegate(native_bitmap);
+    }
+
+    /**
      * Creates and returns a {@link Bitmap} initialized with the given file content.
      */
     public static Bitmap createBitmap(File input, Density density) throws IOException {
@@ -118,6 +132,13 @@
         return BufferedImage.TYPE_INT_ARGB;
     }
 
+    /**
+     * Returns the {@link BufferedImage} used by the delegate of the given {@link Bitmap}.
+     */
+    public BufferedImage getImage() {
+        return mImage;
+    }
+
     // ---- native methods ----
 
     /*package*/ static Bitmap nativeCreate(int[] colors, int offset, int stride, int width,
@@ -127,8 +148,7 @@
         // create the image
         BufferedImage image = new BufferedImage(width, height, imageType);
 
-        // fill it
-        //image.setRGB(x, y, rgb)
+        // FIXME fill the bitmap!
 
         // create a delegate with the content of the stream.
         Bitmap_Delegate delegate = new Bitmap_Delegate(image);
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas.java b/tools/layoutlib/bridge/src/android/graphics/Canvas.java
deleted file mode 100644
index 24da812..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas.java
+++ /dev/null
@@ -1,1247 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package android.graphics;
-
-import com.android.layoutlib.api.ILayoutLog;
-
-import android.graphics.Paint.Align;
-import android.graphics.Paint.FontInfo;
-import android.graphics.Paint.Style;
-import android.graphics.Region.Op;
-
-import java.awt.AlphaComposite;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Composite;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.util.List;
-import java.util.Stack;
-
-/**
- * Re-implementation of the Canvas, 100% in java on top of a BufferedImage.
- */
-public class Canvas extends _Original_Canvas {
-
-    private BufferedImage mBufferedImage;
-    private final Stack<Graphics2D> mGraphicsStack = new Stack<Graphics2D>();
-    private final ILayoutLog mLogger;
-
-    public Canvas() {
-        mLogger = null;
-        // the mBufferedImage will be taken from a bitmap in #setBitmap()
-    }
-
-    public Canvas(Bitmap bitmap) {
-        mLogger = null;
-        mBufferedImage = Bitmap_Delegate.getImage(bitmap);
-        mGraphicsStack.push(mBufferedImage.createGraphics());
-    }
-
-    public Canvas(int nativeCanvas) {
-        mLogger = null;
-        throw new UnsupportedOperationException("Can't create Canvas(int)");
-    }
-
-    // custom constructors for our use.
-    public Canvas(int width, int height, ILayoutLog logger) {
-        mLogger = logger;
-        mBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
-        mGraphicsStack.push(mBufferedImage.createGraphics());
-    }
-
-    public Canvas(int width, int height) {
-        this(width, height, null /* logger*/);
-    }
-
-    // custom mehtods
-    public BufferedImage getImage() {
-        return mBufferedImage;
-    }
-
-    public Graphics2D getGraphics2d() {
-        return mGraphicsStack.peek();
-    }
-
-    public void dispose() {
-        while (mGraphicsStack.size() > 0) {
-            mGraphicsStack.pop().dispose();
-        }
-    }
-
-    /**
-     * Creates a new {@link Graphics2D} based on the {@link Paint} parameters.
-     * <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used.
-     */
-    private Graphics2D getCustomGraphics(Paint paint) {
-        // make new one
-        Graphics2D g = getGraphics2d();
-        g = (Graphics2D)g.create();
-
-        // configure it
-        g.setColor(new Color(paint.getColor()));
-        int alpha = paint.getAlpha();
-        float falpha = alpha / 255.f;
-
-        Style style = paint.getStyle();
-        if (style == Style.STROKE || style == Style.FILL_AND_STROKE) {
-            PathEffect e = paint.getPathEffect();
-            if (e instanceof DashPathEffect) {
-                DashPathEffect dpe = (DashPathEffect)e;
-                g.setStroke(new BasicStroke(
-                        paint.getStrokeWidth(),
-                        paint.getStrokeCap().getJavaCap(),
-                        paint.getStrokeJoin().getJavaJoin(),
-                        paint.getStrokeMiter(),
-                        dpe.getIntervals(),
-                        dpe.getPhase()));
-            } else {
-                g.setStroke(new BasicStroke(
-                        paint.getStrokeWidth(),
-                        paint.getStrokeCap().getJavaCap(),
-                        paint.getStrokeJoin().getJavaJoin(),
-                        paint.getStrokeMiter()));
-            }
-        }
-
-        Xfermode xfermode = paint.getXfermode();
-        if (xfermode instanceof PorterDuffXfermode) {
-            PorterDuff.Mode mode = ((PorterDuffXfermode)xfermode).getMode();
-
-            setModeInGraphics(mode, g, falpha);
-        } else {
-            if (mLogger != null && xfermode != null) {
-                mLogger.warning(String.format(
-                        "Xfermode '%1$s' is not supported in the Layout Editor.",
-                        xfermode.getClass().getCanonicalName()));
-            }
-            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
-        }
-
-        Shader shader = paint.getShader();
-        if (shader != null) {
-            java.awt.Paint shaderPaint = shader.getJavaPaint();
-            if (shaderPaint != null) {
-                g.setPaint(shaderPaint);
-            } else {
-                if (mLogger != null) {
-                    mLogger.warning(String.format(
-                            "Shader '%1$s' is not supported in the Layout Editor.",
-                            shader.getClass().getCanonicalName()));
-                }
-            }
-        }
-
-        return g;
-    }
-
-    private void setModeInGraphics(PorterDuff.Mode mode, Graphics2D g, float falpha) {
-        switch (mode) {
-            case CLEAR:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, falpha));
-                break;
-            case DARKEN:
-                break;
-            case DST:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST, falpha));
-                break;
-            case DST_ATOP:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_ATOP, falpha));
-                break;
-            case DST_IN:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, falpha));
-                break;
-            case DST_OUT:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT, falpha));
-                break;
-            case DST_OVER:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, falpha));
-                break;
-            case LIGHTEN:
-                break;
-            case MULTIPLY:
-                break;
-            case SCREEN:
-                break;
-            case SRC:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, falpha));
-                break;
-            case SRC_ATOP:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, falpha));
-                break;
-            case SRC_IN:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, falpha));
-                break;
-            case SRC_OUT:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT, falpha));
-                break;
-            case SRC_OVER:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
-                break;
-            case XOR:
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, falpha));
-                break;
-        }
-    }
-
-
-    // --------------------
-    // OVERRIDEN ENUMS
-    // This is needed since we rename Canvas into _Original_Canvas
-    // --------------------
-
-    public enum EdgeType {
-        BW(0),  //!< treat edges by just rounding to nearest pixel boundary
-        AA(1);  //!< treat edges by rounding-out, since they may be antialiased
-
-        EdgeType(int nativeInt) {
-            this.nativeInt = nativeInt;
-        }
-        final int nativeInt;
-    }
-
-
-    // --------------------
-    // OVERRIDEN METHODS
-    // --------------------
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#setBitmap(android.graphics.Bitmap)
-     */
-    @Override
-    public void setBitmap(Bitmap bitmap) {
-        mBufferedImage = Bitmap_Delegate.getImage(bitmap);
-        mGraphicsStack.push(mBufferedImage.createGraphics());
-    }
-
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#translate(float, float)
-     */
-    @Override
-    public void translate(float dx, float dy) {
-        getGraphics2d().translate(dx, dy);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#save()
-     */
-    @Override
-    public int save() {
-        // get the current save count
-        int count = mGraphicsStack.size();
-
-        // create a new graphics and add it to the stack
-        Graphics2D g = (Graphics2D)getGraphics2d().create();
-        mGraphicsStack.push(g);
-
-        // return the old save count
-        return count;
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#save(int)
-     */
-    @Override
-    public int save(int saveFlags) {
-        // For now we ignore saveFlags
-        return save();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#restore()
-     */
-    @Override
-    public void restore() {
-        mGraphicsStack.pop();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#restoreToCount(int)
-     */
-    @Override
-    public void restoreToCount(int saveCount) {
-        while (mGraphicsStack.size() > saveCount) {
-            mGraphicsStack.pop();
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#getSaveCount()
-     */
-    @Override
-    public int getSaveCount() {
-        return mGraphicsStack.size();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(float, float, float, float, android.graphics.Region.Op)
-     */
-    @Override
-    public boolean clipRect(float left, float top, float right, float bottom, Op op) {
-        return clipRect(left, top, right, bottom);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(float, float, float, float)
-     */
-    @Override
-    public boolean clipRect(float left, float top, float right, float bottom) {
-        getGraphics2d().clipRect((int)left, (int)top, (int)(right-left), (int)(bottom-top));
-        return true;
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(int, int, int, int)
-     */
-    @Override
-    public boolean clipRect(int left, int top, int right, int bottom) {
-        getGraphics2d().clipRect(left, top, right-left, bottom-top);
-        return true;
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(android.graphics.Rect, android.graphics.Region.Op)
-     */
-    @Override
-    public boolean clipRect(Rect rect, Op op) {
-        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(android.graphics.Rect)
-     */
-    @Override
-    public boolean clipRect(Rect rect) {
-        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(android.graphics.RectF, android.graphics.Region.Op)
-     */
-    @Override
-    public boolean clipRect(RectF rect, Op op) {
-        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRect(android.graphics.RectF)
-     */
-    @Override
-    public boolean clipRect(RectF rect) {
-        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
-    }
-
-    public boolean quickReject(RectF rect, EdgeType type) {
-        return false;
-    }
-
-    @Override
-    public boolean quickReject(RectF rect, _Original_Canvas.EdgeType type) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    public boolean quickReject(Path path, EdgeType type) {
-        return false;
-    }
-
-    @Override
-    public boolean quickReject(Path path, _Original_Canvas.EdgeType type) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    public boolean quickReject(float left, float top, float right, float bottom,
-                               EdgeType type) {
-        return false;
-    }
-
-    @Override
-    public boolean quickReject(float left, float top, float right, float bottom,
-                               _Original_Canvas.EdgeType type) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    /**
-     * Retrieve the clip bounds, returning true if they are non-empty.
-     *
-     * @param bounds Return the clip bounds here. If it is null, ignore it but
-     *               still return true if the current clip is non-empty.
-     * @return true if the current clip is non-empty.
-     */
-    @Override
-    public boolean getClipBounds(Rect bounds) {
-        Rectangle rect = getGraphics2d().getClipBounds();
-        if (rect != null) {
-            bounds.left = rect.x;
-            bounds.top = rect.y;
-            bounds.right = rect.x + rect.width;
-            bounds.bottom = rect.y + rect.height;
-            return true;
-        }
-        return false;
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawColor(int, android.graphics.PorterDuff.Mode)
-     */
-    @Override
-    public void drawColor(int color, PorterDuff.Mode mode) {
-        Graphics2D g = getGraphics2d();
-
-        // save old color
-        Color c = g.getColor();
-
-        Composite composite = g.getComposite();
-
-        // get the alpha from the color
-        int alpha = color >>> 24;
-        float falpha = alpha / 255.f;
-
-        setModeInGraphics(mode, g, falpha);
-
-        g.setColor(new Color(color));
-
-        g.fillRect(0, 0, getWidth(), getHeight());
-
-        g.setComposite(composite);
-
-        // restore color
-        g.setColor(c);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawColor(int)
-     */
-    @Override
-    public void drawColor(int color) {
-        drawColor(color, PorterDuff.Mode.SRC_OVER);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawARGB(int, int, int, int)
-     */
-    @Override
-    public void drawARGB(int a, int r, int g, int b) {
-        drawColor(a << 24 | r << 16 | g << 8 | b, PorterDuff.Mode.SRC_OVER);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawRGB(int, int, int)
-     */
-    @Override
-    public void drawRGB(int r, int g, int b) {
-        drawColor(0xFF << 24 | r << 16 | g << 8 | b, PorterDuff.Mode.SRC_OVER);
-    }
-
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#getWidth()
-     */
-    @Override
-    public int getWidth() {
-        return mBufferedImage.getWidth();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#getHeight()
-     */
-    @Override
-    public int getHeight() {
-        return mBufferedImage.getHeight();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPaint(android.graphics.Paint)
-     */
-    @Override
-    public void drawPaint(Paint paint) {
-        drawColor(paint.getColor());
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawBitmap(android.graphics.Bitmap, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
-        drawBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
-                (int)left, (int)top,
-                (int)left+bitmap.getWidth(), (int)top+bitmap.getHeight(), paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawBitmap(android.graphics.Bitmap, android.graphics.Matrix, android.graphics.Paint)
-     */
-    @Override
-    public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
-        boolean needsRestore = false;
-        if (matrix.isIdentity() == false) {
-            // create a new graphics and apply the matrix to it
-            save(); // this creates a new Graphics2D, and stores it for children call to use
-            needsRestore = true;
-            Graphics2D g = getGraphics2d(); // get the newly create Graphics2D
-
-            // get the Graphics2D current matrix
-            AffineTransform currentTx = g.getTransform();
-            // get the AffineTransform from the matrix
-            AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(matrix);
-
-            // combine them so that the matrix is applied after.
-            currentTx.preConcatenate(matrixTx);
-
-            // give it to the graphics as a new matrix replacing all previous transform
-            g.setTransform(currentTx);
-        }
-
-        // draw the bitmap
-        drawBitmap(bitmap, 0, 0, paint);
-
-        if (needsRestore) {
-            // remove the new graphics
-            restore();
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawBitmap(android.graphics.Bitmap, android.graphics.Rect, android.graphics.Rect, android.graphics.Paint)
-     */
-    @Override
-    public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
-        if (src == null) {
-            drawBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
-                    dst.left, dst.top, dst.right, dst.bottom, paint);
-        } else {
-            drawBitmap(bitmap, src.left, src.top, src.width(), src.height(),
-                    dst.left, dst.top, dst.right, dst.bottom, paint);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawBitmap(android.graphics.Bitmap, android.graphics.Rect, android.graphics.RectF, android.graphics.Paint)
-     */
-    @Override
-    public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
-        if (src == null) {
-            drawBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
-                    (int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom, paint);
-        } else {
-            drawBitmap(bitmap, src.left, src.top, src.width(), src.height(),
-                    (int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom, paint);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawBitmap(int[], int, int, int, int, int, int, boolean, android.graphics.Paint)
-     */
-    @Override
-    public void drawBitmap(int[] colors, int offset, int stride, int x, int y, int width,
-            int height, boolean hasAlpha, Paint paint) {
-        throw new UnsupportedOperationException();
-    }
-
-    private void drawBitmap(Bitmap bitmap, int sleft, int stop, int sright, int sbottom, int dleft,
-            int dtop, int dright, int dbottom, Paint paint) {
-        BufferedImage image = Bitmap_Delegate.getImage(bitmap);
-
-        Graphics2D g = getGraphics2d();
-
-        Composite c = null;
-
-        if (paint != null) {
-            if (paint.isFilterBitmap()) {
-                g = (Graphics2D)g.create();
-                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-                        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-            }
-
-            if (paint.getAlpha() != 0xFF) {
-                c = g.getComposite();
-                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
-                        paint.getAlpha()/255.f));
-            }
-        }
-
-        g.drawImage(image, dleft, dtop, dright, dbottom,
-                sleft, stop, sright, sbottom, null);
-
-        if (paint != null) {
-            if (paint.isFilterBitmap()) {
-                g.dispose();
-            }
-            if (c != null) {
-                g.setComposite(c);
-            }
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#rotate(float, float, float)
-     */
-    @Override
-    public void rotate(float degrees, float px, float py) {
-        if (degrees != 0) {
-            Graphics2D g = getGraphics2d();
-            g.translate(px, py);
-            g.rotate(Math.toRadians(degrees));
-            g.translate(-px, -py);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#rotate(float)
-     */
-    @Override
-    public void rotate(float degrees) {
-        getGraphics2d().rotate(Math.toRadians(degrees));
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#scale(float, float, float, float)
-     */
-    @Override
-    public void scale(float sx, float sy, float px, float py) {
-        Graphics2D g = getGraphics2d();
-        g.translate(px, py);
-        g.scale(sx, sy);
-        g.translate(-px, -py);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#scale(float, float)
-     */
-    @Override
-    public void scale(float sx, float sy) {
-        getGraphics2d().scale(sx, sy);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawText(char[], int, int, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawText(char[] text, int index, int count, float x, float y, Paint paint) {
-        // WARNING: the logic in this method is similar to Paint.measureText.
-        // Any change to this method should be reflected in Paint.measureText
-        Graphics2D g = getGraphics2d();
-
-        g = (Graphics2D)g.create();
-        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
-        // set the color. because this only handles RGB, the alpha channel is handled
-        // as a composite.
-        g.setColor(new Color(paint.getColor()));
-        int alpha = paint.getAlpha();
-        float falpha = alpha / 255.f;
-        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
-
-
-        // Paint.TextAlign indicates how the text is positioned relative to X.
-        // LEFT is the default and there's nothing to do.
-        if (paint.getTextAlign() != Align.LEFT) {
-            float m = paint.measureText(text, index, count);
-            if (paint.getTextAlign() == Align.CENTER) {
-                x -= m / 2;
-            } else if (paint.getTextAlign() == Align.RIGHT) {
-                x -= m;
-            }
-        }
-
-        List<FontInfo> fonts = paint.getFonts();
-        try {
-            if (fonts.size() > 0) {
-                FontInfo mainFont = fonts.get(0);
-                int i = index;
-                int lastIndex = index + count;
-                while (i < lastIndex) {
-                    // always start with the main font.
-                    int upTo = mainFont.mFont.canDisplayUpTo(text, i, lastIndex);
-                    if (upTo == -1) {
-                        // draw all the rest and exit.
-                        g.setFont(mainFont.mFont);
-                        g.drawChars(text, i, lastIndex - i, (int)x, (int)y);
-                        return;
-                    } else if (upTo > 0) {
-                        // draw what's possible
-                        g.setFont(mainFont.mFont);
-                        g.drawChars(text, i, upTo - i, (int)x, (int)y);
-
-                        // compute the width that was drawn to increase x
-                        x += mainFont.mMetrics.charsWidth(text, i, upTo - i);
-
-                        // move index to the first non displayed char.
-                        i = upTo;
-
-                        // don't call continue at this point. Since it is certain the main font
-                        // cannot display the font a index upTo (now ==i), we move on to the
-                        // fallback fonts directly.
-                    }
-
-                    // no char supported, attempt to read the next char(s) with the
-                    // fallback font. In this case we only test the first character
-                    // and then go back to test with the main font.
-                    // Special test for 2-char characters.
-                    boolean foundFont = false;
-                    for (int f = 1 ; f < fonts.size() ; f++) {
-                        FontInfo fontInfo = fonts.get(f);
-
-                        // need to check that the font can display the character. We test
-                        // differently if the char is a high surrogate.
-                        int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1;
-                        upTo = fontInfo.mFont.canDisplayUpTo(text, i, i + charCount);
-                        if (upTo == -1) {
-                            // draw that char
-                            g.setFont(fontInfo.mFont);
-                            g.drawChars(text, i, charCount, (int)x, (int)y);
-
-                            // update x
-                            x += fontInfo.mMetrics.charsWidth(text, i, charCount);
-
-                            // update the index in the text, and move on
-                            i += charCount;
-                            foundFont = true;
-                            break;
-
-                        }
-                    }
-
-                    // in case no font can display the char, display it with the main font.
-                    // (it'll put a square probably)
-                    if (foundFont == false) {
-                        int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1;
-
-                        g.setFont(mainFont.mFont);
-                        g.drawChars(text, i, charCount, (int)x, (int)y);
-
-                        // measure it to advance x
-                        x += mainFont.mMetrics.charsWidth(text, i, charCount);
-
-                        // and move to the next chars.
-                        i += charCount;
-                    }
-                }
-            }
-        } finally {
-            g.dispose();
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawText(java.lang.CharSequence, int, int, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
-        drawText(text.toString().toCharArray(), start, end - start, x, y, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawText(java.lang.String, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawText(String text, float x, float y, Paint paint) {
-        drawText(text.toCharArray(), 0, text.length(), x, y, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawText(java.lang.String, int, int, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawText(String text, int start, int end, float x, float y, Paint paint) {
-        drawText(text.toCharArray(), start, end - start, x, y, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawRect(android.graphics.RectF, android.graphics.Paint)
-     */
-    @Override
-    public void drawRect(RectF rect, Paint paint) {
-        doDrawRect((int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(), paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawRect(float, float, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawRect(float left, float top, float right, float bottom, Paint paint) {
-        doDrawRect((int)left, (int)top, (int)(right-left), (int)(bottom-top), paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawRect(android.graphics.Rect, android.graphics.Paint)
-     */
-    @Override
-    public void drawRect(Rect r, Paint paint) {
-        doDrawRect(r.left, r.top, r.width(), r.height(), paint);
-    }
-
-    private final void doDrawRect(int left, int top, int width, int height, Paint paint) {
-        if (width > 0 && height > 0) {
-            // get a Graphics2D object configured with the drawing parameters.
-            Graphics2D g = getCustomGraphics(paint);
-
-            Style style = paint.getStyle();
-
-            // draw
-            if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
-                g.fillRect(left, top, width, height);
-            }
-
-            if (style == Style.STROKE || style == Style.FILL_AND_STROKE) {
-                g.drawRect(left, top, width, height);
-            }
-
-            // dispose Graphics2D object
-            g.dispose();
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawRoundRect(android.graphics.RectF, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {
-        if (rect.width() > 0 && rect.height() > 0) {
-            // get a Graphics2D object configured with the drawing parameters.
-            Graphics2D g = getCustomGraphics(paint);
-
-            Style style = paint.getStyle();
-
-            // draw
-
-            int arcWidth = (int)(rx * 2);
-            int arcHeight = (int)(ry * 2);
-
-            if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
-                g.fillRoundRect((int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(),
-                        arcWidth, arcHeight);
-            }
-
-            if (style == Style.STROKE || style == Style.FILL_AND_STROKE) {
-                g.drawRoundRect((int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(),
-                        arcWidth, arcHeight);
-            }
-
-            // dispose Graphics2D object
-            g.dispose();
-        }
-    }
-
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawLine(float, float, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
-        // get a Graphics2D object configured with the drawing parameters.
-        Graphics2D g = getCustomGraphics(paint);
-
-        g.drawLine((int)startX, (int)startY, (int)stopX, (int)stopY);
-
-        // dispose Graphics2D object
-        g.dispose();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawLines(float[], int, int, android.graphics.Paint)
-     */
-    @Override
-    public void drawLines(float[] pts, int offset, int count, Paint paint) {
-        // get a Graphics2D object configured with the drawing parameters.
-        Graphics2D g = getCustomGraphics(paint);
-
-        for (int i = 0 ; i < count ; i += 4) {
-            g.drawLine((int)pts[i + offset], (int)pts[i + offset + 1],
-                    (int)pts[i + offset + 2], (int)pts[i + offset + 3]);
-        }
-
-        // dispose Graphics2D object
-        g.dispose();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawLines(float[], android.graphics.Paint)
-     */
-    @Override
-    public void drawLines(float[] pts, Paint paint) {
-        drawLines(pts, 0, pts.length, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawCircle(float, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawCircle(float cx, float cy, float radius, Paint paint) {
-        // get a Graphics2D object configured with the drawing parameters.
-        Graphics2D g = getCustomGraphics(paint);
-
-        Style style = paint.getStyle();
-
-        int size = (int)(radius * 2);
-
-        // draw
-        if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
-            g.fillOval((int)(cx - radius), (int)(cy - radius), size, size);
-        }
-
-        if (style == Style.STROKE || style == Style.FILL_AND_STROKE) {
-            g.drawOval((int)(cx - radius), (int)(cy - radius), size, size);
-        }
-
-        // dispose Graphics2D object
-        g.dispose();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawOval(android.graphics.RectF, android.graphics.Paint)
-     */
-    @Override
-    public void drawOval(RectF oval, Paint paint) {
-        // get a Graphics2D object configured with the drawing parameters.
-        Graphics2D g = getCustomGraphics(paint);
-
-        Style style = paint.getStyle();
-
-        // draw
-        if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
-            g.fillOval((int)oval.left, (int)oval.top, (int)oval.width(), (int)oval.height());
-        }
-
-        if (style == Style.STROKE || style == Style.FILL_AND_STROKE) {
-            g.drawOval((int)oval.left, (int)oval.top, (int)oval.width(), (int)oval.height());
-        }
-
-        // dispose Graphics2D object
-        g.dispose();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPath(android.graphics.Path, android.graphics.Paint)
-     */
-    @Override
-    public void drawPath(Path path, Paint paint) {
-        // get a Graphics2D object configured with the drawing parameters.
-        Graphics2D g = getCustomGraphics(paint);
-
-        Style style = paint.getStyle();
-
-        // draw
-        if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
-            g.fill(path.getAwtShape());
-        }
-
-        if (style == Style.STROKE || style == Style.FILL_AND_STROKE) {
-            g.draw(path.getAwtShape());
-        }
-
-        // dispose Graphics2D object
-        g.dispose();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#setMatrix(android.graphics.Matrix)
-     */
-    @Override
-    public void setMatrix(Matrix matrix) {
-        // get the new current graphics
-        Graphics2D g = getGraphics2d();
-
-        // and apply the matrix
-        g.setTransform(Matrix_Delegate.getAffineTransform(matrix));
-
-        if (mLogger != null && Matrix_Delegate.hasPerspective(matrix)) {
-            mLogger.warning("android.graphics.Canvas#setMatrix(android.graphics.Matrix) only supports affine transformations in the Layout Editor.");
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#concat(android.graphics.Matrix)
-     */
-    @Override
-    public void concat(Matrix matrix) {
-        // get the current top graphics2D object.
-        Graphics2D g = getGraphics2d();
-
-        // get its current matrix
-        AffineTransform currentTx = g.getTransform();
-        // get the AffineTransform of the given matrix
-        AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(matrix);
-
-        // combine them so that the given matrix is applied after.
-        currentTx.preConcatenate(matrixTx);
-
-        // give it to the graphics2D as a new matrix replacing all previous transform
-        g.setTransform(currentTx);
-    }
-
-
-    // --------------------
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipPath(android.graphics.Path, android.graphics.Region.Op)
-     */
-    @Override
-    public boolean clipPath(Path path, Op op) {
-        // TODO Auto-generated method stub
-        return super.clipPath(path, op);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipPath(android.graphics.Path)
-     */
-    @Override
-    public boolean clipPath(Path path) {
-        // TODO Auto-generated method stub
-        return super.clipPath(path);
-    }
-
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRegion(android.graphics.Region, android.graphics.Region.Op)
-     */
-    @Override
-    public boolean clipRegion(Region region, Op op) {
-        // TODO Auto-generated method stub
-        return super.clipRegion(region, op);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#clipRegion(android.graphics.Region)
-     */
-    @Override
-    public boolean clipRegion(Region region) {
-        // TODO Auto-generated method stub
-        return super.clipRegion(region);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawArc(android.graphics.RectF, float, float, boolean, android.graphics.Paint)
-     */
-    @Override
-    public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter,
-            Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawArc(oval, startAngle, sweepAngle, useCenter, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawBitmapMesh(android.graphics.Bitmap, int, int, float[], int, int[], int, android.graphics.Paint)
-     */
-    @Override
-    public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts,
-            int vertOffset, int[] colors, int colorOffset, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawBitmapMesh(bitmap, meshWidth, meshHeight, verts, vertOffset, colors, colorOffset, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPicture(android.graphics.Picture, android.graphics.Rect)
-     */
-    @Override
-    public void drawPicture(Picture picture, Rect dst) {
-        // TODO Auto-generated method stub
-        super.drawPicture(picture, dst);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPicture(android.graphics.Picture, android.graphics.RectF)
-     */
-    @Override
-    public void drawPicture(Picture picture, RectF dst) {
-        // TODO Auto-generated method stub
-        super.drawPicture(picture, dst);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPicture(android.graphics.Picture)
-     */
-    @Override
-    public void drawPicture(Picture picture) {
-        // TODO Auto-generated method stub
-        super.drawPicture(picture);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPoint(float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawPoint(float x, float y, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawPoint(x, y, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPoints(float[], int, int, android.graphics.Paint)
-     */
-    @Override
-    public void drawPoints(float[] pts, int offset, int count, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawPoints(pts, offset, count, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPoints(float[], android.graphics.Paint)
-     */
-    @Override
-    public void drawPoints(float[] pts, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawPoints(pts, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPosText(char[], int, int, float[], android.graphics.Paint)
-     */
-    @Override
-    public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawPosText(text, index, count, pos, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawPosText(java.lang.String, float[], android.graphics.Paint)
-     */
-    @Override
-    public void drawPosText(String text, float[] pos, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawPosText(text, pos, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawTextOnPath(char[], int, int, android.graphics.Path, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawTextOnPath(char[] text, int index, int count, Path path, float offset,
-            float offset2, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawTextOnPath(text, index, count, path, offset, offset2, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawTextOnPath(java.lang.String, android.graphics.Path, float, float, android.graphics.Paint)
-     */
-    @Override
-    public void drawTextOnPath(String text, Path path, float offset, float offset2, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawTextOnPath(text, path, offset, offset2, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int, int, android.graphics.Paint)
-     */
-    @Override
-    public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,
-            float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices,
-            int indexOffset, int indexCount, Paint paint) {
-        // TODO Auto-generated method stub
-        super.drawVertices(mode, vertexCount, verts, vertOffset, texs, texOffset, colors, colorOffset,
-                indices, indexOffset, indexCount, paint);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#getDrawFilter()
-     */
-    @Override
-    public DrawFilter getDrawFilter() {
-        // TODO Auto-generated method stub
-        return super.getDrawFilter();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#getMatrix()
-     */
-    @Override
-    public Matrix getMatrix() {
-        // TODO Auto-generated method stub
-        return super.getMatrix();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#getMatrix(android.graphics.Matrix)
-     */
-    @Override
-    public void getMatrix(Matrix ctm) {
-        // TODO Auto-generated method stub
-        super.getMatrix(ctm);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#isOpaque()
-     */
-    @Override
-    public boolean isOpaque() {
-        // TODO Auto-generated method stub
-        return super.isOpaque();
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#saveLayer(float, float, float, float, android.graphics.Paint, int)
-     */
-    @Override
-    public int saveLayer(float left, float top, float right, float bottom, Paint paint,
-            int saveFlags) {
-        // TODO Auto-generated method stub
-        return super.saveLayer(left, top, right, bottom, paint, saveFlags);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#saveLayer(android.graphics.RectF, android.graphics.Paint, int)
-     */
-    @Override
-    public int saveLayer(RectF bounds, Paint paint, int saveFlags) {
-        // TODO Auto-generated method stub
-        return super.saveLayer(bounds, paint, saveFlags);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#saveLayerAlpha(float, float, float, float, int, int)
-     */
-    @Override
-    public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
-            int saveFlags) {
-        // TODO Auto-generated method stub
-        return super.saveLayerAlpha(left, top, right, bottom, alpha, saveFlags);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#saveLayerAlpha(android.graphics.RectF, int, int)
-     */
-    @Override
-    public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) {
-        // TODO Auto-generated method stub
-        return super.saveLayerAlpha(bounds, alpha, saveFlags);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#setDrawFilter(android.graphics.DrawFilter)
-     */
-    @Override
-    public void setDrawFilter(DrawFilter filter) {
-        // TODO Auto-generated method stub
-        super.setDrawFilter(filter);
-    }
-
-    /* (non-Javadoc)
-     * @see android.graphics.Canvas#skew(float, float)
-     */
-    @Override
-    public void skew(float sx, float sy) {
-        // TODO Auto-generated method stub
-        super.skew(sx, sy);
-    }
-
-
-
-}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
new file mode 100644
index 0000000..bfe5c86
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -0,0 +1,1166 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.graphics;
+
+import com.android.layoutlib.api.ILayoutLog;
+import com.android.layoutlib.bridge.DelegateManager;
+
+import android.graphics.Paint_Delegate.FontInfo;
+import android.text.TextUtils;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Composite;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.util.List;
+import java.util.Stack;
+
+
+/**
+ * Delegate implementing the native methods of android.graphics.Canvas
+ *
+ * Through the layoutlib_create tool, the original native methods of Canvas have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original Canvas class.
+ *
+ * @see DelegateManager
+ *
+ */
+public class Canvas_Delegate {
+
+    // ---- delegate manager ----
+    private static final DelegateManager<Canvas_Delegate> sManager =
+            new DelegateManager<Canvas_Delegate>();
+
+    // ---- delegate helper data ----
+
+    // ---- delegate data ----
+    private BufferedImage mBufferedImage;
+    private final Stack<Graphics2D> mGraphicsStack = new Stack<Graphics2D>();
+    private ILayoutLog mLogger;
+
+    // ---- Public Helper methods ----
+
+    /**
+     * Returns the native delegate associated to a given {@link Canvas} object.
+     */
+    public static Canvas_Delegate getDelegate(Canvas canvas) {
+        return sManager.getDelegate(canvas.mNativeCanvas);
+    }
+
+    /**
+     * Returns the native delegate associated to a given an int referencing a {@link Canvas} object.
+     */
+    public static Canvas_Delegate getDelegate(int native_canvas) {
+        return sManager.getDelegate(native_canvas);
+    }
+
+    /**
+     * Sets the layoutlib logger into the canvas.
+     * @param logger
+     */
+    public void setLogger(ILayoutLog logger) {
+        mLogger = logger;
+    }
+
+    /**
+     * Returns the current {@link Graphics2D} used to draw.
+     */
+    public Graphics2D getGraphics2d() {
+        return mGraphicsStack.peek();
+    }
+
+    /**
+     * Disposes of the {@link Graphics2D} stack.
+     */
+    public void dispose() {
+
+    }
+
+    // ---- native methods ----
+
+    /*package*/ static boolean isOpaque(Canvas thisCanvas) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int getWidth(Canvas thisCanvas) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return canvasDelegate.mBufferedImage.getWidth();
+    }
+
+    /*package*/ static int getHeight(Canvas thisCanvas) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return canvasDelegate.mBufferedImage.getHeight();
+    }
+
+    /*package*/ static void translate(Canvas thisCanvas, float dx, float dy) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        canvasDelegate.getGraphics2d().translate(dx, dy);
+    }
+
+    /*package*/ static void rotate(Canvas thisCanvas, float degrees) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        canvasDelegate.getGraphics2d().rotate(Math.toRadians(degrees));
+    }
+
+    /*package*/ static void scale(Canvas thisCanvas, float sx, float sy) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        canvasDelegate.getGraphics2d().scale(sx, sy);
+    }
+
+    /*package*/ static void skew(Canvas thisCanvas, float kx, float ky) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the current top graphics2D object.
+        Graphics2D g = canvasDelegate.getGraphics2d();
+
+        // get its current matrix
+        AffineTransform currentTx = g.getTransform();
+        // get the AffineTransform for the given skew.
+        float[] mtx = Matrix_Delegate.getSkew(kx, ky);
+        AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(mtx);
+
+        // combine them so that the given matrix is applied after.
+        currentTx.preConcatenate(matrixTx);
+
+        // give it to the graphics2D as a new matrix replacing all previous transform
+        g.setTransform(currentTx);
+    }
+
+    /*package*/ static boolean clipRect(Canvas thisCanvas, RectF rect) {
+        return clipRect(thisCanvas, rect.left, rect.top, rect.right, rect.bottom);
+    }
+
+    /*package*/ static boolean clipRect(Canvas thisCanvas, Rect rect) {
+        return clipRect(thisCanvas, rect.left, rect.top, rect.right, rect.bottom);
+    }
+
+    /*package*/ static boolean clipRect(Canvas thisCanvas, float left, float top, float right,
+            float bottom) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return false;
+        }
+
+        canvasDelegate.getGraphics2d().clipRect((int)left, (int)top, (int)(right-left),
+                (int)(bottom-top));
+        return true;
+    }
+
+    /*package*/ static boolean clipRect(Canvas thisCanvas, int left, int top, int right,
+            int bottom) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return false;
+        }
+
+        canvasDelegate.getGraphics2d().clipRect(left, top, right - left, bottom - top);
+        return true;
+    }
+
+    /*package*/ static int save(Canvas thisCanvas) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return 0;
+        }
+
+        // get the current save count
+        int count = canvasDelegate.mGraphicsStack.size();
+
+        // create a new graphics and add it to the stack
+        Graphics2D g = (Graphics2D)canvasDelegate.getGraphics2d().create();
+        canvasDelegate.mGraphicsStack.push(g);
+
+        // return the old save count
+        return count;
+
+    }
+
+    /*package*/ static int save(Canvas thisCanvas, int saveFlags) {
+        // FIXME implement save(flags)
+        return save(thisCanvas);
+    }
+
+    /*package*/ static void restore(Canvas thisCanvas) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        canvasDelegate.mGraphicsStack.pop();
+    }
+
+    /*package*/ static int getSaveCount(Canvas thisCanvas) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return canvasDelegate.mGraphicsStack.size();
+    }
+
+    /*package*/ static void restoreToCount(Canvas thisCanvas, int saveCount) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        while (canvasDelegate.mGraphicsStack.size() > saveCount) {
+            canvasDelegate.mGraphicsStack.pop();
+        }
+    }
+
+    /*package*/ static void drawPoints(Canvas thisCanvas, float[] pts, int offset, int count,
+            Paint paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void drawPoint(Canvas thisCanvas, float x, float y, Paint paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void drawLines(Canvas thisCanvas, float[] pts, int offset, int count,
+            Paint paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void freeCaches() {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int initRaster(int nativeBitmapOrZero) {
+        if (nativeBitmapOrZero > 0) {
+            // get the Bitmap from the int
+            Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero);
+
+            // create a new Canvas_Delegate with the given bitmap and return its new native int.
+            Canvas_Delegate newDelegate = new Canvas_Delegate(bitmapDelegate.getImage());
+
+            return sManager.addDelegate(newDelegate);
+        } else {
+            // create a new Canvas_Delegate and return its new native int.
+            Canvas_Delegate newDelegate = new Canvas_Delegate();
+
+            return sManager.addDelegate(newDelegate);
+        }
+    }
+
+    /*package*/ static void native_setBitmap(int nativeCanvas, int bitmap) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
+        if (bitmapDelegate == null) {
+            assert false;
+            return;
+        }
+
+        canvasDelegate.setBitmap(bitmapDelegate.getImage());
+    }
+
+    /*package*/ static int native_saveLayer(int nativeCanvas, RectF bounds,
+                                               int paint, int layerFlags) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_saveLayer(int nativeCanvas, float l,
+                                               float t, float r, float b,
+                                               int paint, int layerFlags) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_saveLayerAlpha(int nativeCanvas,
+                                                    RectF bounds, int alpha,
+                                                    int layerFlags) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_saveLayerAlpha(int nativeCanvas, float l,
+                                                    float t, float r, float b,
+                                                    int alpha, int layerFlags) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+
+    /*package*/ static void native_concat(int nCanvas, int nMatrix) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_setMatrix(int nCanvas, int nMatrix) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static boolean native_clipRect(int nCanvas,
+                                                  float left, float top,
+                                                  float right, float bottom,
+                                                  int regionOp) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static boolean native_clipPath(int nativeCanvas,
+                                                  int nativePath,
+                                                  int regionOp) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static boolean native_clipRegion(int nativeCanvas,
+                                                    int nativeRegion,
+                                                    int regionOp) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void nativeSetDrawFilter(int nativeCanvas,
+                                                   int nativeFilter) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static boolean native_getClipBounds(int nativeCanvas,
+                                                       Rect bounds) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return false;
+        }
+
+        Rectangle rect = canvasDelegate.getGraphics2d().getClipBounds();
+        if (rect != null) {
+            bounds.left = rect.x;
+            bounds.top = rect.y;
+            bounds.right = rect.x + rect.width;
+            bounds.bottom = rect.y + rect.height;
+            return true;
+        }
+        return false;
+    }
+
+    /*package*/ static void native_getCTM(int canvas, int matrix) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static boolean native_quickReject(int nativeCanvas,
+                                                     RectF rect,
+                                                     int native_edgeType) {
+        // FIXME properly implement quickReject
+        return false;
+    }
+
+    /*package*/ static boolean native_quickReject(int nativeCanvas,
+                                                     int path,
+                                                     int native_edgeType) {
+        // FIXME properly implement quickReject
+        return false;
+    }
+
+    /*package*/ static boolean native_quickReject(int nativeCanvas,
+                                                     float left, float top,
+                                                     float right, float bottom,
+                                                     int native_edgeType) {
+        // FIXME properly implement quickReject
+        return false;
+    }
+
+    /*package*/ static void native_drawRGB(int nativeCanvas, int r, int g, int b) {
+        native_drawColor(nativeCanvas, 0xFF000000 | r << 16 | (g&0xFF) << 8 | (b&0xFF),
+                PorterDuff.Mode.SRC_OVER.nativeInt);
+
+    }
+
+    /*package*/ static void native_drawARGB(int nativeCanvas, int a, int r, int g, int b) {
+        native_drawColor(nativeCanvas, a << 24 | (r&0xFF) << 16 | (g&0xFF) << 8 | (b&0xFF),
+                PorterDuff.Mode.SRC_OVER.nativeInt);
+    }
+
+    /*package*/ static void native_drawColor(int nativeCanvas, int color) {
+        native_drawColor(nativeCanvas, color, PorterDuff.Mode.SRC_OVER.nativeInt);
+    }
+
+    /*package*/ static void native_drawColor(int nativeCanvas, int color, int mode) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get a new graphics context.
+        Graphics2D graphics = (Graphics2D)canvasDelegate.getGraphics2d().create();
+        try {
+            // reset its transform just in case
+            graphics.setTransform(new AffineTransform());
+
+            // set the color
+            graphics.setColor(new Color(color));
+
+            // set the mode and alpha.
+            int alpha = color >>> 24;
+            float falpha = alpha / 255.f;
+
+            setModeInGraphics(graphics, mode, falpha);
+
+            graphics.fillRect(0, 0, canvasDelegate.mBufferedImage.getWidth(),
+                    canvasDelegate.mBufferedImage.getHeight());
+        } finally {
+            // dispose Graphics2D object
+            graphics.dispose();
+        }
+    }
+
+    /*package*/ static void native_drawPaint(int nativeCanvas, int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawLine(int nativeCanvas, float startX,
+                                               float startY, float stopX,
+                                               float stopY, int paint) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
+        if (paintDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get a Graphics2D object configured with the drawing parameters.
+        Graphics2D g = canvasDelegate.getCustomGraphics(paintDelegate);
+
+        g.drawLine((int)startX, (int)startY, (int)stopX, (int)stopY);
+
+        // dispose Graphics2D object
+        g.dispose();
+    }
+
+    /*package*/ static void native_drawRect(int nativeCanvas, RectF rect,
+                                               int paint) {
+        native_drawRect(nativeCanvas, rect.left, rect.top, rect.right, rect.bottom, paint);
+    }
+
+    /*package*/ static void native_drawRect(int nativeCanvas, float left,
+                                               float top, float right,
+                                               float bottom, int paint) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
+        if (paintDelegate == null) {
+            assert false;
+            return;
+        }
+
+        if (right > left && bottom > top) {
+            // get a Graphics2D object configured with the drawing parameters.
+            Graphics2D g = canvasDelegate.getCustomGraphics(paintDelegate);
+
+            int style = paintDelegate.getStyle();
+
+            // draw
+            if (style == Paint.Style.FILL.nativeInt ||
+                    style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+                g.fillRect((int)left, (int)top, (int)(right-left), (int)(bottom-top));
+            }
+
+            if (style == Paint.Style.STROKE.nativeInt ||
+                    style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+                g.drawRect((int)left, (int)top, (int)(right-left), (int)(bottom-top));
+            }
+
+            // dispose Graphics2D object
+            g.dispose();
+        }
+    }
+
+    /*package*/ static void native_drawOval(int nativeCanvas, RectF oval,
+                                               int paint) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
+        if (paintDelegate == null) {
+            assert false;
+            return;
+        }
+
+        if (oval.right > oval.left && oval.bottom > oval.top) {
+            // get a Graphics2D object configured with the drawing parameters.
+            Graphics2D g = canvasDelegate.getCustomGraphics(paintDelegate);
+
+            int style = paintDelegate.getStyle();
+
+            // draw
+            if (style == Paint.Style.FILL.nativeInt ||
+                    style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+                g.fillOval((int)oval.left, (int)oval.top, (int)oval.width(), (int)oval.height());
+            }
+
+            if (style == Paint.Style.STROKE.nativeInt ||
+                    style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+                g.drawOval((int)oval.left, (int)oval.top, (int)oval.width(), (int)oval.height());
+            }
+
+            // dispose Graphics2D object
+            g.dispose();
+        }
+    }
+
+    /*package*/ static void native_drawCircle(int nativeCanvas, float cx,
+                                                 float cy, float radius,
+                                                 int paint) {
+        native_drawOval(nativeCanvas,
+                new RectF(cx - radius, cy - radius, radius*2, radius*2),
+                paint);
+    }
+
+    /*package*/ static void native_drawArc(int nativeCanvas, RectF oval,
+                                              float startAngle, float sweep,
+                                              boolean useCenter, int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawRoundRect(int nativeCanvas,
+                                                    RectF rect, float rx,
+                                                    float ry, int paint) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
+        if (paintDelegate == null) {
+            assert false;
+            return;
+        }
+
+        if (rect.right > rect.left && rect.bottom > rect.top) {
+            // get a Graphics2D object configured with the drawing parameters.
+            Graphics2D g = canvasDelegate.getCustomGraphics(paintDelegate);
+
+            int style = paintDelegate.getStyle();
+
+            // draw
+            if (style == Paint.Style.FILL.nativeInt ||
+                    style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+                g.fillRoundRect(
+                        (int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(),
+                        (int)rx, (int)ry);
+            }
+
+            if (style == Paint.Style.STROKE.nativeInt ||
+                    style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+                g.drawRoundRect(
+                        (int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(),
+                        (int)rx, (int)ry);
+            }
+
+            // dispose Graphics2D object
+            g.dispose();
+        }
+    }
+
+    /*package*/ static void native_drawPath(int nativeCanvas, int path,
+                                               int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawBitmap(Canvas thisCanvas, int nativeCanvas, int bitmap,
+                                                 float left, float top,
+                                                 int nativePaintOrZero,
+                                                 int canvasDensity,
+                                                 int screenDensity,
+                                                 int bitmapDensity) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawBitmap(Canvas thisCanvas, int nativeCanvas, int bitmap,
+                                                 Rect src, RectF dst,
+                                                 int nativePaintOrZero,
+                                                 int screenDensity,
+                                                 int bitmapDensity) {
+        // get the delegate from the native int.
+        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
+        if (bitmapDelegate == null) {
+            assert false;
+            return;
+        }
+
+        BufferedImage image = bitmapDelegate.getImage();
+
+        if (src == null) {
+            drawBitmap(nativeCanvas, image, nativePaintOrZero,
+                    0, 0, image.getWidth(), image.getHeight(),
+                    (int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom);
+        } else {
+            drawBitmap(nativeCanvas, image, nativePaintOrZero,
+                    src.left, src.top, src.width(), src.height(),
+                    (int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom);
+        }
+    }
+
+    /*package*/ static void native_drawBitmap(int nativeCanvas, int bitmap,
+                                                 Rect src, Rect dst,
+                                                 int nativePaintOrZero,
+                                                 int screenDensity,
+                                                 int bitmapDensity) {
+        // get the delegate from the native int.
+        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
+        if (bitmapDelegate == null) {
+            assert false;
+            return;
+        }
+
+        BufferedImage image = bitmapDelegate.getImage();
+
+        if (src == null) {
+            drawBitmap(nativeCanvas, image, nativePaintOrZero,
+                    0, 0, image.getWidth(), image.getHeight(),
+                    dst.left, dst.top, dst.right, dst.bottom);
+        } else {
+            drawBitmap(nativeCanvas, image, nativePaintOrZero,
+                    src.left, src.top, src.width(), src.height(),
+                    dst.left, dst.top, dst.right, dst.bottom);
+        }
+    }
+
+    /*package*/ static void native_drawBitmap(int nativeCanvas, int[] colors,
+                                                int offset, int stride, float x,
+                                                 float y, int width, int height,
+                                                 boolean hasAlpha,
+                                                 int nativePaintOrZero) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void nativeDrawBitmapMatrix(int nCanvas, int nBitmap,
+                                                      int nMatrix, int nPaint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void nativeDrawBitmapMesh(int nCanvas, int nBitmap,
+                                                    int meshWidth, int meshHeight,
+                                                    float[] verts, int vertOffset,
+                                                    int[] colors, int colorOffset, int nPaint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void nativeDrawVertices(int nCanvas, int mode, int n,
+                   float[] verts, int vertOffset, float[] texs, int texOffset,
+                   int[] colors, int colorOffset, short[] indices,
+                   int indexOffset, int indexCount, int nPaint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawText(int nativeCanvas, char[] text,
+                                               int index, int count, float x,
+                                               float y, int flags, int paint) {
+        // WARNING: the logic in this method is similar to Paint.measureText.
+        // Any change to this method should be reflected in Paint.measureText
+
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
+        if (paintDelegate == null) {
+            assert false;
+            return;
+        }
+
+        Graphics2D g = (Graphics2D) canvasDelegate.getCustomGraphics(paintDelegate);
+        try {
+            // Paint.TextAlign indicates how the text is positioned relative to X.
+            // LEFT is the default and there's nothing to do.
+            if (paintDelegate.getTextAlign() != Paint.Align.LEFT.nativeInt) {
+                float m = paintDelegate.measureText(text, index, count);
+                if (paintDelegate.getTextAlign() == Paint.Align.CENTER.nativeInt) {
+                    x -= m / 2;
+                } else if (paintDelegate.getTextAlign() == Paint.Align.RIGHT.nativeInt) {
+                    x -= m;
+                }
+            }
+
+            List<FontInfo> fonts = paintDelegate.getFonts();
+
+            if (fonts.size() > 0) {
+                FontInfo mainFont = fonts.get(0);
+                int i = index;
+                int lastIndex = index + count;
+                while (i < lastIndex) {
+                    // always start with the main font.
+                    int upTo = mainFont.mFont.canDisplayUpTo(text, i, lastIndex);
+                    if (upTo == -1) {
+                        // draw all the rest and exit.
+                        g.setFont(mainFont.mFont);
+                        g.drawChars(text, i, lastIndex - i, (int)x, (int)y);
+                        return;
+                    } else if (upTo > 0) {
+                        // draw what's possible
+                        g.setFont(mainFont.mFont);
+                        g.drawChars(text, i, upTo - i, (int)x, (int)y);
+
+                        // compute the width that was drawn to increase x
+                        x += mainFont.mMetrics.charsWidth(text, i, upTo - i);
+
+                        // move index to the first non displayed char.
+                        i = upTo;
+
+                        // don't call continue at this point. Since it is certain the main font
+                        // cannot display the font a index upTo (now ==i), we move on to the
+                        // fallback fonts directly.
+                    }
+
+                    // no char supported, attempt to read the next char(s) with the
+                    // fallback font. In this case we only test the first character
+                    // and then go back to test with the main font.
+                    // Special test for 2-char characters.
+                    boolean foundFont = false;
+                    for (int f = 1 ; f < fonts.size() ; f++) {
+                        FontInfo fontInfo = fonts.get(f);
+
+                        // need to check that the font can display the character. We test
+                        // differently if the char is a high surrogate.
+                        int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1;
+                        upTo = fontInfo.mFont.canDisplayUpTo(text, i, i + charCount);
+                        if (upTo == -1) {
+                            // draw that char
+                            g.setFont(fontInfo.mFont);
+                            g.drawChars(text, i, charCount, (int)x, (int)y);
+
+                            // update x
+                            x += fontInfo.mMetrics.charsWidth(text, i, charCount);
+
+                            // update the index in the text, and move on
+                            i += charCount;
+                            foundFont = true;
+                            break;
+
+                        }
+                    }
+
+                    // in case no font can display the char, display it with the main font.
+                    // (it'll put a square probably)
+                    if (foundFont == false) {
+                        int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1;
+
+                        g.setFont(mainFont.mFont);
+                        g.drawChars(text, i, charCount, (int)x, (int)y);
+
+                        // measure it to advance x
+                        x += mainFont.mMetrics.charsWidth(text, i, charCount);
+
+                        // and move to the next chars.
+                        i += charCount;
+                    }
+                }
+            }
+        } finally {
+            g.dispose();
+        }
+    }
+
+    /*package*/ static void native_drawText(int nativeCanvas, String text,
+                                               int start, int end, float x,
+                                               float y, int flags, int paint) {
+        int count = end - start;
+        char[] buffer = TemporaryBuffer.obtain(count);
+        TextUtils.getChars(text, start, end, buffer, 0);
+
+        native_drawText(nativeCanvas, buffer, 0, count, x, y, flags, paint);
+    }
+
+
+    /*package*/ static void native_drawTextRun(int nativeCanvas, String text,
+            int start, int end, int contextStart, int contextEnd,
+            float x, float y, int flags, int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+
+    /*package*/ static void native_drawTextRun(int nativeCanvas, char[] text,
+            int start, int count, int contextStart, int contextCount,
+            float x, float y, int flags, int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+
+    /*package*/ static void native_drawPosText(int nativeCanvas,
+                                                  char[] text, int index,
+                                                  int count, float[] pos,
+                                                  int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawPosText(int nativeCanvas,
+                                                  String text, float[] pos,
+                                                  int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawTextOnPath(int nativeCanvas,
+                                                     char[] text, int index,
+                                                     int count, int path,
+                                                     float hOffset,
+                                                     float vOffset, int bidiFlags,
+                                                     int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawTextOnPath(int nativeCanvas,
+                                                     String text, int path,
+                                                     float hOffset,
+                                                     float vOffset,
+                                                     int flags, int paint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_drawPicture(int nativeCanvas,
+                                                  int nativePicture) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void finalizer(int nativeCanvas) {
+        sManager.removeDelegate(nativeCanvas);
+    }
+
+    // ---- Private delegate/helper methods ----
+
+    private Canvas_Delegate(BufferedImage image) {
+        setBitmap(image);
+    }
+
+    private Canvas_Delegate() {
+    }
+
+    private void setBitmap(BufferedImage image) {
+        mBufferedImage = image;
+        mGraphicsStack.push(mBufferedImage.createGraphics());
+    }
+
+    /**
+     * Creates a new {@link Graphics2D} based on the {@link Paint} parameters.
+     * <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used.
+     */
+    private Graphics2D getCustomGraphics(Paint_Delegate paint) {
+        // make new one
+        Graphics2D g = getGraphics2d();
+        g = (Graphics2D)g.create();
+
+        if (paint.isAntiAliased()) {
+            g.setRenderingHint(
+                    RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            g.setRenderingHint(
+                    RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+        }
+
+        // configure it
+        g.setColor(new Color(paint.getColor()));
+        int alpha = paint.getAlpha();
+        float falpha = alpha / 255.f;
+
+        int style = paint.getStyle();
+        if (style == Paint.Style.STROKE.nativeInt ||
+                style == Paint.Style.FILL_AND_STROKE.nativeInt) {
+            /* FIXME
+            PathEffect e = paint.getPathEffect();
+            if (e instanceof DashPathEffect) {
+                DashPathEffect dpe = (DashPathEffect)e;
+                g.setStroke(new BasicStroke(
+                        paint.getStrokeWidth(),
+                        paint.getStrokeCap().getJavaCap(),
+                        paint.getStrokeJoin().getJavaJoin(),
+                        paint.getStrokeMiter(),
+                        dpe.getIntervals(),
+                        dpe.getPhase()));
+            } else {*/
+                g.setStroke(new BasicStroke(
+                        paint.getStrokeWidth(),
+                        paint.getJavaCap(),
+                        paint.getJavaJoin(),
+                        paint.getStrokeMiter()));
+          /*  }*/
+        }
+/*
+        Xfermode xfermode = paint.getXfermode();
+        if (xfermode instanceof PorterDuffXfermode) {
+            PorterDuff.Mode mode = ((PorterDuffXfermode)xfermode).getMode();
+
+            setModeInGraphics(mode, g, falpha);
+        } else {
+            if (mLogger != null && xfermode != null) {
+                mLogger.warning(String.format(
+                        "Xfermode '%1$s' is not supported in the Layout Editor.",
+                        xfermode.getClass().getCanonicalName()));
+            }
+            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
+        }
+*/
+        int nativeShader = paint.getShader();
+        Shader_Delegate shaderDelegate = Shader_Delegate.getDelegate(nativeShader);
+        if (shaderDelegate != null) {
+            java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
+            if (shaderPaint != null) {
+                g.setPaint(shaderPaint);
+            } else {
+                if (mLogger != null) {
+                    mLogger.warning(String.format(
+                            "Shader '%1$s' is not supported in the Layout Editor.",
+                            shaderDelegate.getClass().getCanonicalName()));
+                }
+            }
+        }
+
+        return g;
+    }
+
+    private static void setModeInGraphics(Graphics2D g, int mode, float falpha) {
+        for (PorterDuff.Mode m : PorterDuff.Mode.values()) {
+            if (m.nativeInt == mode) {
+                setModeInGraphics(g, m, falpha);
+                return;
+            }
+        }
+    }
+
+    private static void setModeInGraphics(Graphics2D g, PorterDuff.Mode mode, float falpha) {
+        switch (mode) {
+            case CLEAR:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, falpha));
+                break;
+            case DARKEN:
+                break;
+            case DST:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST, falpha));
+                break;
+            case DST_ATOP:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_ATOP, falpha));
+                break;
+            case DST_IN:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, falpha));
+                break;
+            case DST_OUT:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT, falpha));
+                break;
+            case DST_OVER:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, falpha));
+                break;
+            case LIGHTEN:
+                break;
+            case MULTIPLY:
+                break;
+            case SCREEN:
+                break;
+            case SRC:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, falpha));
+                break;
+            case SRC_ATOP:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, falpha));
+                break;
+            case SRC_IN:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, falpha));
+                break;
+            case SRC_OUT:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT, falpha));
+                break;
+            case SRC_OVER:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
+                break;
+            case XOR:
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, falpha));
+                break;
+        }
+    }
+
+
+    private static void drawBitmap(
+            int nativeCanvas,
+            BufferedImage image,
+            int nativePaintOrZero,
+            int sleft, int stop, int sright, int sbottom,
+            int dleft, int dtop, int dright, int dbottom) {
+        // get the delegate from the native int.
+        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
+        if (canvasDelegate == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate paintDelegate = null;
+        if (nativePaintOrZero > 0) {
+            paintDelegate = Paint_Delegate.getDelegate(nativePaintOrZero);
+            if (paintDelegate == null) {
+                assert false;
+                return;
+            }
+        }
+
+        drawBitmap(canvasDelegate, image, paintDelegate,
+                sleft, stop, sright, sbottom,
+                dleft, dtop, dright, dbottom);
+    }
+
+    private static void drawBitmap(
+            Canvas_Delegate canvasDelegate,
+            BufferedImage image,
+            Paint_Delegate paintDelegate,
+            int sleft, int stop, int sright, int sbottom,
+            int dleft, int dtop, int dright, int dbottom) {
+
+        Graphics2D g = canvasDelegate.getGraphics2d();
+
+        Composite c = null;
+
+        if (paintDelegate != null) {
+            if (paintDelegate.isFilterBitmap()) {
+                g = (Graphics2D)g.create();
+                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+            }
+
+            if (paintDelegate.getAlpha() != 0xFF) {
+                c = g.getComposite();
+                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
+                        paintDelegate.getAlpha()/255.f));
+            }
+        }
+
+        g.drawImage(image, dleft, dtop, dright, dbottom,
+                sleft, stop, sright, sbottom, null);
+
+        if (paintDelegate != null) {
+            if (paintDelegate.isFilterBitmap()) {
+                g.dispose();
+            }
+            if (c != null) {
+                g.setComposite(c);
+            }
+        }
+    }
+
+}
+
diff --git a/tools/layoutlib/bridge/src/android/graphics/ComposeShader.java b/tools/layoutlib/bridge/src/android/graphics/ComposeShader.java
deleted file mode 100644
index 863d64a..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/ComposeShader.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package android.graphics;
-
-import java.awt.Paint;
-
-/** A subclass of shader that returns the composition of two other shaders, combined by
-    an {@link android.graphics.Xfermode} subclass.
-*/
-public class ComposeShader extends Shader {
-    /** Create a new compose shader, given shaders A, B, and a combining mode.
-        When the mode is applied, it will be given the result from shader A as its
-        "dst", and the result of from shader B as its "src".
-        @param shaderA  The colors from this shader are seen as the "dst" by the mode
-        @param shaderB  The colors from this shader are seen as the "src" by the mode
-        @param mode     The mode that combines the colors from the two shaders. If mode
-                        is null, then SRC_OVER is assumed.
-    */
-    public ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode) {
-        // FIXME Implement shader
-    }
-
-    /** Create a new compose shader, given shaders A, B, and a combining PorterDuff mode.
-        When the mode is applied, it will be given the result from shader A as its
-        "dst", and the result of from shader B as its "src".
-        @param shaderA  The colors from this shader are seen as the "dst" by the mode
-        @param shaderB  The colors from this shader are seen as the "src" by the mode
-        @param mode     The PorterDuff mode that combines the colors from the two shaders.
-    */
-    public ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode) {
-        // FIXME Implement shader
-    }
-
-    @Override
-    Paint getJavaPaint() {
-        return null;
-    }
-}
-
diff --git a/tools/layoutlib/bridge/src/android/graphics/GradientShader.java b/tools/layoutlib/bridge/src/android/graphics/Gradient_Delegate.java
similarity index 93%
rename from tools/layoutlib/bridge/src/android/graphics/GradientShader.java
rename to tools/layoutlib/bridge/src/android/graphics/Gradient_Delegate.java
index 8c5a2a4..042d557 100644
--- a/tools/layoutlib/bridge/src/android/graphics/GradientShader.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Gradient_Delegate.java
@@ -16,19 +16,12 @@
 
 package android.graphics;
 
+import android.graphics.Shader.TileMode;
 
 /**
- * Base class for Gradient shader. This is not a standard android class and is just used
- * as a base class for the re-implemented gradient classes.
- *
- * It also provides a base class to handle common code between the different shaders'
- * implementations of {@link java.awt.Paint}.
- *
- * @see LinearGradient
- * @see RadialGradient
- * @see SweepGradient
+ * Base class for true Gradient shader delegate.
  */
-public abstract class GradientShader extends Shader {
+public abstract class Gradient_Delegate extends Shader_Delegate {
 
     protected final int[] mColors;
     protected final float[] mPositions;
@@ -41,7 +34,7 @@
      *            corresponding color in the colors array. If this is null, the
      *            the colors are distributed evenly along the gradient line.
      */
-    protected GradientShader(int colors[], float positions[]) {
+    protected Gradient_Delegate(int colors[], float positions[]) {
         if (colors.length < 2) {
             throw new IllegalArgumentException("needs >= 2 number of colors");
         }
@@ -199,7 +192,5 @@
         private int computeChannel(int c1, int c2, float percent) {
             return c1 + (int)((percent * (c2-c1)) + .5);
         }
-
-
     }
 }
diff --git a/tools/layoutlib/bridge/src/android/graphics/LinearGradient.java b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
similarity index 66%
rename from tools/layoutlib/bridge/src/android/graphics/LinearGradient.java
rename to tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
index 10c4a5e..405e537 100644
--- a/tools/layoutlib/bridge/src/android/graphics/LinearGradient.java
+++ b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2010 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.
@@ -16,10 +16,80 @@
 
 package android.graphics;
 
-public class LinearGradient extends GradientShader {
+import com.android.layoutlib.bridge.DelegateManager;
 
+import android.graphics.Shader.TileMode;
+
+import java.awt.Paint;
+
+/**
+ * Delegate implementing the native methods of android.graphics.LinearGradient
+ *
+ * Through the layoutlib_create tool, the original native methods of LinearGradient have been
+ * replaced by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original LinearGradient class.
+ *
+ * Because this extends {@link Shader_Delegate}, there's no need to use a {@link DelegateManager},
+ * as all the Shader classes will be added to the manager owned by {@link Shader_Delegate}.
+ *
+ * @see Shader_Delegate
+ *
+ */
+public class LinearGradient_Delegate extends Gradient_Delegate {
+
+    // ---- delegate data ----
     private java.awt.Paint mJavaPaint;
 
+    // ---- Public Helper methods ----
+
+    @Override
+    public Paint getJavaPaint() {
+        return mJavaPaint;
+    }
+
+    // ---- native methods ----
+
+    /*package*/ static int nativeCreate1(LinearGradient thisGradient,
+            float x0, float y0, float x1, float y1,
+            int colors[], float positions[], int tileMode) {
+        // figure out the tile
+        TileMode tile = null;
+        for (TileMode tm : TileMode.values()) {
+            if (tm.nativeInt == tileMode) {
+                tile = tm;
+                break;
+            }
+        }
+
+        LinearGradient_Delegate newDelegate = new LinearGradient_Delegate(x0, y0, x1, y1,
+                colors, positions, tile);
+        return sManager.addDelegate(newDelegate);
+    }
+    /*package*/ static int nativeCreate2(LinearGradient thisGradient,
+            float x0, float y0, float x1, float y1,
+            int color0, int color1, int tileMode) {
+        return nativeCreate1(thisGradient,
+                x0, y0, x1, y1, new int[] { color0, color1}, null /*positions*/,
+                tileMode);
+    }
+    /*package*/ static int nativePostCreate1(LinearGradient thisGradient,
+            int native_shader, float x0, float y0, float x1, float y1,
+            int colors[], float positions[], int tileMode) {
+        // nothing to be done here.
+        return 0;
+    }
+    /*package*/ static int nativePostCreate2(LinearGradient thisGradient,
+            int native_shader, float x0, float y0, float x1, float y1,
+            int color0, int color1, int tileMode) {
+        // nothing to be done here.
+        return 0;
+    }
+
+    // ---- Private delegate/helper methods ----
+
     /**
      * Create a shader that draws a linear gradient along a line.
      *
@@ -33,35 +103,13 @@
      *            the colors are distributed evenly along the gradient line.
      * @param tile The Shader tiling mode
      */
-    public LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[],
-            TileMode tile) {
+    private LinearGradient_Delegate(float x0, float y0, float x1, float y1,
+            int colors[], float positions[], TileMode tile) {
         super(colors, positions);
         mJavaPaint = new LinearGradientPaint(x0, y0, x1, y1, mColors, mPositions, tile);
     }
 
-    /**
-     * Create a shader that draws a linear gradient along a line.
-     *
-     * @param x0 The x-coordinate for the start of the gradient line
-     * @param y0 The y-coordinate for the start of the gradient line
-     * @param x1 The x-coordinate for the end of the gradient line
-     * @param y1 The y-coordinate for the end of the gradient line
-     * @param color0 The color at the start of the gradient line.
-     * @param color1 The color at the end of the gradient line.
-     * @param tile The Shader tiling mode
-     */
-    public LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1,
-            TileMode tile) {
-        this(x0, y0, x1, y1, new int[] { color0, color1}, null /*positions*/, tile);
-    }
-
-    // ---------- Custom Methods
-
-    @Override
-    java.awt.Paint getJavaPaint() {
-        return mJavaPaint;
-    }
-
+    // ---- Custom Java Paint ----
     /**
      * Linear Gradient (Java) Paint able to handle more than 2 points, as
      * {@link java.awt.GradientPaint} only supports 2 points and does not support Android's tile
@@ -101,7 +149,7 @@
 
             public LinearGradientPaintContext(java.awt.image.ColorModel colorModel) {
                 mColorModel = colorModel;
-                // FIXME: so far all this is always the same rect gotten in getRaster with an indentity matrix?
+                // FIXME: so far all this is always the same rect gotten in getRaster with an identity matrix?
             }
 
             public void dispose() {
diff --git a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
index cc4a80c..0966f39 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
@@ -50,6 +50,10 @@
 
     // ---- Public Helper methods ----
 
+    public static Matrix_Delegate getDelegate(int native_instance) {
+        return sManager.getDelegate(native_instance);
+    }
+
     /**
      * Returns an {@link AffineTransform} matching the given Matrix.
      */
@@ -73,6 +77,35 @@
         return (delegate.mValues[6] != 0 || delegate.mValues[7] != 0 || delegate.mValues[8] != 1);
     }
 
+    /**
+     * Sets the content of the matrix with the content of another matrix.
+     */
+    public void set(Matrix_Delegate matrix) {
+        System.arraycopy(matrix.mValues, 0, mValues, 0, MATRIX_SIZE);
+    }
+
+    /**
+     * Resets the matrix to be the identity matrix.
+     */
+    public void reset() {
+        reset(mValues);
+    }
+
+    /**
+     * Returns whether or not the matrix is identity.
+     */
+    public boolean isIdentity() {
+        for (int i = 0, k = 0; i < 3; i++) {
+            for (int j = 0; j < 3; j++, k++) {
+                if (mValues[k] != ((i==j) ? 1 : 0)) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
 
     // ---- native methods ----
 
@@ -101,15 +134,7 @@
             return false;
         }
 
-        for (int i = 0, k = 0; i < 3; i++) {
-            for (int j = 0; j < 3; j++, k++) {
-                if (d.mValues[k] != ((i==j) ? 1 : 0)) {
-                    return false;
-                }
-            }
-        }
-
-        return true;
+        return d.isIdentity();
     }
 
     /*package*/ static boolean native_rectStaysRect(int native_object) {
@@ -689,13 +714,17 @@
     // ---- Private helper methods ----
 
     private static AffineTransform getAffineTransform(Matrix_Delegate d) {
+        return getAffineTransform(d.mValues);
+    }
+
+    /*package*/ static AffineTransform getAffineTransform(float[] matrix) {
         // the AffineTransform constructor takes the value in a different order
         // for a matrix [ 0 1 2 ]
         //              [ 3 4 5 ]
         // the order is 0, 3, 1, 4, 2, 5...
         return new AffineTransform(
-                d.mValues[0], d.mValues[3], d.mValues[1],
-                d.mValues[4], d.mValues[2], d.mValues[5]);
+                matrix[0], matrix[3], matrix[1],
+                matrix[4], matrix[2], matrix[5]);
     }
 
 
@@ -862,7 +891,7 @@
      * <p/>This in effect does dest = a*b
      * dest cannot be the same as a or b.
      */
-    private static void multiply(float dest[], float[] a, float[] b) {
+     /*package*/ static void multiply(float dest[], float[] a, float[] b) {
         // first row
         dest[0] = b[0] * a[0] + b[1] * a[3] + b[2] * a[6];
         dest[1] = b[0] * a[1] + b[1] * a[4] + b[2] * a[7];
@@ -885,11 +914,11 @@
      * @param dy
      * @return
      */
-    private static float[] getTranslate(float dx, float dy) {
+    /*package*/ static float[] getTranslate(float dx, float dy) {
         return setTranslate(new float[9], dx, dy);
     }
 
-    private static float[] setTranslate(float[] dest, float dx, float dy) {
+    /*package*/ static float[] setTranslate(float[] dest, float dx, float dy) {
         dest[0] = 1;
         dest[1] = 0;
         dest[2] = dx;
@@ -902,7 +931,7 @@
         return dest;
     }
 
-    private static float[] getScale(float sx, float sy) {
+    /*package*/ static float[] getScale(float sx, float sy) {
         return new float[] { sx, 0, 0, 0, sy, 0, 0, 0, 1 };
     }
 
@@ -913,7 +942,7 @@
      * @param px
      * @param py
      */
-    private static float[] getScale(float sx, float sy, float px, float py) {
+    /*package*/ static float[] getScale(float sx, float sy, float px, float py) {
         float[] tmp = new float[9];
         float[] tmp2 = new float[9];
 
@@ -932,7 +961,7 @@
     }
 
 
-    private static float[] getRotate(float degrees) {
+    /*package*/ static float[] getRotate(float degrees) {
         double rad = Math.toRadians(degrees);
         float sin = (float)Math.sin(rad);
         float cos = (float)Math.cos(rad);
@@ -940,11 +969,11 @@
         return getRotate(sin, cos);
     }
 
-    private static float[] getRotate(float sin, float cos) {
+    /*package*/ static float[] getRotate(float sin, float cos) {
         return setRotate(new float[9], sin, cos);
     }
 
-    private static float[] setRotate(float[] dest, float degrees) {
+    /*package*/ static float[] setRotate(float[] dest, float degrees) {
         double rad = Math.toRadians(degrees);
         float sin = (float)Math.sin(rad);
         float cos = (float)Math.cos(rad);
@@ -952,7 +981,7 @@
         return setRotate(dest, sin, cos);
     }
 
-    private static float[] setRotate(float[] dest, float sin, float cos) {
+    /*package*/ static float[] setRotate(float[] dest, float sin, float cos) {
         dest[0] = cos;
         dest[1] = -sin;
         dest[2] = 0;
@@ -965,7 +994,7 @@
         return dest;
     }
 
-    private static float[] getRotate(float degrees, float px, float py) {
+    /*package*/ static float[] getRotate(float degrees, float px, float py) {
         float[] tmp = new float[9];
         float[] tmp2 = new float[9];
 
@@ -986,11 +1015,11 @@
         return tmp;
     }
 
-    private static float[] getSkew(float kx, float ky) {
+    /*package*/ static float[] getSkew(float kx, float ky) {
         return new float[] { 1, kx, 0, ky, 1, 0, 0, 0, 1 };
     }
 
-    private static float[] getSkew(float kx, float ky, float px, float py) {
+    /*package*/ static float[] getSkew(float kx, float ky, float px, float py) {
         float[] tmp = new float[9];
         float[] tmp2 = new float[9];
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint.java b/tools/layoutlib/bridge/src/android/graphics/Paint.java
deleted file mode 100644
index 2de21c1..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/Paint.java
+++ /dev/null
@@ -1,1211 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package android.graphics;
-
-import android.text.SpannableString;
-import android.text.SpannableStringBuilder;
-import android.text.SpannedString;
-import android.text.TextUtils;
-
-import java.awt.BasicStroke;
-import java.awt.Font;
-import java.awt.Toolkit;
-import java.awt.font.FontRenderContext;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * A paint implementation overridden by the LayoutLib bridge.
- */
-public class Paint extends _Original_Paint {
-
-    private int mColor = 0xFFFFFFFF;
-    private float mStrokeWidth = 1.f;
-    private float mTextSize = 20;
-    private float mScaleX = 1;
-    private float mSkewX = 0;
-    private Align mAlign = Align.LEFT;
-    private Style mStyle = Style.FILL;
-    private float mStrokeMiter = 4.0f;
-    private Cap mCap = Cap.BUTT;
-    private Join mJoin = Join.MITER;
-    private int mFlags = 0;
-
-    /**
-     * Class associating a {@link Font} and it's {@link java.awt.FontMetrics}.
-     */
-    public static final class FontInfo {
-        Font mFont;
-        java.awt.FontMetrics mMetrics;
-    }
-
-    private List<FontInfo> mFonts;
-    private final FontRenderContext mFontContext = new FontRenderContext(
-            new AffineTransform(), true, true);
-
-    public static final int ANTI_ALIAS_FLAG       = _Original_Paint.ANTI_ALIAS_FLAG;
-    public static final int FILTER_BITMAP_FLAG    = _Original_Paint.FILTER_BITMAP_FLAG;
-    public static final int DITHER_FLAG           = _Original_Paint.DITHER_FLAG;
-    public static final int UNDERLINE_TEXT_FLAG   = _Original_Paint.UNDERLINE_TEXT_FLAG;
-    public static final int STRIKE_THRU_TEXT_FLAG = _Original_Paint.STRIKE_THRU_TEXT_FLAG;
-    public static final int FAKE_BOLD_TEXT_FLAG   = _Original_Paint.FAKE_BOLD_TEXT_FLAG;
-    public static final int LINEAR_TEXT_FLAG      = _Original_Paint.LINEAR_TEXT_FLAG;
-    public static final int SUBPIXEL_TEXT_FLAG    = _Original_Paint.SUBPIXEL_TEXT_FLAG;
-    public static final int DEV_KERN_TEXT_FLAG    = _Original_Paint.DEV_KERN_TEXT_FLAG;
-
-    public static class FontMetrics extends _Original_Paint.FontMetrics {
-    }
-
-    public static class FontMetricsInt extends _Original_Paint.FontMetricsInt {
-    }
-
-    /**
-     * The Style specifies if the primitive being drawn is filled,
-     * stroked, or both (in the same color). The default is FILL.
-     */
-    public enum Style {
-        /**
-         * Geometry and text drawn with this style will be filled, ignoring all
-         * stroke-related settings in the paint.
-         */
-        FILL            (0),
-        /**
-         * Geometry and text drawn with this style will be stroked, respecting
-         * the stroke-related fields on the paint.
-         */
-        STROKE          (1),
-        /**
-         * Geometry and text drawn with this style will be both filled and
-         * stroked at the same time, respecting the stroke-related fields on
-         * the paint.
-         */
-        FILL_AND_STROKE (2);
-
-        Style(int nativeInt) {
-            this.nativeInt = nativeInt;
-        }
-        final int nativeInt;
-    }
-
-    /**
-     * The Cap specifies the treatment for the beginning and ending of
-     * stroked lines and paths. The default is BUTT.
-     */
-    public enum Cap {
-        /**
-         * The stroke ends with the path, and does not project beyond it.
-         */
-        BUTT    (0),
-        /**
-         * The stroke projects out as a square, with the center at the end
-         * of the path.
-         */
-        ROUND   (1),
-        /**
-         * The stroke projects out as a semicircle, with the center at the
-         * end of the path.
-         */
-        SQUARE  (2);
-
-        private Cap(int nativeInt) {
-            this.nativeInt = nativeInt;
-        }
-        final int nativeInt;
-
-        /** custom for layoutlib */
-        public int getJavaCap() {
-            switch (this) {
-                case BUTT:
-                    return BasicStroke.CAP_BUTT;
-                case ROUND:
-                    return BasicStroke.CAP_ROUND;
-                default:
-                case SQUARE:
-                    return BasicStroke.CAP_SQUARE;
-            }
-        }
-    }
-
-    /**
-     * The Join specifies the treatment where lines and curve segments
-     * join on a stroked path. The default is MITER.
-     */
-    public enum Join {
-        /**
-         * The outer edges of a join meet at a sharp angle
-         */
-        MITER   (0),
-        /**
-         * The outer edges of a join meet in a circular arc.
-         */
-        ROUND   (1),
-        /**
-         * The outer edges of a join meet with a straight line
-         */
-        BEVEL   (2);
-
-        private Join(int nativeInt) {
-            this.nativeInt = nativeInt;
-        }
-        final int nativeInt;
-
-        /** custom for layoutlib */
-        public int getJavaJoin() {
-            switch (this) {
-                default:
-                case MITER:
-                    return BasicStroke.JOIN_MITER;
-                case ROUND:
-                    return BasicStroke.JOIN_ROUND;
-                case BEVEL:
-                    return BasicStroke.JOIN_BEVEL;
-            }
-        }
-    }
-
-    /**
-     * Align specifies how drawText aligns its text relative to the
-     * [x,y] coordinates. The default is LEFT.
-     */
-    public enum Align {
-        /**
-         * The text is drawn to the right of the x,y origin
-         */
-        LEFT    (0),
-        /**
-         * The text is drawn centered horizontally on the x,y origin
-         */
-        CENTER  (1),
-        /**
-         * The text is drawn to the left of the x,y origin
-         */
-        RIGHT   (2);
-
-        private Align(int nativeInt) {
-            this.nativeInt = nativeInt;
-        }
-        final int nativeInt;
-    }
-
-    public Paint() {
-        this(0);
-    }
-
-    /*
-     * Do not remove or com.android.layoutlib.bridge.TestClassReplacement fails.
-     */
-    @Override
-    public void finalize() { }
-
-    public Paint(int flags) {
-        setFlags(flags | DEFAULT_PAINT_FLAGS);
-        initFont();
-    }
-
-    public Paint(Paint paint) {
-        set(paint);
-        initFont();
-    }
-
-    @Override
-    public void reset() {
-        super.reset();
-    }
-
-    /**
-     * Returns the list of {@link Font} objects. The first item is the main font, the rest
-     * are fall backs for characters not present in the main font.
-     */
-    public List<FontInfo> getFonts() {
-        return mFonts;
-    }
-
-    private void initFont() {
-        mTypeface = Typeface.DEFAULT;
-        updateFontObject();
-    }
-
-    /**
-     * Update the {@link Font} object from the typeface, text size and scaling
-     */
-    @SuppressWarnings("deprecation")
-    private void updateFontObject() {
-        if (mTypeface != null) {
-            // Get the fonts from the TypeFace object.
-            List<Font> fonts = Typeface_Delegate.getFonts(mTypeface);
-
-            // create new font objects as well as FontMetrics, based on the current text size
-            // and skew info.
-            ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size());
-            for (Font font : fonts) {
-                FontInfo info = new FontInfo();
-                info.mFont = font.deriveFont(mTextSize);
-                if (mScaleX != 1.0 || mSkewX != 0) {
-                    // TODO: support skew
-                    info.mFont = info.mFont.deriveFont(new AffineTransform(
-                            mScaleX, mSkewX, 0, 0, 1, 0));
-                }
-                info.mMetrics = Toolkit.getDefaultToolkit().getFontMetrics(info.mFont);
-
-                infoList.add(info);
-            }
-
-            mFonts = Collections.unmodifiableList(infoList);
-        }
-    }
-
-    //----------------------------------------
-
-    public void set(Paint src) {
-        if (this != src) {
-            mColor = src.mColor;
-            mTextSize = src.mTextSize;
-            mScaleX = src.mScaleX;
-            mSkewX = src.mSkewX;
-            mAlign = src.mAlign;
-            mStyle = src.mStyle;
-            mFlags = src.mFlags;
-
-            updateFontObject();
-
-            super.set(src);
-        }
-    }
-
-    @Override
-    public void setCompatibilityScaling(float factor) {
-        super.setCompatibilityScaling(factor);
-    }
-
-    @Override
-    public int getFlags() {
-        return mFlags;
-    }
-
-    @Override
-    public void setFlags(int flags) {
-        mFlags = flags;
-    }
-
-    @Override
-    public boolean isAntiAlias() {
-        return super.isAntiAlias();
-    }
-
-    @Override
-    public boolean isDither() {
-        return super.isDither();
-    }
-
-    @Override
-    public boolean isLinearText() {
-        return super.isLinearText();
-    }
-
-    @Override
-    public boolean isStrikeThruText() {
-        return super.isStrikeThruText();
-    }
-
-    @Override
-    public boolean isUnderlineText() {
-        return super.isUnderlineText();
-    }
-
-    @Override
-    public boolean isFakeBoldText() {
-        return super.isFakeBoldText();
-    }
-
-    @Override
-    public boolean isSubpixelText() {
-        return super.isSubpixelText();
-    }
-
-    @Override
-    public boolean isFilterBitmap() {
-        return super.isFilterBitmap();
-    }
-
-    /**
-     * Return the font's recommended interline spacing, given the Paint's
-     * settings for typeface, textSize, etc. If metrics is not null, return the
-     * fontmetric values in it.
-     *
-     * @param metrics If this object is not null, its fields are filled with
-     *                the appropriate values given the paint's text attributes.
-     * @return the font's recommended interline spacing.
-     */
-    public float getFontMetrics(FontMetrics metrics) {
-        if (mFonts.size() > 0) {
-            java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics;
-            if (metrics != null) {
-                // Android expects negative ascent so we invert the value from Java.
-                metrics.top = - javaMetrics.getMaxAscent();
-                metrics.ascent = - javaMetrics.getAscent();
-                metrics.descent = javaMetrics.getDescent();
-                metrics.bottom = javaMetrics.getMaxDescent();
-                metrics.leading = javaMetrics.getLeading();
-            }
-
-            return javaMetrics.getHeight();
-        }
-
-        return 0;
-    }
-
-    public int getFontMetricsInt(FontMetricsInt metrics) {
-        if (mFonts.size() > 0) {
-            java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics;
-            if (metrics != null) {
-                // Android expects negative ascent so we invert the value from Java.
-                metrics.top = - javaMetrics.getMaxAscent();
-                metrics.ascent = - javaMetrics.getAscent();
-                metrics.descent = javaMetrics.getDescent();
-                metrics.bottom = javaMetrics.getMaxDescent();
-                metrics.leading = javaMetrics.getLeading();
-            }
-
-            return javaMetrics.getHeight();
-        }
-
-        return 0;
-    }
-
-    /**
-     * Reimplemented to return Paint.FontMetrics instead of _Original_Paint.FontMetrics
-     */
-    public FontMetrics getFontMetrics() {
-        FontMetrics fm = new FontMetrics();
-        getFontMetrics(fm);
-        return fm;
-    }
-
-    /**
-     * Reimplemented to return Paint.FontMetricsInt instead of _Original_Paint.FontMetricsInt
-     */
-    public FontMetricsInt getFontMetricsInt() {
-        FontMetricsInt fm = new FontMetricsInt();
-        getFontMetricsInt(fm);
-        return fm;
-    }
-
-
-
-    @Override
-    public float getFontMetrics(_Original_Paint.FontMetrics metrics) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    @Override
-    public int getFontMetricsInt(_Original_Paint.FontMetricsInt metrics) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    @Override
-    public Typeface setTypeface(Typeface typeface) {
-        if (typeface != null) {
-            mTypeface = typeface;
-        } else {
-            mTypeface = Typeface.DEFAULT;
-        }
-
-        updateFontObject();
-
-        return typeface;
-    }
-
-    @Override
-    public Typeface getTypeface() {
-        return super.getTypeface();
-    }
-
-    @Override
-    public int getColor() {
-        return mColor;
-    }
-
-    @Override
-    public void setColor(int color) {
-        mColor = color;
-    }
-
-    @Override
-    public void setARGB(int a, int r, int g, int b) {
-        super.setARGB(a, r, g, b);
-    }
-
-    @Override
-    public void setAlpha(int alpha) {
-        mColor = (alpha << 24) | (mColor & 0x00FFFFFF);
-    }
-
-    @Override
-    public int getAlpha() {
-        return mColor >>> 24;
-    }
-
-    /**
-     * Set or clear the shader object.
-     * <p />
-     * Pass null to clear any previous shader.
-     * As a convenience, the parameter passed is also returned.
-     *
-     * @param shader May be null. the new shader to be installed in the paint
-     * @return       shader
-     */
-    @Override
-    public Shader setShader(Shader shader) {
-        return mShader = shader;
-    }
-
-    @Override
-    public Shader getShader() {
-        return super.getShader();
-    }
-
-    /**
-     * Set or clear the paint's colorfilter, returning the parameter.
-     *
-     * @param filter May be null. The new filter to be installed in the paint
-     * @return       filter
-     */
-    @Override
-    public ColorFilter setColorFilter(ColorFilter filter) {
-        mColorFilter = filter;
-        return filter;
-    }
-
-    @Override
-    public ColorFilter getColorFilter() {
-        return super.getColorFilter();
-    }
-
-    /**
-     * Set or clear the xfermode object.
-     * <p />
-     * Pass null to clear any previous xfermode.
-     * As a convenience, the parameter passed is also returned.
-     *
-     * @param xfermode May be null. The xfermode to be installed in the paint
-     * @return         xfermode
-     */
-    @Override
-    public Xfermode setXfermode(Xfermode xfermode) {
-        return mXfermode = xfermode;
-    }
-
-    @Override
-    public Xfermode getXfermode() {
-        return super.getXfermode();
-    }
-
-    @Override
-    public Rasterizer setRasterizer(Rasterizer rasterizer) {
-        mRasterizer = rasterizer;
-        return rasterizer;
-    }
-
-    @Override
-    public Rasterizer getRasterizer() {
-        return super.getRasterizer();
-    }
-
-    @Override
-    public void setShadowLayer(float radius, float dx, float dy, int color) {
-        // TODO Auto-generated method stub
-    }
-
-    @Override
-    public void clearShadowLayer() {
-        super.clearShadowLayer();
-    }
-
-    public void setTextAlign(Align align) {
-        mAlign = align;
-    }
-
-    @Override
-    public void setTextAlign(android.graphics._Original_Paint.Align align) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    public Align getTextAlign() {
-        return mAlign;
-    }
-
-    public void setStyle(Style style) {
-        mStyle = style;
-    }
-
-    @Override
-    public void setStyle(android.graphics._Original_Paint.Style style) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    public Style getStyle() {
-        return mStyle;
-    }
-
-    @Override
-    public void setDither(boolean dither) {
-        mFlags |= dither ? DITHER_FLAG : ~DITHER_FLAG;
-    }
-
-    @Override
-    public void setAntiAlias(boolean aa) {
-        mFlags |= aa ? ANTI_ALIAS_FLAG : ~ANTI_ALIAS_FLAG;
-    }
-
-    @Override
-    public void setFakeBoldText(boolean flag) {
-        mFlags |= flag ? FAKE_BOLD_TEXT_FLAG : ~FAKE_BOLD_TEXT_FLAG;
-    }
-
-    @Override
-    public void setLinearText(boolean flag) {
-        mFlags |= flag ? LINEAR_TEXT_FLAG : ~LINEAR_TEXT_FLAG;
-    }
-
-    @Override
-    public void setSubpixelText(boolean flag) {
-        mFlags |= flag ? SUBPIXEL_TEXT_FLAG : ~SUBPIXEL_TEXT_FLAG;
-    }
-
-    @Override
-    public void setUnderlineText(boolean flag) {
-        mFlags |= flag ? UNDERLINE_TEXT_FLAG : ~UNDERLINE_TEXT_FLAG;
-    }
-
-    @Override
-    public void setStrikeThruText(boolean flag) {
-        mFlags |= flag ? STRIKE_THRU_TEXT_FLAG : ~STRIKE_THRU_TEXT_FLAG;
-    }
-
-    @Override
-    public void setFilterBitmap(boolean flag) {
-        mFlags |= flag ? FILTER_BITMAP_FLAG : ~FILTER_BITMAP_FLAG;
-    }
-
-    @Override
-    public float getStrokeWidth() {
-        return mStrokeWidth;
-    }
-
-    @Override
-    public void setStrokeWidth(float width) {
-        mStrokeWidth = width;
-    }
-
-    @Override
-    public float getStrokeMiter() {
-        return mStrokeMiter;
-    }
-
-    @Override
-    public void setStrokeMiter(float miter) {
-        mStrokeMiter = miter;
-    }
-
-    @Override
-    public void setStrokeCap(android.graphics._Original_Paint.Cap cap) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    public void setStrokeCap(Cap cap) {
-        mCap = cap;
-    }
-
-    public Cap getStrokeCap() {
-        return mCap;
-    }
-
-    @Override
-    public void setStrokeJoin(android.graphics._Original_Paint.Join join) {
-        throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
-    }
-
-    public void setStrokeJoin(Join join) {
-        mJoin = join;
-    }
-
-    public Join getStrokeJoin() {
-        return mJoin;
-    }
-
-    @Override
-    public boolean getFillPath(Path src, Path dst) {
-        return super.getFillPath(src, dst);
-    }
-
-    @Override
-    public PathEffect setPathEffect(PathEffect effect) {
-        mPathEffect = effect;
-        return effect;
-    }
-
-    @Override
-    public PathEffect getPathEffect() {
-        return super.getPathEffect();
-    }
-
-    @Override
-    public MaskFilter setMaskFilter(MaskFilter maskfilter) {
-        mMaskFilter = maskfilter;
-        return maskfilter;
-    }
-
-    @Override
-    public MaskFilter getMaskFilter() {
-        return super.getMaskFilter();
-    }
-
-    /**
-     * Return the paint's text size.
-     *
-     * @return the paint's text size.
-     */
-    @Override
-    public float getTextSize() {
-        return mTextSize;
-    }
-
-    /**
-     * Set the paint's text size. This value must be > 0
-     *
-     * @param textSize set the paint's text size.
-     */
-    @Override
-    public void setTextSize(float textSize) {
-        mTextSize = textSize;
-
-        updateFontObject();
-    }
-
-    /**
-     * Return the paint's horizontal scale factor for text. The default value
-     * is 1.0.
-     *
-     * @return the paint's scale factor in X for drawing/measuring text
-     */
-    @Override
-    public float getTextScaleX() {
-        return mScaleX;
-    }
-
-    /**
-     * Set the paint's horizontal scale factor for text. The default value
-     * is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will
-     * stretch the text narrower.
-     *
-     * @param scaleX set the paint's scale in X for drawing/measuring text.
-     */
-    @Override
-    public void setTextScaleX(float scaleX) {
-        mScaleX = scaleX;
-
-        updateFontObject();
-    }
-
-    /**
-     * Return the paint's horizontal skew factor for text. The default value
-     * is 0.
-     *
-     * @return         the paint's skew factor in X for drawing text.
-     */
-    @Override
-    public float getTextSkewX() {
-        return mSkewX;
-    }
-
-    /**
-     * Set the paint's horizontal skew factor for text. The default value
-     * is 0. For approximating oblique text, use values around -0.25.
-     *
-     * @param skewX set the paint's skew factor in X for drawing text.
-     */
-    @Override
-    public void setTextSkewX(float skewX) {
-        mSkewX = skewX;
-
-        updateFontObject();
-    }
-
-    @Override
-    public float getFontSpacing() {
-        return super.getFontSpacing();
-    }
-
-    /**
-     * Return the distance above (negative) the baseline (ascent) based on the
-     * current typeface and text size.
-     *
-     * @return the distance above (negative) the baseline (ascent) based on the
-     *         current typeface and text size.
-     */
-    @Override
-    public float ascent() {
-        if (mFonts.size() > 0) {
-            java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics;
-            // Android expects negative ascent so we invert the value from Java.
-            return - javaMetrics.getAscent();
-        }
-
-        return 0;
-    }
-
-    /**
-     * Return the distance below (positive) the baseline (descent) based on the
-     * current typeface and text size.
-     *
-     * @return the distance below (positive) the baseline (descent) based on
-     *         the current typeface and text size.
-     */
-    @Override
-    public float descent() {
-        if (mFonts.size() > 0) {
-            java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics;
-            return javaMetrics.getDescent();
-        }
-
-        return 0;
-    }
-
-    /**
-     * Return the width of the text.
-     *
-     * @param text  The text to measure
-     * @param index The index of the first character to start measuring
-     * @param count THe number of characters to measure, beginning with start
-     * @return      The width of the text
-     */
-    @Override
-    public float measureText(char[] text, int index, int count) {
-        // WARNING: the logic in this method is similar to Canvas.drawText.
-        // Any change to this method should be reflected in Canvas.drawText
-        if (mFonts.size() > 0) {
-            FontInfo mainFont = mFonts.get(0);
-            int i = index;
-            int lastIndex = index + count;
-            float total = 0f;
-            while (i < lastIndex) {
-                // always start with the main font.
-                int upTo = mainFont.mFont.canDisplayUpTo(text, i, lastIndex);
-                if (upTo == -1) {
-                    // shortcut to exit
-                    return total + mainFont.mMetrics.charsWidth(text, i, lastIndex - i);
-                } else if (upTo > 0) {
-                    total += mainFont.mMetrics.charsWidth(text, i, upTo - i);
-                    i = upTo;
-                    // don't call continue at this point. Since it is certain the main font
-                    // cannot display the font a index upTo (now ==i), we move on to the
-                    // fallback fonts directly.
-                }
-
-                // no char supported, attempt to read the next char(s) with the
-                // fallback font. In this case we only test the first character
-                // and then go back to test with the main font.
-                // Special test for 2-char characters.
-                boolean foundFont = false;
-                for (int f = 1 ; f < mFonts.size() ; f++) {
-                    FontInfo fontInfo = mFonts.get(f);
-
-                    // need to check that the font can display the character. We test
-                    // differently if the char is a high surrogate.
-                    int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1;
-                    upTo = fontInfo.mFont.canDisplayUpTo(text, i, i + charCount);
-                    if (upTo == -1) {
-                        total += fontInfo.mMetrics.charsWidth(text, i, charCount);
-                        i += charCount;
-                        foundFont = true;
-                        break;
-
-                    }
-                }
-
-                // in case no font can display the char, measure it with the main font.
-                if (foundFont == false) {
-                    int size = Character.isHighSurrogate(text[i]) ? 2 : 1;
-                    total += mainFont.mMetrics.charsWidth(text, i, size);
-                    i += size;
-                }
-            }
-        }
-
-        return 0;
-    }
-
-    /**
-     * Return the width of the text.
-     *
-     * @param text  The text to measure
-     * @param start The index of the first character to start measuring
-     * @param end   1 beyond the index of the last character to measure
-     * @return      The width of the text
-     */
-    @Override
-    public float measureText(String text, int start, int end) {
-        return measureText(text.toCharArray(), start, end - start);
-    }
-
-    /**
-     * Return the width of the text.
-     *
-     * @param text  The text to measure
-     * @return      The width of the text
-     */
-    @Override
-    public float measureText(String text) {
-        return measureText(text.toCharArray(), 0, text.length());
-    }
-
-    /*
-     * re-implement to call SpannableStringBuilder.measureText with a Paint object
-     * instead of an _Original_Paint
-     */
-    @Override
-    public float measureText(CharSequence text, int start, int end) {
-        if (text instanceof String) {
-            return measureText((String)text, start, end);
-        }
-        if (text instanceof SpannedString ||
-            text instanceof SpannableString) {
-            return measureText(text.toString(), start, end);
-        }
-        if (text instanceof SpannableStringBuilder) {
-            return ((SpannableStringBuilder)text).measureText(start, end, this);
-        }
-
-        char[] buf = TemporaryBuffer.obtain(end - start);
-        TextUtils.getChars(text, start, end, buf, 0);
-        float result = measureText(buf, 0, end - start);
-        TemporaryBuffer.recycle(buf);
-        return result;
-    }
-
-    /**
-     * Measure the text, stopping early if the measured width exceeds maxWidth.
-     * Return the number of chars that were measured, and if measuredWidth is
-     * not null, return in it the actual width measured.
-     *
-     * @param text  The text to measure
-     * @param index The offset into text to begin measuring at
-     * @param count The number of maximum number of entries to measure. If count
-     *              is negative, then the characters before index are measured
-     *              in reverse order. This allows for measuring the end of
-     *              string.
-     * @param maxWidth The maximum width to accumulate.
-     * @param measuredWidth Optional. If not null, returns the actual width
-     *                     measured.
-     * @return The number of chars that were measured. Will always be <=
-     *         abs(count).
-     */
-    @Override
-    public int breakText(char[] text, int index, int count,
-                                float maxWidth, float[] measuredWidth) {
-        int inc = count > 0 ? 1 : -1;
-
-        int measureIndex = 0;
-        float measureAcc = 0;
-        for (int i = index ; i != index + count ; i += inc, measureIndex++) {
-            int start, end;
-            if (i < index) {
-                start = i;
-                end = index;
-            } else {
-                start = index;
-                end = i;
-            }
-
-            // measure from start to end
-            float res = measureText(text, start, end - start + 1);
-
-            if (measuredWidth != null) {
-                measuredWidth[measureIndex] = res;
-            }
-
-            measureAcc += res;
-            if (res > maxWidth) {
-                // we should not return this char index, but since it's 0-based and we need
-                // to return a count, we simply return measureIndex;
-                return measureIndex;
-            }
-
-        }
-
-        return measureIndex;
-    }
-
-    /**
-     * Measure the text, stopping early if the measured width exceeds maxWidth.
-     * Return the number of chars that were measured, and if measuredWidth is
-     * not null, return in it the actual width measured.
-     *
-     * @param text  The text to measure
-     * @param measureForwards If true, measure forwards, starting at index.
-     *                        Otherwise, measure backwards, starting with the
-     *                        last character in the string.
-     * @param maxWidth The maximum width to accumulate.
-     * @param measuredWidth Optional. If not null, returns the actual width
-     *                     measured.
-     * @return The number of chars that were measured. Will always be <=
-     *         abs(count).
-     */
-    @Override
-    public int breakText(String text, boolean measureForwards,
-                                float maxWidth, float[] measuredWidth) {
-        return breakText(text,
-                0 /* start */, text.length() /* end */,
-                measureForwards, maxWidth, measuredWidth);
-    }
-
-    /**
-     * Measure the text, stopping early if the measured width exceeds maxWidth.
-     * Return the number of chars that were measured, and if measuredWidth is
-     * not null, return in it the actual width measured.
-     *
-     * @param text  The text to measure
-     * @param start The offset into text to begin measuring at
-     * @param end   The end of the text slice to measure.
-     * @param measureForwards If true, measure forwards, starting at start.
-     *                        Otherwise, measure backwards, starting with end.
-     * @param maxWidth The maximum width to accumulate.
-     * @param measuredWidth Optional. If not null, returns the actual width
-     *                     measured.
-     * @return The number of chars that were measured. Will always be <=
-     *         abs(end - start).
-     */
-    @Override
-    public int breakText(CharSequence text, int start, int end, boolean measureForwards,
-            float maxWidth, float[] measuredWidth) {
-        char[] buf = new char[end - start];
-        int result;
-
-        TextUtils.getChars(text, start, end, buf, 0);
-
-        if (measureForwards) {
-            result = breakText(buf, 0, end - start, maxWidth, measuredWidth);
-        } else {
-            result = breakText(buf, 0, -(end - start), maxWidth, measuredWidth);
-        }
-
-        return result;
-    }
-
-    /**
-     * Return the advance widths for the characters in the string.
-     *
-     * @param text     The text to measure
-     * @param index    The index of the first char to to measure
-     * @param count    The number of chars starting with index to measure
-     * @param widths   array to receive the advance widths of the characters.
-     *                 Must be at least a large as count.
-     * @return         the actual number of widths returned.
-     */
-    @Override
-    public int getTextWidths(char[] text, int index, int count,
-                             float[] widths) {
-        if (mFonts.size() > 0) {
-            if ((index | count) < 0 || index + count > text.length
-                    || count > widths.length) {
-                throw new ArrayIndexOutOfBoundsException();
-            }
-
-            // FIXME: handle multi-char characters.
-            // Need to figure out if the lengths of the width array takes into account
-            // multi-char characters.
-            for (int i = 0; i < count; i++) {
-                char c = text[i + index];
-                boolean found = false;
-                for (FontInfo info : mFonts) {
-                    if (info.mFont.canDisplay(c)) {
-                        widths[i] = info.mMetrics.charWidth(c);
-                        found = true;
-                        break;
-                    }
-                }
-
-                if (found == false) {
-                    // we stop there.
-                    return i;
-                }
-            }
-
-            return count;
-        }
-
-        return 0;
-    }
-
-    /**
-     * Return the advance widths for the characters in the string.
-     *
-     * @param text   The text to measure
-     * @param start  The index of the first char to to measure
-     * @param end    The end of the text slice to measure
-     * @param widths array to receive the advance widths of the characters.
-     *               Must be at least a large as the text.
-     * @return       the number of unichars in the specified text.
-     */
-    @Override
-    public int getTextWidths(String text, int start, int end, float[] widths) {
-        if ((start | end | (end - start) | (text.length() - end)) < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (end - start > widths.length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
-
-        return getTextWidths(text.toCharArray(), start, end - start, widths);
-    }
-
-    /*
-     * re-implement to call SpannableStringBuilder.getTextWidths with a Paint object
-     * instead of an _Original_Paint
-     */
-    @Override
-    public int getTextWidths(CharSequence text, int start, int end, float[] widths) {
-        if (text instanceof String) {
-            return getTextWidths((String)text, start, end, widths);
-        }
-        if (text instanceof SpannedString || text instanceof SpannableString) {
-            return getTextWidths(text.toString(), start, end, widths);
-        }
-        if (text instanceof SpannableStringBuilder) {
-            return ((SpannableStringBuilder)text).getTextWidths(start, end, widths, this);
-        }
-
-        char[] buf = TemporaryBuffer.obtain(end - start);
-        TextUtils.getChars(text, start, end, buf, 0);
-        int result = getTextWidths(buf, 0, end - start, widths);
-        TemporaryBuffer.recycle(buf);
-        return result;
-    }
-
-    @Override
-    public int getTextWidths(String text, float[] widths) {
-        return super.getTextWidths(text, widths);
-    }
-
-    /**
-     * Return the path (outline) for the specified text.
-     * Note: just like Canvas.drawText, this will respect the Align setting in
-     * the paint.
-     *
-     * @param text     The text to retrieve the path from
-     * @param index    The index of the first character in text
-     * @param count    The number of characterss starting with index
-     * @param x        The x coordinate of the text's origin
-     * @param y        The y coordinate of the text's origin
-     * @param path     The path to receive the data describing the text. Must
-     *                 be allocated by the caller.
-     */
-    @Override
-    public void getTextPath(char[] text, int index, int count,
-                            float x, float y, Path path) {
-
-        // TODO this is the ORIGINAL implementation. REPLACE AS NEEDED OR REMOVE
-
-        if ((index | count) < 0 || index + count > text.length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
-
-        // TODO native_getTextPath(mNativePaint, text, index, count, x, y, path.ni());
-
-        throw new UnsupportedOperationException("IMPLEMENT AS NEEDED");
-    }
-
-    /**
-     * Return the path (outline) for the specified text.
-     * Note: just like Canvas.drawText, this will respect the Align setting
-     * in the paint.
-     *
-     * @param text  The text to retrieve the path from
-     * @param start The first character in the text
-     * @param end   1 past the last charcter in the text
-     * @param x     The x coordinate of the text's origin
-     * @param y     The y coordinate of the text's origin
-     * @param path  The path to receive the data describing the text. Must
-     *              be allocated by the caller.
-     */
-    @Override
-    public void getTextPath(String text, int start, int end,
-                            float x, float y, Path path) {
-        if ((start | end | (end - start) | (text.length() - end)) < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-
-        getTextPath(text.toCharArray(), start, end - start, x, y, path);
-    }
-
-    /**
-     * Return in bounds (allocated by the caller) the smallest rectangle that
-     * encloses all of the characters, with an implied origin at (0,0).
-     *
-     * @param text  String to measure and return its bounds
-     * @param start Index of the first char in the string to measure
-     * @param end   1 past the last char in the string measure
-     * @param bounds Returns the unioned bounds of all the text. Must be
-     *               allocated by the caller.
-     */
-    @Override
-    public void getTextBounds(String text, int start, int end, Rect bounds) {
-        if ((start | end | (end - start) | (text.length() - end)) < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (bounds == null) {
-            throw new NullPointerException("need bounds Rect");
-        }
-
-        getTextBounds(text.toCharArray(), start, end - start, bounds);
-    }
-
-    /**
-     * Return in bounds (allocated by the caller) the smallest rectangle that
-     * encloses all of the characters, with an implied origin at (0,0).
-     *
-     * @param text  Array of chars to measure and return their unioned bounds
-     * @param index Index of the first char in the array to measure
-     * @param count The number of chars, beginning at index, to measure
-     * @param bounds Returns the unioned bounds of all the text. Must be
-     *               allocated by the caller.
-     */
-    @Override
-    public void getTextBounds(char[] text, int index, int count, Rect bounds) {
-        // FIXME
-        if (mFonts.size() > 0) {
-            if ((index | count) < 0 || index + count > text.length) {
-                throw new ArrayIndexOutOfBoundsException();
-            }
-            if (bounds == null) {
-                throw new NullPointerException("need bounds Rect");
-            }
-
-            FontInfo mainInfo = mFonts.get(0);
-
-            Rectangle2D rect = mainInfo.mFont.getStringBounds(text, index, index + count, mFontContext);
-            bounds.set(0, 0, (int)rect.getWidth(), (int)rect.getHeight());
-        }
-    }
-
-    public static void finalizer(int foo) {
-        // pass
-    }
-}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
new file mode 100644
index 0000000..6e90bdd
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -0,0 +1,963 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+import android.graphics.Paint.FontMetrics;
+import android.graphics.Paint.FontMetricsInt;
+import android.text.TextUtils;
+
+import java.awt.BasicStroke;
+import java.awt.Font;
+import java.awt.Toolkit;
+import java.awt.font.FontRenderContext;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Delegate implementing the native methods of android.graphics.Paint
+ *
+ * Through the layoutlib_create tool, the original native methods of Paint have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original Paint class.
+ *
+ * @see DelegateManager
+ *
+ */
+public class Paint_Delegate {
+
+    /**
+     * Class associating a {@link Font} and it's {@link java.awt.FontMetrics}.
+     */
+    /*package*/ static final class FontInfo {
+        Font mFont;
+        java.awt.FontMetrics mMetrics;
+    }
+
+    // ---- delegate manager ----
+    private static final DelegateManager<Paint_Delegate> sManager =
+            new DelegateManager<Paint_Delegate>();
+
+    // ---- delegate helper data ----
+    private List<FontInfo> mFonts;
+    private final FontRenderContext mFontContext = new FontRenderContext(
+            new AffineTransform(), true, true);
+
+    // ---- delegate data ----
+    private int mFlags;
+    private int mColor;
+    private int mStyle;
+    private int mCap;
+    private int mJoin;
+    private int mTextAlign;
+    private int mTypeface;
+    private float mStrokeWidth;
+    private float mStrokeMiter;
+    private float mTextSize;
+    private float mTextScaleX;
+    private float mTextSkewX;
+
+    private int mXfermode;
+    private int mColorFilter;
+    private int mShader;
+    private int mPathEffect;
+    private int mMaskFilter;
+
+
+    // ---- Public Helper methods ----
+
+    public static Paint_Delegate getDelegate(int native_paint) {
+        return sManager.getDelegate(native_paint);
+    }
+
+    /**
+     * Returns the list of {@link Font} objects. The first item is the main font, the rest
+     * are fall backs for characters not present in the main font.
+     */
+    public List<FontInfo> getFonts() {
+        return mFonts;
+    }
+
+    public boolean isAntiAliased() {
+        return (mFlags & Paint.ANTI_ALIAS_FLAG) != 0;
+    }
+
+    public boolean isFilterBitmap() {
+        return (mFlags & Paint.FILTER_BITMAP_FLAG) != 0;
+    }
+
+    public int getStyle() {
+        return mStyle;
+    }
+
+    public int getColor() {
+        return mColor;
+    }
+
+    public int getAlpha() {
+        return mColor >>> 24;
+    }
+
+    public int getTextAlign() {
+        return mTextAlign;
+    }
+
+    public float getStrokeWidth() {
+        return mStrokeWidth;
+    }
+
+    public float getStrokeMiter() {
+        return mStrokeMiter;
+    }
+
+    public int getJavaCap() {
+        switch (Paint.sCapArray[mCap]) {
+            case BUTT:
+                return BasicStroke.CAP_BUTT;
+            case ROUND:
+                return BasicStroke.CAP_ROUND;
+            default:
+            case SQUARE:
+                return BasicStroke.CAP_SQUARE;
+        }
+    }
+
+    public int getJavaJoin() {
+        switch (Paint.sJoinArray[mJoin]) {
+            default:
+            case MITER:
+                return BasicStroke.JOIN_MITER;
+            case ROUND:
+                return BasicStroke.JOIN_ROUND;
+            case BEVEL:
+                return BasicStroke.JOIN_BEVEL;
+        }
+    }
+
+    public int getXfermode() {
+        return mXfermode;
+    }
+
+    public int getColorFilter() {
+        return mColorFilter;
+    }
+
+    public int getShader() {
+        return mShader;
+    }
+
+    public int getPathEffect() {
+        return mPathEffect;
+    }
+
+    public int getMaskFilter() {
+        return mMaskFilter;
+    }
+
+    // ---- native methods ----
+
+    /*package*/ static int getFlags(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mFlags;
+    }
+
+    /*package*/ static void setFlags(Paint thisPaint, int flags) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mFlags = flags;
+    }
+
+    /*package*/ static void setFilterBitmap(Paint thisPaint, boolean filter) {
+        setFlag(thisPaint, Paint.FILTER_BITMAP_FLAG, filter);
+    }
+
+    /*package*/ static void setAntiAlias(Paint thisPaint, boolean aa) {
+        setFlag(thisPaint, Paint.ANTI_ALIAS_FLAG, aa);
+    }
+
+    /*package*/ static void setSubpixelText(Paint thisPaint, boolean subpixelText) {
+        setFlag(thisPaint, Paint.SUBPIXEL_TEXT_FLAG, subpixelText);
+    }
+
+    /*package*/ static void setUnderlineText(Paint thisPaint, boolean underlineText) {
+        setFlag(thisPaint, Paint.UNDERLINE_TEXT_FLAG, underlineText);
+    }
+
+    /*package*/ static void setStrikeThruText(Paint thisPaint, boolean strikeThruText) {
+        setFlag(thisPaint, Paint.STRIKE_THRU_TEXT_FLAG, strikeThruText);
+    }
+
+    /*package*/ static void setFakeBoldText(Paint thisPaint, boolean fakeBoldText) {
+        setFlag(thisPaint, Paint.FAKE_BOLD_TEXT_FLAG, fakeBoldText);
+    }
+
+    /*package*/ static void setDither(Paint thisPaint, boolean dither) {
+        setFlag(thisPaint, Paint.DITHER_FLAG, dither);
+    }
+
+    /*package*/ static void setLinearText(Paint thisPaint, boolean linearText) {
+        setFlag(thisPaint, Paint.LINEAR_TEXT_FLAG, linearText);
+    }
+
+    /*package*/ static int getColor(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mColor;
+    }
+
+    /*package*/ static void setColor(Paint thisPaint, int color) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mColor = color;
+    }
+
+    /*package*/ static int getAlpha(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.getAlpha();
+    }
+
+    /*package*/ static void setAlpha(Paint thisPaint, int a) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mColor = (a << 24) | (delegate.mColor & 0x00FFFFFF);
+    }
+
+    /*package*/ static float getStrokeWidth(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 1.f;
+        }
+
+        return delegate.mStrokeWidth;
+    }
+
+    /*package*/ static void setStrokeWidth(Paint thisPaint, float width) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mStrokeWidth = width;
+    }
+
+    /*package*/ static float getStrokeMiter(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 1.f;
+        }
+
+        return delegate.mStrokeMiter;
+    }
+
+    /*package*/ static void setStrokeMiter(Paint thisPaint, float miter) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mStrokeMiter = miter;
+    }
+
+    /*package*/ static void nSetShadowLayer(Paint thisPaint, float radius, float dx, float dy,
+            int color) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static float getTextSize(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 1.f;
+        }
+
+        return delegate.mTextSize;
+    }
+
+    /*package*/ static void setTextSize(Paint thisPaint, float textSize) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mTextSize = textSize;
+    }
+
+    /*package*/ static float getTextScaleX(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 1.f;
+        }
+
+        return delegate.mTextScaleX;
+    }
+
+    /*package*/ static void setTextScaleX(Paint thisPaint, float scaleX) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mTextScaleX = scaleX;
+    }
+
+    /*package*/ static float getTextSkewX(Paint thisPaint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 1.f;
+        }
+
+        return delegate.mTextSkewX;
+    }
+
+    /*package*/ static void setTextSkewX(Paint thisPaint, float skewX) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mTextSkewX = skewX;
+    }
+
+    /*package*/ static float ascent(Paint thisPaint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static float descent(Paint thisPaint) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static float getFontMetrics(Paint thisPaint, FontMetrics metrics) {
+        // get the delegate
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        if (delegate.mFonts.size() > 0) {
+            java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics;
+            if (metrics != null) {
+                // Android expects negative ascent so we invert the value from Java.
+                metrics.top = - javaMetrics.getMaxAscent();
+                metrics.ascent = - javaMetrics.getAscent();
+                metrics.descent = javaMetrics.getDescent();
+                metrics.bottom = javaMetrics.getMaxDescent();
+                metrics.leading = javaMetrics.getLeading();
+            }
+
+            return javaMetrics.getHeight();
+        }
+
+        return 0;
+    }
+
+    /*package*/ static int getFontMetricsInt(Paint thisPaint, FontMetricsInt fmi) {
+        // get the delegate
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        if (delegate.mFonts.size() > 0) {
+            java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics;
+            if (fmi != null) {
+                // Android expects negative ascent so we invert the value from Java.
+                fmi.top = - javaMetrics.getMaxAscent();
+                fmi.ascent = - javaMetrics.getAscent();
+                fmi.descent = javaMetrics.getDescent();
+                fmi.bottom = javaMetrics.getMaxDescent();
+                fmi.leading = javaMetrics.getLeading();
+            }
+
+            return javaMetrics.getHeight();
+        }
+
+        return 0;
+    }
+
+    /*package*/ static float native_measureText(Paint thisPaint, char[] text, int index,
+            int count) {
+        // WARNING: the logic in this method is similar to Canvas.drawText.
+        // Any change to this method should be reflected in Canvas.drawText
+
+        // get the delegate
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.measureText(text, index, count);
+    }
+
+    /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end) {
+        return native_measureText(thisPaint, text.toCharArray(), start, end - start);
+    }
+
+    /*package*/ static float native_measureText(Paint thisPaint, String text) {
+        return native_measureText(thisPaint, text.toCharArray(), 0, text.length());
+    }
+
+    /*package*/ static int native_breakText(Paint thisPaint, char[] text, int index, int count,
+            float maxWidth, float[] measuredWidth) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_breakText(Paint thisPaint, String text, boolean measureForwards,
+            float maxWidth, float[] measuredWidth) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+
+    /*package*/ static int native_init() {
+        Paint_Delegate newDelegate = new Paint_Delegate();
+        return sManager.addDelegate(newDelegate);
+    }
+
+    /*package*/ static int native_initWithPaint(int paint) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(paint);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        Paint_Delegate newDelegate = new Paint_Delegate(delegate);
+        return sManager.addDelegate(newDelegate);
+    }
+
+    /*package*/ static void native_reset(int native_object) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.reset();
+    }
+
+    /*package*/ static void native_set(int native_dst, int native_src) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate_dst = sManager.getDelegate(native_dst);
+        if (delegate_dst == null) {
+            assert false;
+            return;
+        }
+
+        // get the delegate from the native int.
+        Paint_Delegate delegate_src = sManager.getDelegate(native_src);
+        if (delegate_src == null) {
+            assert false;
+            return;
+        }
+
+        delegate_dst.set(delegate_src);
+    }
+
+    /*package*/ static int native_getStyle(int native_object) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mStyle;
+    }
+
+    /*package*/ static void native_setStyle(int native_object, int style) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mStyle = style;
+    }
+
+    /*package*/ static int native_getStrokeCap(int native_object) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mCap;
+    }
+
+    /*package*/ static void native_setStrokeCap(int native_object, int cap) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mCap = cap;
+    }
+
+    /*package*/ static int native_getStrokeJoin(int native_object) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mJoin;
+    }
+
+    /*package*/ static void native_setStrokeJoin(int native_object, int join) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mJoin = join;
+    }
+
+    /*package*/ static boolean native_getFillPath(int native_object, int src, int dst) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_setShader(int native_object, int shader) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return shader;
+        }
+
+        return delegate.mShader = shader;
+    }
+
+    /*package*/ static int native_setColorFilter(int native_object, int filter) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return filter;
+        }
+
+        return delegate.mColorFilter = filter;
+    }
+
+    /*package*/ static int native_setXfermode(int native_object, int xfermode) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return xfermode;
+        }
+
+        return delegate.mXfermode = xfermode;
+    }
+
+    /*package*/ static int native_setPathEffect(int native_object, int effect) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return effect;
+        }
+
+        return delegate.mPathEffect = effect;
+    }
+
+    /*package*/ static int native_setMaskFilter(int native_object, int maskfilter) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return maskfilter;
+        }
+
+        return delegate.mMaskFilter = maskfilter;
+    }
+
+    /*package*/ static int native_setTypeface(int native_object, int typeface) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mTypeface = typeface;
+    }
+
+    /*package*/ static int native_setRasterizer(int native_object, int rasterizer) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+
+    /*package*/ static int native_getTextAlign(int native_object) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return 0;
+        }
+
+        return delegate.mTextAlign;
+    }
+
+    /*package*/ static void native_setTextAlign(int native_object, int align) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        delegate.mTextAlign = align;
+    }
+
+    /*package*/ static float native_getFontMetrics(int native_paint, FontMetrics metrics) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_getTextWidths(int native_object, char[] text, int index,
+            int count, float[] widths) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_getTextWidths(int native_object, String text, int start,
+            int end, float[] widths) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static float native_getTextRunAdvances(int native_object,
+            char[] text, int index, int count, int contextIndex, int contextCount,
+            int flags, float[] advances, int advancesIndex) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(native_object);
+        if (delegate == null) {
+            assert false;
+            return 0.f;
+        }
+
+        if (delegate.mFonts.size() > 0) {
+            // FIXME: handle multi-char characters (see measureText)
+            float totalAdvance = 0;
+            for (int i = 0; i < count; i++) {
+                char c = text[i + index];
+                boolean found = false;
+                for (FontInfo info : delegate.mFonts) {
+                    if (info.mFont.canDisplay(c)) {
+                        float adv = info.mMetrics.charWidth(c);
+                        totalAdvance += adv;
+                        if (advances != null) {
+                            advances[i] = adv;
+                        }
+
+                        found = true;
+                        break;
+                    }
+                }
+
+                if (found == false) {
+                    // no advance for this char.
+                    if (advances != null) {
+                        advances[i] = 0.f;
+                    }
+                }
+            }
+
+            return totalAdvance;
+        }
+
+        return 0;
+
+    }
+
+    /*package*/ static float native_getTextRunAdvances(int native_object,
+            String text, int start, int end, int contextStart, int contextEnd,
+            int flags, float[] advances, int advancesIndex) {
+        // FIXME: support contextStart, contextEnd and direction flag
+        int count = end - start;
+        char[] buffer = TemporaryBuffer.obtain(count);
+        TextUtils.getChars(text, start, end, buffer, 0);
+
+        return native_getTextRunAdvances(native_object, buffer, 0, count, contextStart,
+                contextEnd - contextStart, flags, advances, advancesIndex);
+    }
+
+    /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, char[] text,
+            int contextStart, int contextLength, int flags, int offset, int cursorOpt) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, String text,
+            int contextStart, int contextEnd, int flags, int offset, int cursorOpt) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_getTextPath(int native_object, int bidiFlags,
+                char[] text, int index, int count, float x, float y, int path) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void native_getTextPath(int native_object, int bidiFlags,
+            String text, int start, int end, float x, float y, int path) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start,
+            int end, Rect bounds) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index,
+            int count, Rect bounds) {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
+    /*package*/ static void finalizer(int nativePaint) {
+        sManager.removeDelegate(nativePaint);
+    }
+
+    // ---- Private delegate/helper methods ----
+
+    private Paint_Delegate() {
+        reset();
+
+        mTypeface = Typeface.sDefaults[0].native_instance;
+        updateFontObject();
+    }
+
+    private Paint_Delegate(Paint_Delegate paint) {
+        set(paint);
+        updateFontObject();
+    }
+
+    private void set(Paint_Delegate paint) {
+        mFlags = paint.mFlags;
+        mColor = paint.mColor;
+        mStyle = paint.mStyle;
+        mCap = paint.mCap;
+        mJoin = paint.mJoin;
+        mTextAlign = paint.mTextAlign;
+        mTypeface = paint.mTypeface;
+        mStrokeWidth = paint.mStrokeWidth;
+        mStrokeMiter = paint.mStrokeMiter;
+        mTextSize = paint.mTextSize;
+        mTextScaleX = paint.mTextScaleX;
+        mTextSkewX = paint.mTextSkewX;
+        mXfermode = paint.mXfermode;
+        mColorFilter = paint.mColorFilter;
+        mShader = paint.mShader;
+        mPathEffect = paint.mPathEffect;
+        mMaskFilter = paint.mMaskFilter;
+    }
+
+    private void reset() {
+        mFlags = Paint.DEFAULT_PAINT_FLAGS;
+        mColor = 0;
+        mStyle = 0;
+        mCap = 0;
+        mJoin = 0;
+        mTextAlign = 0;
+        mTypeface = 0;
+        mStrokeWidth = 1.f;
+        mStrokeMiter = 2.f;
+        mTextSize = 20.f;
+        mTextScaleX = 1.f;
+        mTextSkewX = 0.f;
+        mXfermode = 0;
+        mColorFilter = 0;
+        mShader = 0;
+        mPathEffect = 0;
+        mMaskFilter = 0;
+    }
+
+    /**
+     * Update the {@link Font} object from the typeface, text size and scaling
+     */
+    private void updateFontObject() {
+        if (mTypeface != 0) {
+            // Get the fonts from the TypeFace object.
+            List<Font> fonts = Typeface_Delegate.getFonts(mTypeface);
+
+            // create new font objects as well as FontMetrics, based on the current text size
+            // and skew info.
+            ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size());
+            for (Font font : fonts) {
+                FontInfo info = new FontInfo();
+                info.mFont = font.deriveFont(mTextSize);
+                if (mTextScaleX != 1.0 || mTextSkewX != 0) {
+                    // TODO: support skew
+                    info.mFont = info.mFont.deriveFont(new AffineTransform(
+                            mTextScaleX, mTextSkewX, 0, 0, 1, 0));
+                }
+                info.mMetrics = Toolkit.getDefaultToolkit().getFontMetrics(info.mFont);
+
+                infoList.add(info);
+            }
+
+            mFonts = Collections.unmodifiableList(infoList);
+        }
+    }
+
+    /*package*/ float measureText(char[] text, int index, int count) {
+        if (mFonts.size() > 0) {
+            FontInfo mainFont = mFonts.get(0);
+            int i = index;
+            int lastIndex = index + count;
+            float total = 0f;
+            while (i < lastIndex) {
+                // always start with the main font.
+                int upTo = mainFont.mFont.canDisplayUpTo(text, i, lastIndex);
+                if (upTo == -1) {
+                    // shortcut to exit
+                    return total + mainFont.mMetrics.charsWidth(text, i, lastIndex - i);
+                } else if (upTo > 0) {
+                    total += mainFont.mMetrics.charsWidth(text, i, upTo - i);
+                    i = upTo;
+                    // don't call continue at this point. Since it is certain the main font
+                    // cannot display the font a index upTo (now ==i), we move on to the
+                    // fallback fonts directly.
+                }
+
+                // no char supported, attempt to read the next char(s) with the
+                // fallback font. In this case we only test the first character
+                // and then go back to test with the main font.
+                // Special test for 2-char characters.
+                boolean foundFont = false;
+                for (int f = 1 ; f < mFonts.size() ; f++) {
+                    FontInfo fontInfo = mFonts.get(f);
+
+                    // need to check that the font can display the character. We test
+                    // differently if the char is a high surrogate.
+                    int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1;
+                    upTo = fontInfo.mFont.canDisplayUpTo(text, i, i + charCount);
+                    if (upTo == -1) {
+                        total += fontInfo.mMetrics.charsWidth(text, i, charCount);
+                        i += charCount;
+                        foundFont = true;
+                        break;
+
+                    }
+                }
+
+                // in case no font can display the char, measure it with the main font.
+                if (foundFont == false) {
+                    int size = Character.isHighSurrogate(text[i]) ? 2 : 1;
+                    total += mainFont.mMetrics.charsWidth(text, i, size);
+                    i += size;
+                }
+            }
+        }
+
+        return 0;
+
+    }
+
+    private static void setFlag(Paint thisPaint, int flagMask, boolean flagValue) {
+        // get the delegate from the native int.
+        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
+        if (delegate == null) {
+            assert false;
+            return;
+        }
+
+        if (flagValue) {
+            delegate.mFlags |= flagMask;
+        } else {
+            delegate.mFlags &= ~flagMask;
+        }
+    }
+}
diff --git a/tools/layoutlib/bridge/src/android/graphics/RadialGradient.java b/tools/layoutlib/bridge/src/android/graphics/RadialGradient.java
deleted file mode 100644
index 4409a80..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/RadialGradient.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package android.graphics;
-
-public class RadialGradient extends GradientShader {
-
-    private RadialGradientPaint mPaint;
-
-    /**
-     * Create a shader that draws a radial gradient given the center and radius.
-     *
-     * @param x The x-coordinate of the center of the radius
-     * @param y The y-coordinate of the center of the radius
-     * @param radius Must be positive. The radius of the circle for this
-     *            gradient
-     * @param colors The colors to be distributed between the center and edge of
-     *            the circle
-     * @param positions May be NULL. The relative position of each corresponding
-     *            color in the colors array. If this is NULL, the the colors are
-     *            distributed evenly between the center and edge of the circle.
-     * @param tile The Shader tiling mode
-     */
-    public RadialGradient(float x, float y, float radius, int colors[], float positions[],
-            TileMode tile) {
-        super(colors, positions);
-        if (radius <= 0) {
-            throw new IllegalArgumentException("radius must be > 0");
-        }
-
-        mPaint = new RadialGradientPaint(x, y, radius, mColors, mPositions, tile);
-    }
-
-    /**
-     * Create a shader that draws a radial gradient given the center and radius.
-     *
-     * @param x The x-coordinate of the center of the radius
-     * @param y The y-coordinate of the center of the radius
-     * @param radius Must be positive. The radius of the circle for this
-     *            gradient
-     * @param color0 The color at the center of the circle.
-     * @param color1 The color at the edge of the circle.
-     * @param tile The Shader tiling mode
-     */
-    public RadialGradient(float x, float y, float radius, int color0, int color1, TileMode tile) {
-        this(x, y, radius, new int[] { color0, color1 }, null /* positions */, tile);
-    }
-
-    @Override
-    java.awt.Paint getJavaPaint() {
-        return mPaint;
-    }
-
-    private static class RadialGradientPaint extends GradientPaint {
-
-        private final float mX;
-        private final float mY;
-        private final float mRadius;
-
-        public RadialGradientPaint(float x, float y, float radius, int[] colors, float[] positions, TileMode mode) {
-            super(colors, positions, mode);
-            mX = x;
-            mY = y;
-            mRadius = radius;
-        }
-
-        public java.awt.PaintContext createContext(
-                java.awt.image.ColorModel     colorModel,
-                java.awt.Rectangle            deviceBounds,
-                java.awt.geom.Rectangle2D     userBounds,
-                java.awt.geom.AffineTransform xform,
-                java.awt.RenderingHints       hints) {
-            precomputeGradientColors();
-            return new RadialGradientPaintContext(colorModel);
-        }
-
-        private class RadialGradientPaintContext implements java.awt.PaintContext {
-
-            private final java.awt.image.ColorModel mColorModel;
-
-            public RadialGradientPaintContext(java.awt.image.ColorModel colorModel) {
-                mColorModel = colorModel;
-            }
-
-            public void dispose() {
-            }
-
-            public java.awt.image.ColorModel getColorModel() {
-                return mColorModel;
-            }
-
-            public java.awt.image.Raster getRaster(int x, int y, int w, int h) {
-                java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h,
-                        java.awt.image.BufferedImage.TYPE_INT_ARGB);
-
-                int[] data = new int[w*h];
-
-                // compute distance from each point to the center, and figure out the distance from
-                // it.
-                int index = 0;
-                for (int iy = 0 ; iy < h ; iy++) {
-                    for (int ix = 0 ; ix < w ; ix++) {
-                        float _x = x + ix - mX;
-                        float _y = y + iy - mY;
-                        float distance = (float) Math.sqrt(_x * _x + _y * _y);
-
-                        data[index++] = getGradientColor(distance / mRadius);
-                    }
-                }
-
-                image.setRGB(0 /*startX*/, 0 /*startY*/, w, h, data, 0 /*offset*/, w /*scansize*/);
-
-                return image.getRaster();
-            }
-
-        }
-    }
-
-}
diff --git a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
new file mode 100644
index 0000000..c4e764c
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+import android.graphics.Shader.TileMode;
+
+import java.awt.Paint;
+
+/**
+ * Delegate implementing the native methods of android.graphics.RadialGradient
+ *
+ * Through the layoutlib_create tool, the original native methods of RadialGradient have been
+ * replaced by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original RadialGradient class.
+ *
+ * Because this extends {@link Shader_Delegate}, there's no need to use a {@link DelegateManager},
+ * as all the Shader classes will be added to the manager owned by {@link Shader_Delegate}.
+ *
+ * @see Shader_Delegate
+ *
+ */
+public class RadialGradient_Delegate extends Gradient_Delegate {
+
+    // ---- delegate data ----
+    private java.awt.Paint mJavaPaint;
+
+    // ---- Public Helper methods ----
+
+    @Override
+    public Paint getJavaPaint() {
+        return mJavaPaint;
+    }
+
+    // ---- native methods ----
+
+    /*package*/ static int nativeCreate1(float x, float y, float radius,
+            int colors[], float positions[], int tileMode) {
+        // figure out the tile
+        TileMode tile = null;
+        for (TileMode tm : TileMode.values()) {
+            if (tm.nativeInt == tileMode) {
+                tile = tm;
+                break;
+            }
+        }
+
+        RadialGradient_Delegate newDelegate = new RadialGradient_Delegate(x, y, radius,
+                colors, positions, tile);
+        return sManager.addDelegate(newDelegate);
+    }
+
+    /*package*/ static int nativeCreate2(float x, float y, float radius,
+            int color0, int color1, int tileMode) {
+        return nativeCreate1(x, y, radius, new int[] { color0, color1 }, null /*positions*/,
+                tileMode);
+    }
+
+    /*package*/ static int nativePostCreate1(int native_shader, float x, float y, float radius,
+            int colors[], float positions[], int tileMode) {
+        // nothing to be done here.
+        return 0;
+    }
+
+    /*package*/ static int nativePostCreate2(int native_shader, float x, float y, float radius,
+            int color0, int color1, int tileMode) {
+        // nothing to be done here.
+        return 0;
+    }
+
+    // ---- Private delegate/helper methods ----
+
+    /**
+     * Create a shader that draws a radial gradient given the center and radius.
+     *
+     * @param x The x-coordinate of the center of the radius
+     * @param y The y-coordinate of the center of the radius
+     * @param radius Must be positive. The radius of the circle for this
+     *            gradient
+     * @param colors The colors to be distributed between the center and edge of
+     *            the circle
+     * @param positions May be NULL. The relative position of each corresponding
+     *            color in the colors array. If this is NULL, the the colors are
+     *            distributed evenly between the center and edge of the circle.
+     * @param tile The Shader tiling mode
+     */
+    private RadialGradient_Delegate(float x, float y, float radius, int colors[], float positions[],
+            TileMode tile) {
+        super(colors, positions);
+
+        mJavaPaint = new RadialGradientPaint(x, y, radius, mColors, mPositions, tile);
+    }
+
+    private static class RadialGradientPaint extends GradientPaint {
+
+        private final float mX;
+        private final float mY;
+        private final float mRadius;
+
+        public RadialGradientPaint(float x, float y, float radius, int[] colors, float[] positions,
+                TileMode mode) {
+            super(colors, positions, mode);
+            mX = x;
+            mY = y;
+            mRadius = radius;
+        }
+
+        public java.awt.PaintContext createContext(
+                java.awt.image.ColorModel     colorModel,
+                java.awt.Rectangle            deviceBounds,
+                java.awt.geom.Rectangle2D     userBounds,
+                java.awt.geom.AffineTransform xform,
+                java.awt.RenderingHints       hints) {
+            precomputeGradientColors();
+            return new RadialGradientPaintContext(colorModel);
+        }
+
+        private class RadialGradientPaintContext implements java.awt.PaintContext {
+
+            private final java.awt.image.ColorModel mColorModel;
+
+            public RadialGradientPaintContext(java.awt.image.ColorModel colorModel) {
+                mColorModel = colorModel;
+            }
+
+            public void dispose() {
+            }
+
+            public java.awt.image.ColorModel getColorModel() {
+                return mColorModel;
+            }
+
+            public java.awt.image.Raster getRaster(int x, int y, int w, int h) {
+                java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h,
+                        java.awt.image.BufferedImage.TYPE_INT_ARGB);
+
+                int[] data = new int[w*h];
+
+                // compute distance from each point to the center, and figure out the distance from
+                // it.
+                int index = 0;
+                for (int iy = 0 ; iy < h ; iy++) {
+                    for (int ix = 0 ; ix < w ; ix++) {
+                        float _x = x + ix - mX;
+                        float _y = y + iy - mY;
+                        float distance = (float) Math.sqrt(_x * _x + _y * _y);
+
+                        data[index++] = getGradientColor(distance / mRadius);
+                    }
+                }
+
+                image.setRGB(0 /*startX*/, 0 /*startY*/, w, h, data, 0 /*offset*/, w /*scansize*/);
+
+                return image.getRaster();
+            }
+
+        }
+    }
+
+}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Shader.java b/tools/layoutlib/bridge/src/android/graphics/Shader.java
deleted file mode 100644
index 0cc5940..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/Shader.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package android.graphics;
-
-
-
-/**
- * Shader is the based class for objects that return horizontal spans of colors
- * during drawing. A subclass of Shader is installed in a Paint calling
- * paint.setShader(shader). After that any object (other than a bitmap) that is
- * drawn with that paint will get its color(s) from the shader.
- */
-public abstract class Shader {
-
-    private final Matrix mMatrix = new Matrix();
-
-    public enum TileMode {
-        /**
-         * replicate the edge color if the shader draws outside of its
-         * original bounds
-         */
-        CLAMP   (0),
-        /**
-         * repeat the shader's image horizontally and vertically
-         */
-        REPEAT  (1),
-        /**
-         * repeat the shader's image horizontally and vertically, alternating
-         * mirror images so that adjacent images always seam
-         */
-        MIRROR  (2);
-
-        TileMode(int nativeInt) {
-            this.nativeInt = nativeInt;
-        }
-        final int nativeInt;
-    }
-
-    /**
-     * Return true if the shader has a non-identity local matrix.
-     * @param localM If not null, it is set to the shader's local matrix.
-     * @return true if the shader has a non-identity local matrix
-     */
-    public boolean getLocalMatrix(Matrix localM) {
-        if (localM != null) {
-            localM.set(mMatrix);
-        }
-
-        return !mMatrix.isIdentity();
-    }
-
-    /**
-     * Set the shader's local matrix. Passing null will reset the shader's
-     * matrix to identity
-     * @param localM The shader's new local matrix, or null to specify identity
-     */
-    public void setLocalMatrix(Matrix localM) {
-        if (localM != null) {
-            mMatrix.set(localM);
-        } else {
-            mMatrix.reset();
-        }
-    }
-
-    /**
-     * Returns a java.awt.Paint object matching this shader.
-     */
-    abstract java.awt.Paint getJavaPaint();
-}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
new file mode 100644
index 0000000..4dcf144
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package android.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+/**
+ * Delegate implementing the native methods of android.graphics.Shader
+ *
+ * Through the layoutlib_create tool, the original native methods of Shader have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original Shader class.
+ *
+ * This also serve as a base class for all Shader delegate classes.
+ *
+ * @see DelegateManager
+ *
+ */
+public abstract class Shader_Delegate {
+
+    // ---- delegate manager ----
+    protected static final DelegateManager<Shader_Delegate> sManager =
+            new DelegateManager<Shader_Delegate>();
+
+    // ---- delegate helper data ----
+
+    // ---- delegate data ----
+    private int mLocalMatrix = 0;
+
+    // ---- Public Helper methods ----
+
+    public static Shader_Delegate getDelegate(int nativeShader) {
+        return sManager.getDelegate(nativeShader);
+    }
+
+    public abstract java.awt.Paint getJavaPaint();
+
+    // ---- native methods ----
+
+    /*package*/ static void nativeDestructor(int native_shader, int native_skiaShader) {
+        sManager.removeDelegate(native_shader);
+    }
+
+    /*package*/ static boolean nativeGetLocalMatrix(int native_shader, int matrix_instance) {
+        // get the delegate from the native int.
+        Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
+        if (shaderDelegate == null) {
+            assert false;
+            return false;
+        }
+
+        Matrix_Delegate localMatrixDelegate = null;
+        if (shaderDelegate.mLocalMatrix > 0) {
+            localMatrixDelegate = Matrix_Delegate.getDelegate(shaderDelegate.mLocalMatrix);
+            if (localMatrixDelegate == null) {
+                assert false;
+                return false;
+            }
+        }
+
+        Matrix_Delegate destMatrixDelegate = null;
+        if (matrix_instance > 0) {
+            destMatrixDelegate = Matrix_Delegate.getDelegate(shaderDelegate.mLocalMatrix);
+            if (destMatrixDelegate == null) {
+                assert false;
+                return false;
+            }
+
+            if (localMatrixDelegate != null) {
+                destMatrixDelegate.set(localMatrixDelegate);
+            } else {
+                // since there's no local matrix, it's considered to be the identity, reset
+                // the destination matrix
+                destMatrixDelegate.reset();
+            }
+        }
+
+        return localMatrixDelegate == null || localMatrixDelegate.isIdentity();
+    }
+
+    /*package*/ static void nativeSetLocalMatrix(int native_shader, int native_skiaShader,
+            int matrix_instance) {
+        // get the delegate from the native int.
+        Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
+        if (shaderDelegate == null) {
+            assert false;
+            return;
+        }
+
+        shaderDelegate.mLocalMatrix = matrix_instance;
+    }
+
+    // ---- Private delegate/helper methods ----
+
+}
diff --git a/tools/layoutlib/bridge/src/android/graphics/SweepGradient.java b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
similarity index 67%
rename from tools/layoutlib/bridge/src/android/graphics/SweepGradient.java
rename to tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
index 87036ed..0492e4f 100644
--- a/tools/layoutlib/bridge/src/android/graphics/SweepGradient.java
+++ b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2010 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.
@@ -16,9 +16,62 @@
 
 package android.graphics;
 
-public class SweepGradient extends GradientShader {
+import com.android.layoutlib.bridge.DelegateManager;
 
-    private SweepGradientPaint mPaint;
+import java.awt.Paint;
+
+/**
+ * Delegate implementing the native methods of android.graphics.SweepGradient
+ *
+ * Through the layoutlib_create tool, the original native methods of SweepGradient have been
+ * replaced by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original SweepGradient class.
+ *
+ * Because this extends {@link Shader_Delegate}, there's no need to use a {@link DelegateManager},
+ * as all the Shader classes will be added to the manager owned by {@link Shader_Delegate}.
+ *
+ * @see Shader_Delegate
+ *
+ */
+public class SweepGradient_Delegate extends Gradient_Delegate {
+
+    // ---- delegate data ----
+    private java.awt.Paint mJavaPaint;
+
+    // ---- Public Helper methods ----
+
+    @Override
+    public Paint getJavaPaint() {
+        return mJavaPaint;
+    }
+
+    // ---- native methods ----
+
+    /*package*/ static int nativeCreate1(float x, float y, int colors[], float positions[]) {
+        SweepGradient_Delegate newDelegate = new SweepGradient_Delegate(x, y, colors, positions);
+        return sManager.addDelegate(newDelegate);
+    }
+
+    /*package*/ static int nativeCreate2(float x, float y, int color0, int color1) {
+        return nativeCreate1(x, y, new int[] { color0, color1 }, null /*positions*/);
+    }
+
+    /*package*/ static int nativePostCreate1(int native_shader, float cx, float cy,
+            int[] colors, float[] positions) {
+        // nothing to be done here.
+        return 0;
+    }
+
+    /*package*/ static int nativePostCreate2(int native_shader, float cx, float cy,
+            int color0, int color1) {
+        // nothing to be done here.
+        return 0;
+    }
+
+    // ---- Private delegate/helper methods ----
 
     /**
      * A subclass of Shader that draws a sweep gradient around a center point.
@@ -34,28 +87,11 @@
      *                 If positions is NULL, then the colors are automatically
      *                 spaced evenly.
      */
-    public SweepGradient(float cx, float cy,
+    private SweepGradient_Delegate(float cx, float cy,
                          int colors[], float positions[]) {
         super(colors, positions);
 
-        mPaint = new SweepGradientPaint(cx, cy, mColors, mPositions);
-    }
-
-    /**
-     * A subclass of Shader that draws a sweep gradient around a center point.
-     *
-     * @param cx       The x-coordinate of the center
-     * @param cy       The y-coordinate of the center
-     * @param color0   The color to use at the start of the sweep
-     * @param color1   The color to use at the end of the sweep
-     */
-    public SweepGradient(float cx, float cy, int color0, int color1) {
-        this(cx, cy, new int[] { color0, color1}, null /*positions*/);
-    }
-
-    @Override
-    java.awt.Paint getJavaPaint() {
-        return mPaint;
+        mJavaPaint = new SweepGradientPaint(cx, cy, mColors, mPositions);
     }
 
     private static class SweepGradientPaint extends GradientPaint {
@@ -135,6 +171,4 @@
 
         }
     }
-
 }
-
diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
index 248bdab..7e90e7d 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
@@ -72,7 +72,11 @@
     }
 
     public static List<Font> getFonts(Typeface typeface) {
-        Typeface_Delegate delegate = sManager.getDelegate(typeface.native_instance);
+        return getFonts(typeface.native_instance);
+    }
+
+    public static List<Font> getFonts(int native_int) {
+        Typeface_Delegate delegate = sManager.getDelegate(native_int);
         if (delegate == null) {
             assert false;
             return null;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 9eb83c8..cdb4148 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -24,6 +24,7 @@
 import com.android.layoutlib.api.IResourceValue;
 import com.android.layoutlib.api.IStyleResourceValue;
 import com.android.layoutlib.api.IXmlPullParser;
+import com.android.layoutlib.api.IDensityBasedResourceValue.Density;
 import com.android.layoutlib.api.ILayoutResult.ILayoutViewInfo;
 import com.android.layoutlib.bridge.LayoutResult.LayoutViewInfo;
 import com.android.ninepatch.NinePatch;
@@ -33,7 +34,9 @@
 import android.content.ClipData;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
+import android.graphics.Bitmap_Delegate;
 import android.graphics.Canvas;
+import android.graphics.Canvas_Delegate;
 import android.graphics.Rect;
 import android.graphics.Region;
 import android.graphics.Typeface_Delegate;
@@ -64,6 +67,7 @@
 import android.widget.TabHost;
 import android.widget.TabWidget;
 
+import java.awt.image.BufferedImage;
 import java.lang.ref.SoftReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -450,13 +454,28 @@
             view.layout(0, screenOffset, screenWidth, screenHeight);
 
             // draw the views
-            Canvas canvas = new Canvas(screenWidth, screenHeight - screenOffset, logger);
+            // create the BufferedImage into which the layout will be rendered.
+            BufferedImage image = new BufferedImage(screenWidth, screenHeight - screenOffset,
+                    BufferedImage.TYPE_INT_ARGB);
+
+            // create an Android bitmap around the BufferedImage
+            Bitmap bitmap = Bitmap_Delegate.createBitmap(image, Density.getEnum(density));
+
+            // create a Canvas around the Android bitmap
+            Canvas canvas = new Canvas(bitmap);
+
+            // to set the logger, get the native delegate
+            Canvas_Delegate canvasDelegate = Canvas_Delegate.getDelegate(canvas);
+            canvasDelegate.setLogger(logger);
+
 
             root.draw(canvas);
-            canvas.dispose();
+            canvasDelegate.dispose();
 
-            return new LayoutResult(visit(((ViewGroup)view).getChildAt(0), context),
-                    canvas.getImage());
+            return new LayoutResult(
+                    visit(((ViewGroup)view).getChildAt(0), context),
+                    image);
+
         } catch (PostInflateException e) {
             return new LayoutResult(ILayoutResult.ERROR, "Error during post inflation process:\n"
                     + e.getMessage());
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/NinePatchDrawable.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/NinePatchDrawable.java
index abbf2f0..2c92567 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/NinePatchDrawable.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/NinePatchDrawable.java
@@ -19,6 +19,7 @@
 import com.android.ninepatch.NinePatch;
 
 import android.graphics.Canvas;
+import android.graphics.Canvas_Delegate;
 import android.graphics.ColorFilter;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
@@ -80,7 +81,8 @@
     @Override
     public void draw(Canvas canvas) {
         Rect r = getBounds();
-        m9Patch.draw(canvas.getGraphics2d(), r.left, r.top, r.width(), r.height());
+        Canvas_Delegate canvasDelegate = Canvas_Delegate.getDelegate(canvas);
+        m9Patch.draw(canvasDelegate.getGraphics2d(), r.left, r.top, r.width(), r.height());
 
         return;
     }
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java
index 6e14e82..ba3c51a 100644
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java
@@ -17,8 +17,6 @@
 package com.android.layoutlib.bridge;
 
 import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics._Original_Paint;
 import android.text.TextPaint;
 
 import junit.framework.TestCase;
@@ -58,14 +56,6 @@
         }
     }
 
-    public void testPaint() {
-        _Original_Paint o = new _Original_Paint();
-        assertNotNull(o);
-
-        Paint p = new Paint();
-        assertNotNull(p);
-    }
-
     public void textTextPaint() {
         TextPaint p = new TextPaint();
         assertNotNull(p);
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java
index 7c1eecd..a86b5c9 100644
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java
@@ -87,7 +87,11 @@
 
             try {
                 // try to load the method with the given parameter types.
-                delegateClass.getDeclaredMethod(originalMethod.getName(), parameters);
+                Method delegateMethod = delegateClass.getDeclaredMethod(originalMethod.getName(),
+                        parameters);
+
+                // check that the method is static
+                assertTrue((delegateMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC);
             } catch (NoSuchMethodException e) {
                 // compute a full class name that's long but not too long.
                 StringBuilder sb = new StringBuilder(originalMethod.getName() + "(");
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
index 0ecb474..2a6ef4d 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
@@ -104,7 +104,13 @@
      */
     private final static String[] DELEGATE_CLASS_NATIVES = new String[] {
         "android.graphics.Bitmap",
+        "android.graphics.Canvas",
+        "android.graphics.LinearGradient",
         "android.graphics.Matrix",
+        "android.graphics.Paint",
+        "android.graphics.RadialGradient",
+        "android.graphics.Shader",
+        "android.graphics.SweepGradient",
         "android.graphics.Typeface",
     };
 
@@ -125,17 +131,9 @@
     private final static String[] RENAMED_CLASSES =
         new String[] {
             "android.graphics.BitmapFactory",       "android.graphics._Original_BitmapFactory",
-            "android.graphics.BitmapShader",        "android.graphics._Original_BitmapShader",
-            "android.graphics.Canvas",              "android.graphics._Original_Canvas",
-            "android.graphics.ComposeShader",       "android.graphics._Original_ComposeShader",
             "android.graphics.DashPathEffect",       "android.graphics._Original_DashPathEffect",
-            "android.graphics.LinearGradient",      "android.graphics._Original_LinearGradient",
-            "android.graphics.Paint",               "android.graphics._Original_Paint",
             "android.graphics.Path",                "android.graphics._Original_Path",
             "android.graphics.PorterDuffXfermode",  "android.graphics._Original_PorterDuffXfermode",
-            "android.graphics.RadialGradient",      "android.graphics._Original_RadialGradient",
-            "android.graphics.Shader",              "android.graphics._Original_Shader",
-            "android.graphics.SweepGradient",       "android.graphics._Original_SweepGradient",
             "android.os.ServiceManager",            "android.os._Original_ServiceManager",
             "android.util.FloatMath",               "android.util._Original_FloatMath",
             "android.view.SurfaceView",             "android.view._Original_SurfaceView",
@@ -150,13 +148,6 @@
      */
     private final static String[] DELETE_RETURNS =
         new String[] {
-            "android.graphics.Paint",       // class to delete methods from
-            "android.graphics.Paint$Align", // list of type identifying methods to delete
-            "android.graphics.Paint$Style",
-            "android.graphics.Paint$Join",
-            "android.graphics.Paint$Cap",
-            "android.graphics.Paint$FontMetrics",
-            "android.graphics.Paint$FontMetricsInt",
             null };                         // separator, for next class/methods list.
 }
 
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java
index 21d6682..c7968a4 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java
@@ -169,7 +169,7 @@
         // Construct the descriptor of the delegate. For a static method, it's the same
         // however for an instance method we need to pass the 'this' reference first
         String desc = mDesc;
-        if (!mIsStatic && argTypes.length > 0) {
+        if (!mIsStatic) {
             Type[] argTypes2 = new Type[argTypes.length + 1];
 
             argTypes2[0] = Type.getObjectType(mClassName);
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index 720f6ac..4bd5286 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -58,11 +58,7 @@
 
     int getWifiEnabledState();
 
-    int getNumAllowedChannels();
-
-    boolean setNumAllowedChannels(int numChannels, boolean persist);
-
-    int[] getValidChannelCounts();
+    void setCountryCode(String country, boolean persist);
 
     boolean saveConfiguration();
 
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 356a0bd..c85a988 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -672,57 +672,19 @@
     }
 
     /**
-     * Return the number of frequency channels that are allowed
-     * to be used in the current regulatory domain.
-     * @return the number of allowed channels, or {@code -1} if an error occurs
+     * Set the country code.
+     * @param countryCode country code in ISO 3166 format.
+     * @param persist {@code true} if this needs to be remembered
      *
-     * @hide pending API council
+     * @hide
      */
-    public int getNumAllowedChannels() {
+    public void setCountryCode(String country, boolean persist) {
         try {
-            return mService.getNumAllowedChannels();
-        } catch (RemoteException e) {
-            return -1;
-        }
+            mService.setCountryCode(country, persist);
+        } catch (RemoteException e) { }
     }
 
     /**
-     * Set the number of frequency channels that are allowed to be used
-     * in the current regulatory domain. This method should be used only
-     * if the correct number of channels cannot be determined automatically
-     * for some reason.
-     * @param numChannels the number of allowed channels. Must be greater than 0
-     * and less than or equal to 16.
-     * @param persist {@code true} if you want this remembered
-     * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g.,
-     * {@code numChannels} is out of range.
-     *
-     * @hide pending API council
-     */
-    public boolean setNumAllowedChannels(int numChannels, boolean persist) {
-        try {
-            return mService.setNumAllowedChannels(numChannels, persist);
-        } catch (RemoteException e) {
-            return false;
-        }
-    }
-
-    /**
-     * Return the list of valid values for the number of allowed radio channels
-     * for various regulatory domains.
-     * @return the list of channel counts, or {@code null} if the operation fails
-     *
-     * @hide pending API council review
-     */
-    public int[] getValidChannelCounts() {
-        try {
-            return mService.getValidChannelCounts();
-        } catch (RemoteException e) {
-            return null;
-        }
-   }
-
-    /**
      * Return the DHCP-assigned addresses from the last successful DHCP request,
      * if any.
      * @return the DHCP information
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 3d8157c..06f945b 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -117,10 +117,6 @@
 
     public native static int getPowerModeCommand();
 
-    public native static boolean setNumAllowedChannelsCommand(int numChannels);
-
-    public native static int getNumAllowedChannelsCommand();
-
     /**
      * Sets the bluetooth coexistence mode.
      * 
@@ -163,6 +159,8 @@
 
     public native static boolean setSuspendOptimizationsCommand(boolean enabled);
 
+    public native static boolean setCountryCodeCommand(String countryCode);
+
     /**
      * Wait for the supplicant to send an event, returning the event string.
      * @return the event string sent by the supplicant.
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 6bd67cc..fdb50e2 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -111,7 +111,6 @@
 
     private String mInterfaceName;
 
-    private int mNumAllowedChannels = 0;
     private int mLastSignalLevel = -1;
     private String mLastBssid;
     private int mLastNetworkId;
@@ -271,26 +270,18 @@
      * false(0)
      */
     private static final int CMD_SET_BLUETOOTH_SCAN_MODE          = 79;
-    /* Set number of allowed channels */
-    private static final int CMD_SET_NUM_ALLOWED_CHANNELS         = 80;
+    /* Set the country code */
+    private static final int CMD_SET_COUNTRY_CODE                 = 80;
     /* Request connectivity manager wake lock before driver stop */
     private static final int CMD_REQUEST_CM_WAKELOCK              = 81;
     /* Enables RSSI poll */
     private static final int CMD_ENABLE_RSSI_POLL                 = 82;
     /* RSSI poll */
     private static final int CMD_RSSI_POLL                        = 83;
-    /* Get current RSSI */
-    private static final int CMD_GET_RSSI                         = 84;
-    /* Get approx current RSSI */
-    private static final int CMD_GET_RSSI_APPROX                  = 85;
-    /* Get link speed on connection */
-    private static final int CMD_GET_LINK_SPEED                   = 86;
-    /* Radio mac address */
-    private static final int CMD_GET_MAC_ADDR                     = 87;
     /* Set up packet filtering */
-    private static final int CMD_START_PACKET_FILTERING           = 88;
+    private static final int CMD_START_PACKET_FILTERING           = 84;
     /* Clear packet filter */
-    private static final int CMD_STOP_PACKET_FILTERING            = 89;
+    private static final int CMD_STOP_PACKET_FILTERING            = 85;
     /* Connect to a specified network (network id
      * or WifiConfiguration) This involves increasing
      * the priority of the network, enabling the network
@@ -299,21 +290,24 @@
      * an existing network. All the networks get enabled
      * upon a successful connection or a failure.
      */
-    private static final int CMD_CONNECT_NETWORK                  = 90;
+    private static final int CMD_CONNECT_NETWORK                  = 86;
     /* Save the specified network. This involves adding
      * an enabled network (if new) and updating the
      * config and issuing a save on supplicant config.
      */
-    private static final int CMD_SAVE_NETWORK                     = 91;
+    private static final int CMD_SAVE_NETWORK                     = 87;
     /* Delete the specified network. This involves
      * removing the network and issuing a save on
      * supplicant config.
      */
-    private static final int CMD_FORGET_NETWORK                   = 92;
+    private static final int CMD_FORGET_NETWORK                   = 88;
     /* Start Wi-Fi protected setup push button configuration */
-    private static final int CMD_START_WPS_PBC                    = 93;
-    /* Start Wi-Fi protected setup pin method configuration */
-    private static final int CMD_START_WPS_PIN                    = 94;
+    private static final int CMD_START_WPS_PBC                    = 89;
+    /* Start Wi-Fi protected setup pin method configuration with pin obtained from AP */
+    private static final int CMD_START_WPS_PIN_FROM_AP            = 90;
+    /* Start Wi-Fi protected setup pin method configuration with pin obtained from device */
+    private static final int CMD_START_WPS_PIN_FROM_DEVICE        = 91;
+
     /**
      * Interval in milliseconds between polling for connection
      * status items that are not sent via asynchronous events.
@@ -334,6 +328,9 @@
     /* 2.4GHz allows 802.11B/G operation */
     private static final int BAND_2G = 2;
 
+    private static final int SUCCESS = 1;
+    private static final int FAILURE = -1;
+
     /**
      * The maximum number of times we will retry a connection to an access point
      * for which we have failed in acquiring an IP address from DHCP. A value of
@@ -519,8 +516,11 @@
     /**
      * TODO: doc
      */
-    public boolean syncPingSupplicant() {
-        return sendSyncMessage(CMD_PING_SUPPLICANT).boolValue;
+    public boolean syncPingSupplicant(AsyncChannel channel) {
+        Message resultMsg = channel.sendMessageSynchronously(CMD_PING_SUPPLICANT);
+        boolean result = (resultMsg.arg1 != FAILURE);
+        resultMsg.recycle();
+        return result;
     }
 
     /**
@@ -698,8 +698,11 @@
      *
      * @return network id of the new network
      */
-    public int syncAddOrUpdateNetwork(WifiConfiguration config) {
-        return sendSyncMessage(CMD_ADD_OR_UPDATE_NETWORK, config).intValue;
+    public int syncAddOrUpdateNetwork(AsyncChannel channel, WifiConfiguration config) {
+        Message resultMsg = channel.sendMessageSynchronously(CMD_ADD_OR_UPDATE_NETWORK, config);
+        int result = resultMsg.arg1;
+        resultMsg.recycle();
+        return result;
     }
 
     public List<WifiConfiguration> syncGetConfiguredNetworks() {
@@ -713,39 +716,24 @@
      */
     public boolean syncRemoveNetwork(AsyncChannel channel, int networkId) {
         Message resultMsg = channel.sendMessageSynchronously(CMD_REMOVE_NETWORK, networkId);
-        boolean result = resultMsg.arg1 != 0;
+        boolean result = (resultMsg.arg1 != FAILURE);
         resultMsg.recycle();
         return result;
     }
 
     /**
-     * Return the result of a removeNetwork
-     *
-     * @param srcMsg is the original message
-     * @param result is true if successfully removed
-     */
-    private void removeNetworkReply(Message srcMsg, boolean result) {
-        mReplyChannel.replyToMessage(srcMsg, CMD_REMOVE_NETWORK, result ? 1 : 0);
-    }
-
-    private class EnableNetParams {
-        private int netId;
-        private boolean disableOthers;
-        EnableNetParams(int n, boolean b) {
-            netId = n;
-            disableOthers = b;
-        }
-    }
-    /**
      * Enable a network
      *
      * @param netId network id of the network
      * @param disableOthers true, if all other networks have to be disabled
      * @return {@code true} if the operation succeeds, {@code false} otherwise
      */
-    public boolean syncEnableNetwork(int netId, boolean disableOthers) {
-        return sendSyncMessage(CMD_ENABLE_NETWORK,
-                new EnableNetParams(netId, disableOthers)).boolValue;
+    public boolean syncEnableNetwork(AsyncChannel channel, int netId, boolean disableOthers) {
+        Message resultMsg = channel.sendMessageSynchronously(CMD_ENABLE_NETWORK, netId,
+                disableOthers ? 1 : 0);
+        boolean result = (resultMsg.arg1 != FAILURE);
+        resultMsg.recycle();
+        return result;
     }
 
     /**
@@ -754,8 +742,11 @@
      * @param netId network id of the network
      * @return {@code true} if the operation succeeds, {@code false} otherwise
      */
-    public boolean syncDisableNetwork(int netId) {
-        return sendSyncMessage(obtainMessage(CMD_DISABLE_NETWORK, netId, 0)).boolValue;
+    public boolean syncDisableNetwork(AsyncChannel channel, int netId) {
+        Message resultMsg = channel.sendMessageSynchronously(CMD_DISABLE_NETWORK, netId);
+        boolean result = (resultMsg.arg1 != FAILURE);
+        resultMsg.recycle();
+        return result;
     }
 
     /**
@@ -801,11 +792,11 @@
     }
 
     public void startWpsWithPinFromAccessPoint(String bssid, int apPin) {
-        sendMessage(obtainMessage(CMD_START_WPS_PIN, apPin, 0, bssid));
+        sendMessage(obtainMessage(CMD_START_WPS_PIN_FROM_AP, apPin, 0, bssid));
     }
 
     public int syncStartWpsWithPinFromDevice(AsyncChannel channel, String bssid) {
-        Message resultMsg = channel.sendMessageSynchronously(CMD_START_WPS_PIN, bssid);
+        Message resultMsg = channel.sendMessageSynchronously(CMD_START_WPS_PIN_FROM_DEVICE, bssid);
         int result = resultMsg.arg1;
         resultMsg.recycle();
         return result;
@@ -814,41 +805,6 @@
     public void enableRssiPolling(boolean enabled) {
        sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
     }
-    /**
-     * Get RSSI to currently connected network
-     *
-     * @return RSSI value, -1 on failure
-     */
-    public int syncGetRssi() {
-        return sendSyncMessage(CMD_GET_RSSI).intValue;
-    }
-
-    /**
-     * Get approx RSSI to currently connected network
-     *
-     * @return RSSI value, -1 on failure
-     */
-    public int syncGetRssiApprox() {
-        return sendSyncMessage(CMD_GET_RSSI_APPROX).intValue;
-    }
-
-    /**
-     * Get link speed to currently connected network
-     *
-     * @return link speed, -1 on failure
-     */
-    public int syncGetLinkSpeed() {
-        return sendSyncMessage(CMD_GET_LINK_SPEED).intValue;
-    }
-
-    /**
-     * Get MAC address of radio
-     *
-     * @return MAC address, null on failure
-     */
-    public String syncGetMacAddress() {
-        return sendSyncMessage(CMD_GET_MAC_ADDR).stringValue;
-    }
 
     /**
      * Start packet filtering
@@ -875,42 +831,17 @@
     }
 
     /**
-     * Set the number of allowed radio frequency channels from the system
-     * setting value, if any.
+     * Set the country code
+     * @param countryCode following ISO 3166 format
+     * @param persist {@code true} if the setting should be remembered.
      */
-    public void setNumAllowedChannels() {
-        try {
-            setNumAllowedChannels(
-                    Settings.Secure.getInt(mContext.getContentResolver(),
-                    Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS));
-        } catch (Settings.SettingNotFoundException e) {
-            if (mNumAllowedChannels != 0) {
-                setNumAllowedChannels(mNumAllowedChannels);
-            }
-            // otherwise, use the driver default
+    public void setCountryCode(String countryCode, boolean persist) {
+        if (persist) {
+            Settings.Secure.putString(mContext.getContentResolver(),
+                    Settings.Secure.WIFI_COUNTRY_CODE,
+                    countryCode);
         }
-    }
-
-    /**
-     * Set the number of radio frequency channels that are allowed to be used
-     * in the current regulatory domain.
-     * @param numChannels the number of allowed channels. Must be greater than 0
-     * and less than or equal to 16.
-     */
-    public void setNumAllowedChannels(int numChannels) {
-        sendMessage(obtainMessage(CMD_SET_NUM_ALLOWED_CHANNELS, numChannels, 0));
-    }
-
-    /**
-     * Get number of allowed channels
-     *
-     * @return channel count, -1 on failure
-     *
-     * TODO: this is not a public API and needs to be removed in favor
-     * of asynchronous reporting. unused for now.
-     */
-    public int getNumAllowedChannels() {
-        return -1;
+        sendMessage(obtainMessage(CMD_SET_COUNTRY_CODE, countryCode));
     }
 
     /**
@@ -943,8 +874,11 @@
      *
      * TODO: deprecate this
      */
-    public boolean syncSaveConfig() {
-        return sendSyncMessage(CMD_SAVE_CONFIG).boolValue;
+    public boolean syncSaveConfig(AsyncChannel channel) {
+        Message resultMsg = channel.sendMessageSynchronously(CMD_SAVE_CONFIG);
+        boolean result = (resultMsg.arg1 != FAILURE);
+        resultMsg.recycle();
+        return result;
     }
 
     /**
@@ -998,7 +932,6 @@
         sb.append("mWifiInfo ").append(mWifiInfo).append(LS);
         sb.append("mDhcpInfo ").append(mDhcpInfo).append(LS);
         sb.append("mNetworkInfo ").append(mNetworkInfo).append(LS);
-        sb.append("mNumAllowedChannels ").append(mNumAllowedChannels).append(LS);
         sb.append("mLastSignalLevel ").append(mLastSignalLevel).append(LS);
         sb.append("mLastBssid ").append(mLastBssid).append(LS);
         sb.append("mLastNetworkId ").append(mLastNetworkId).append(LS);
@@ -1018,70 +951,16 @@
      * Internal private functions
      ********************************************************/
 
-    class SyncReturn {
-        boolean boolValue;
-        int intValue;
-        String stringValue;
-        Object objValue;
-    }
-
-    class SyncParams {
-        Object mParameter;
-        SyncReturn mSyncReturn;
-        SyncParams() {
-            mSyncReturn = new SyncReturn();
-        }
-        SyncParams(Object p) {
-            mParameter = p;
-            mSyncReturn = new SyncReturn();
-        }
-    }
-
     /**
-     * message.obj is used to store SyncParams
+     * Set the country code from the system setting value, if any.
      */
-    private SyncReturn syncedSend(Message msg) {
-        SyncParams syncParams = (SyncParams) msg.obj;
-        synchronized(syncParams) {
-            if (DBG) Log.d(TAG, "syncedSend " + msg);
-            sendMessage(msg);
-            try {
-                syncParams.wait();
-            } catch (InterruptedException e) {
-                Log.e(TAG, "sendSyncMessage: unexpected interruption of wait()");
-                return null;
-            }
-        }
-        return syncParams.mSyncReturn;
-    }
-
-    private SyncReturn sendSyncMessage(Message msg) {
-        SyncParams syncParams = new SyncParams();
-        msg.obj = syncParams;
-        return syncedSend(msg);
-    }
-
-    private SyncReturn sendSyncMessage(int what, Object param) {
-        SyncParams syncParams = new SyncParams(param);
-        Message msg = obtainMessage(what, syncParams);
-        return syncedSend(msg);
-    }
-
-
-    private SyncReturn sendSyncMessage(int what) {
-        return sendSyncMessage(obtainMessage(what));
-    }
-
-    private void notifyOnMsgObject(Message msg) {
-        SyncParams syncParams = (SyncParams) msg.obj;
-        if (syncParams != null) {
-            synchronized(syncParams) {
-                if (DBG) Log.d(TAG, "notifyOnMsgObject " + msg);
-                syncParams.notify();
-            }
-        }
-        else {
-            Log.e(TAG, "Error! syncParams in notifyOnMsgObject is null");
+    private void setCountryCode() {
+        String countryCode = Settings.Secure.getString(mContext.getContentResolver(),
+                Settings.Secure.WIFI_COUNTRY_CODE);
+        if (countryCode != null && !countryCode.isEmpty()) {
+            setCountryCode(countryCode, false);
+        } else {
+            //use driver default
         }
     }
 
@@ -1620,7 +1499,6 @@
         @Override
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
-            SyncParams syncParams;
             switch (message.what) {
                 case CMD_SET_BLUETOOTH_HEADSET_PROXY:
                     mBluetoothHeadset = (BluetoothHeadset) message.obj;
@@ -1633,19 +1511,10 @@
                 case CMD_ENABLE_NETWORK:
                 case CMD_DISABLE_NETWORK:
                 case CMD_ADD_OR_UPDATE_NETWORK:
-                case CMD_GET_RSSI:
-                case CMD_GET_RSSI_APPROX:
-                case CMD_GET_LINK_SPEED:
-                case CMD_GET_MAC_ADDR:
-                case CMD_SAVE_CONFIG:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.boolValue = false;
-                    syncParams.mSyncReturn.intValue = -1;
-                    syncParams.mSyncReturn.stringValue = null;
-                    notifyOnMsgObject(message);
-                    break;
                 case CMD_REMOVE_NETWORK:
-                    removeNetworkReply(message, false);
+                case CMD_SAVE_CONFIG:
+                case CMD_START_WPS_PIN_FROM_DEVICE:
+                    mReplyChannel.replyToMessage(message, message.what, FAILURE);
                     break;
                 case CMD_ENABLE_RSSI_POLL:
                     mEnableRssiPolling = (message.arg1 == 1);
@@ -1681,13 +1550,13 @@
                 case CMD_SET_HIGH_PERF_MODE:
                 case CMD_SET_BLUETOOTH_COEXISTENCE:
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
+                case CMD_SET_COUNTRY_CODE:
                 case CMD_REQUEST_CM_WAKELOCK:
                 case CMD_CONNECT_NETWORK:
                 case CMD_SAVE_NETWORK:
                 case CMD_FORGET_NETWORK:
                 case CMD_START_WPS_PBC:
-                case CMD_START_WPS_PIN:
+                case CMD_START_WPS_PIN_FROM_AP:
                     break;
                 default:
                     Log.e(TAG, "Error! unhandled message" + message);
@@ -1783,7 +1652,7 @@
                 case CMD_SET_HIGH_PERF_MODE:
                 case CMD_SET_BLUETOOTH_COEXISTENCE:
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
+                case CMD_SET_COUNTRY_CODE:
                 case CMD_START_PACKET_FILTERING:
                 case CMD_STOP_PACKET_FILTERING:
                     deferMessage(message);
@@ -1911,7 +1780,7 @@
                 case CMD_SET_HIGH_PERF_MODE:
                 case CMD_SET_BLUETOOTH_COEXISTENCE:
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
+                case CMD_SET_COUNTRY_CODE:
                 case CMD_START_PACKET_FILTERING:
                 case CMD_STOP_PACKET_FILTERING:
                     deferMessage(message);
@@ -2008,7 +1877,7 @@
                 case CMD_SET_HIGH_PERF_MODE:
                 case CMD_SET_BLUETOOTH_COEXISTENCE:
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
+                case CMD_SET_COUNTRY_CODE:
                 case CMD_START_PACKET_FILTERING:
                 case CMD_STOP_PACKET_FILTERING:
                     deferMessage(message);
@@ -2032,7 +1901,6 @@
         @Override
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
-            SyncParams syncParams;
             WifiConfiguration config;
             switch(message.what) {
                 case CMD_STOP_SUPPLICANT:   /* Supplicant stopped by user */
@@ -2060,36 +1928,29 @@
                     sendScanResultsAvailableBroadcast();
                     break;
                 case CMD_PING_SUPPLICANT:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.boolValue = WifiNative.pingCommand();
-                    notifyOnMsgObject(message);
+                    boolean ok = WifiNative.pingCommand();
+                    mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
                     break;
                 case CMD_ADD_OR_UPDATE_NETWORK:
                     EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
-                    syncParams = (SyncParams) message.obj;
-                    config = (WifiConfiguration) syncParams.mParameter;
-                    syncParams.mSyncReturn.intValue = WifiConfigStore.addOrUpdateNetwork(config);
-                    notifyOnMsgObject(message);
+                    config = (WifiConfiguration) message.obj;
+                    mReplyChannel.replyToMessage(message, CMD_ADD_OR_UPDATE_NETWORK,
+                            WifiConfigStore.addOrUpdateNetwork(config));
                     break;
                 case CMD_REMOVE_NETWORK:
                     EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
-                    boolean ok = WifiConfigStore.removeNetwork(message.arg1);
-                    removeNetworkReply(message, ok);
+                    ok = WifiConfigStore.removeNetwork(message.arg1);
+                    mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
                     break;
                 case CMD_ENABLE_NETWORK:
                     EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
-                    syncParams = (SyncParams) message.obj;
-                    EnableNetParams enableNetParams = (EnableNetParams) syncParams.mParameter;
-                    syncParams.mSyncReturn.boolValue = WifiConfigStore.enableNetwork(
-                            enableNetParams.netId, enableNetParams.disableOthers);
-                    notifyOnMsgObject(message);
+                    ok = WifiConfigStore.enableNetwork(message.arg1, message.arg2 == 1);
+                    mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
                     break;
                 case CMD_DISABLE_NETWORK:
                     EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.boolValue = WifiConfigStore.disableNetwork(
-                            message.arg1);
-                    notifyOnMsgObject(message);
+                    ok = WifiConfigStore.disableNetwork(message.arg1);
+                    mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
                     break;
                 case CMD_BLACKLIST_NETWORK:
                     EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
@@ -2099,9 +1960,9 @@
                     WifiNative.clearBlacklistCommand();
                     break;
                 case CMD_SAVE_CONFIG:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.boolValue = WifiConfigStore.saveConfig();
-                    notifyOnMsgObject(message);
+                    ok = WifiConfigStore.saveConfig();
+                    mReplyChannel.replyToMessage(message, CMD_SAVE_CONFIG, ok ? SUCCESS : FAILURE);
+
                     // Inform the backup manager about a data change
                     IBackupManager ibm = IBackupManager.Stub.asInterface(
                             ServiceManager.getService(Context.BACKUP_SERVICE));
@@ -2113,11 +1974,6 @@
                         }
                     }
                     break;
-                case CMD_GET_MAC_ADDR:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.stringValue = WifiNative.getMacAddressCommand();
-                    notifyOnMsgObject(message);
-                    break;
                     /* Cannot start soft AP while in client mode */
                 case CMD_START_AP:
                     Log.d(TAG, "Failed to start soft AP with a running supplicant");
@@ -2165,7 +2021,7 @@
                 case CMD_SET_HIGH_PERF_MODE:
                 case CMD_SET_BLUETOOTH_COEXISTENCE:
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
+                case CMD_SET_COUNTRY_CODE:
                 case CMD_START_PACKET_FILTERING:
                 case CMD_STOP_PACKET_FILTERING:
                 case CMD_START_SCAN:
@@ -2191,8 +2047,8 @@
             mIsRunning = true;
             updateBatteryWorkSource(null);
 
-            /* Initialize channel count */
-            setNumAllowedChannels();
+            /* set country code */
+            setCountryCode();
 
             if (mIsScanMode) {
                 WifiNative.setScanResultHandlingCommand(SCAN_ONLY_MODE);
@@ -2207,7 +2063,6 @@
         @Override
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
-            SyncParams syncParams;
             switch(message.what) {
                 case CMD_SET_SCAN_TYPE:
                     if (message.arg1 == SCAN_ACTIVE) {
@@ -2225,9 +2080,12 @@
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
                     WifiNative.setBluetoothCoexistenceScanModeCommand(message.arg1 == 1);
                     break;
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
-                    mNumAllowedChannels = message.arg1;
-                    WifiNative.setNumAllowedChannelsCommand(message.arg1);
+                case CMD_SET_COUNTRY_CODE:
+                    String country = (String) message.obj;
+                    Log.d(TAG, "set country code " + country);
+                    if (!WifiNative.setCountryCodeCommand(country.toUpperCase())) {
+                        Log.e(TAG, "Failed to set country code " + country);
+                    }
                     break;
                 case CMD_STOP_DRIVER:
                     mWakeLock.acquire();
@@ -2283,7 +2141,7 @@
                 case CMD_SET_HIGH_PERF_MODE:
                 case CMD_SET_BLUETOOTH_COEXISTENCE:
                 case CMD_SET_BLUETOOTH_SCAN_MODE:
-                case CMD_SET_NUM_ALLOWED_CHANNELS:
+                case CMD_SET_COUNTRY_CODE:
                 case CMD_START_PACKET_FILTERING:
                 case CMD_STOP_PACKET_FILTERING:
                 case CMD_START_SCAN:
@@ -2333,7 +2191,6 @@
         @Override
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
-            SyncParams syncParams;
             switch(message.what) {
                 case CMD_SET_SCAN_MODE:
                     if (message.arg1 == SCAN_ONLY_MODE) {
@@ -2374,7 +2231,6 @@
         @Override
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
-            SyncParams syncParams;
             StateChangeResult stateChangeResult;
             switch(message.what) {
                 case PASSWORD_MAY_BE_INCORRECT_EVENT:
@@ -2449,18 +2305,25 @@
                         transitionTo(mDisconnectingState);
                     }
                     break;
-                case CMD_START_WPS_PIN:
+                case CMD_START_WPS_PIN_FROM_AP:
                     bssid = (String) message.obj;
                     int apPin = message.arg1;
-                    int pin;
-                    if (apPin != 0) {
-                        /* WPS pin from access point */
-                        success = WifiConfigStore.startWpsWithPinFromAccessPoint(bssid, apPin);
-                    } else {
-                        pin = WifiConfigStore.startWpsWithPinFromDevice(bssid);
-                        success = (pin != -1);
-                        mReplyChannel.replyToMessage(message, CMD_START_WPS_PIN, pin);
+
+                    /* WPS pin from access point */
+                    success = WifiConfigStore.startWpsWithPinFromAccessPoint(bssid, apPin);
+
+                    if (success) {
+                        mWpsStarted = true;
+                        /* Expect a disconnection from the old connection */
+                        transitionTo(mDisconnectingState);
                     }
+                    break;
+                case CMD_START_WPS_PIN_FROM_DEVICE:
+                    bssid = (String) message.obj;
+                    int pin = WifiConfigStore.startWpsWithPinFromDevice(bssid);
+                    success = (pin != FAILURE);
+                    mReplyChannel.replyToMessage(message, CMD_START_WPS_PIN_FROM_DEVICE, pin);
+
                     if (success) {
                         mWpsStarted = true;
                         /* Expect a disconnection from the old connection */
@@ -2491,21 +2354,6 @@
                     handleNetworkDisconnect();
                     transitionTo(mDisconnectedState);
                     break;
-                case CMD_GET_RSSI:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.intValue = WifiNative.getRssiCommand();
-                    notifyOnMsgObject(message);
-                    break;
-                case CMD_GET_RSSI_APPROX:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.intValue = WifiNative.getRssiApproxCommand();
-                    notifyOnMsgObject(message);
-                    break;
-                case CMD_GET_LINK_SPEED:
-                    syncParams = (SyncParams) message.obj;
-                    syncParams.mSyncReturn.intValue = WifiNative.getLinkSpeedCommand();
-                    notifyOnMsgObject(message);
-                    break;
                 default:
                     return NOT_HANDLED;
             }