Merge change 24391 into eclair

* changes:
  RIO-7461: Update media scanner to scan AAC files. (Change in frameworks/base git)
diff --git a/api/current.xml b/api/current.xml
index c8384e4..fa9ab93 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -25457,6 +25457,50 @@
  deprecated="not deprecated"
  visibility="public"
 >
+<method name="disable"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="enable"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getAddress"
+ return="java.lang.String"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getName"
+ return="java.lang.String"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getRemoteDevice"
  return="android.bluetooth.BluetoothDevice"
  abstract="false"
@@ -25470,6 +25514,39 @@
 <parameter name="address" type="java.lang.String">
 </parameter>
 </method>
+<method name="getScanMode"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getState"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="isEnabled"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="listenUsingRfcommOn"
  return="android.bluetooth.BluetoothServerSocket"
  abstract="false"
@@ -25485,6 +25562,186 @@
 <exception name="IOException" type="java.io.IOException">
 </exception>
 </method>
+<method name="setName"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="name" type="java.lang.String">
+</parameter>
+</method>
+<method name="setScanMode"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="mode" type="int">
+</parameter>
+</method>
+<field name="ACTION_SCAN_MODE_CHANGED"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.bluetooth.intent.action.SCAN_MODE_CHANGED&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="ACTION_STATE_CHANGED"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.bluetooth.intent.action.STATE_CHANGED&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="ERROR"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="-1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_PREVIOUS_SCAN_MODE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.bluetooth.intent.extra.PREVIOUS_SCAN_MODE&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_PREVIOUS_STATE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.bluetooth.intent.extra.PREVIOUS_STATE&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_SCAN_MODE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.bluetooth.intent.extra.SCAN_MODE&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_STATE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.bluetooth.intent.extra.STATE&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCAN_MODE_CONNECTABLE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="51"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCAN_MODE_CONNECTABLE_DISCOVERABLE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="53"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCAN_MODE_NONE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="50"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="STATE_OFF"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="40"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="STATE_ON"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="42"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="STATE_TURNING_OFF"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="43"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="STATE_TURNING_ON"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="41"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 </class>
 <class name="BluetoothDevice"
  extends="java.lang.Object"
@@ -25533,6 +25790,17 @@
  visibility="public"
 >
 </method>
+<method name="getName"
+ return="java.lang.String"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="writeToParcel"
  return="void"
  abstract="false"
@@ -25548,6 +25816,17 @@
 <parameter name="flags" type="int">
 </parameter>
 </method>
+<field name="ERROR"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="-1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 </class>
 <class name="BluetoothServerSocket"
  extends="java.lang.Object"
diff --git a/cmds/stagefright/record.cpp b/cmds/stagefright/record.cpp
index 81a1c0a..4751580 100644
--- a/cmds/stagefright/record.cpp
+++ b/cmds/stagefright/record.cpp
@@ -228,7 +228,7 @@
 #endif
 
     sp<MetaData> encMeta = new MetaData;
-    encMeta->setCString(kKeyMIMEType, 1 ? "audio/3gpp" : "audio/mp4a-latm");
+    encMeta->setCString(kKeyMIMEType, 1 ? "audio/amr-wb" : "audio/mp4a-latm");
     encMeta->setInt32(kKeySampleRate, kSampleRate);
     encMeta->setInt32(kKeyChannelCount, kNumChannels);
     encMeta->setInt32(kKeyMaxInputSize, 8192);
@@ -248,7 +248,7 @@
         buffer->release();
         buffer = NULL;
 
-        if (++n == 10000) {
+        if (++n == 100) {
             break;
         }
     }
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java
index b531a50..060f20e 100644
--- a/core/java/android/bluetooth/BluetoothA2dp.java
+++ b/core/java/android/bluetooth/BluetoothA2dp.java
@@ -42,9 +42,6 @@
  *
  * Currently the BluetoothA2dp service runs in the system server and this
  * proxy object will be immediately bound to the service on construction.
- * However this may change in future releases, and error codes such as
- * BluetoothError.ERROR_IPC_NOT_READY will be returned from this API when the
- * proxy object is not yet attached.
  * 
  * Currently this class provides methods to connect to A2DP audio sinks.
  *
@@ -105,16 +102,16 @@
      *  Listen for SINK_STATE_CHANGED_ACTION to find out when the
      *  connection is completed.
      *  @param device Remote BT device.
-     *  @return Result code, negative indicates an immediate error.
+     *  @return false on immediate error, true otherwise
      *  @hide
      */
-    public int connectSink(BluetoothDevice device) {
+    public boolean connectSink(BluetoothDevice device) {
         if (DBG) log("connectSink(" + device + ")");
         try {
             return mService.connectSink(device);
         } catch (RemoteException e) {
-            Log.w(TAG, "", e);
-            return BluetoothError.ERROR_IPC;
+            Log.e(TAG, "", e);
+            return false;
         }
     }
 
@@ -122,16 +119,16 @@
      *  Listen for SINK_STATE_CHANGED_ACTION to find out when
      *  disconnect is completed.
      *  @param device Remote BT device.
-     *  @return Result code, negative indicates an immediate error.
+     *  @return false on immediate error, true otherwise
      *  @hide
      */
-    public int disconnectSink(BluetoothDevice device) {
+    public boolean disconnectSink(BluetoothDevice device) {
         if (DBG) log("disconnectSink(" + device + ")");
         try {
             return mService.disconnectSink(device);
         } catch (RemoteException e) {
-            Log.w(TAG, "", e);
-            return BluetoothError.ERROR_IPC;
+            Log.e(TAG, "", e);
+            return false;
         }
     }
 
@@ -156,14 +153,14 @@
             return Collections.unmodifiableSet(
                     new HashSet<BluetoothDevice>(Arrays.asList(mService.getConnectedSinks())));
         } catch (RemoteException e) {
-            Log.w(TAG, "", e);
+            Log.e(TAG, "", e);
             return null;
         }
     }
 
     /** Get the state of an A2DP sink
      *  @param device Remote BT device.
-     *  @return State code, or negative on error
+     *  @return State code, one of STATE_
      *  @hide
      */
     public int getSinkState(BluetoothDevice device) {
@@ -171,8 +168,8 @@
         try {
             return mService.getSinkState(device);
         } catch (RemoteException e) {
-            Log.w(TAG, "", e);
-            return BluetoothError.ERROR_IPC;
+            Log.e(TAG, "", e);
+            return BluetoothA2dp.STATE_DISCONNECTED;
         }
     }
 
@@ -186,15 +183,15 @@
      * @param device Paired sink
      * @param priority Integer priority, for example PRIORITY_AUTO or
      *                 PRIORITY_NONE
-     * @return Result code, negative indicates an error
+     * @return true if priority is set, false on error
      */
-    public int setSinkPriority(BluetoothDevice device, int priority) {
+    public boolean setSinkPriority(BluetoothDevice device, int priority) {
         if (DBG) log("setSinkPriority(" + device + ", " + priority + ")");
         try {
             return mService.setSinkPriority(device, priority);
         } catch (RemoteException e) {
-            Log.w(TAG, "", e);
-            return BluetoothError.ERROR_IPC;
+            Log.e(TAG, "", e);
+            return false;
         }
     }
 
@@ -208,8 +205,8 @@
         try {
             return mService.getSinkPriority(device);
         } catch (RemoteException e) {
-            Log.w(TAG, "", e);
-            return BluetoothError.ERROR_IPC;
+            Log.e(TAG, "", e);
+            return PRIORITY_OFF;
         }
     }
 
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 5a182f0..18f6995 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -16,6 +16,8 @@
 
 package android.bluetooth;
 
+import android.annotation.SdkConstant;
+import android.annotation.SdkConstant.SdkConstantType;
 import android.os.RemoteException;
 import android.util.Log;
 
@@ -40,32 +42,118 @@
 public final class BluetoothAdapter {
     private static final String TAG = "BluetoothAdapter";
 
-    /** @hide */
-    public static final int BLUETOOTH_STATE_OFF = 0;
-    /** @hide */
-    public static final int BLUETOOTH_STATE_TURNING_ON = 1;
-    /** @hide */
-    public static final int BLUETOOTH_STATE_ON = 2;
-    /** @hide */
-    public static final int BLUETOOTH_STATE_TURNING_OFF = 3;
+    /**
+     * Sentinel error value for this class. Guaranteed to not equal any other
+     * integer constant in this class. Provided as a convenience for functions
+     * that require a sentinel error value, for example:
+     * <p><code>Intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+     * BluetoothAdapter.ERROR)</code>
+     */
+    public static final int ERROR = -1;
 
-    /** Inquiry scan and page scan are both off.
-     *  Device is neither discoverable nor connectable
-     *  @hide */
-    public static final int SCAN_MODE_NONE = 0;
-    /** Page scan is on, inquiry scan is off.
-     *  Device is connectable, but not discoverable
-     *  @hide*/
-    public static final int SCAN_MODE_CONNECTABLE = 1;
-    /** Page scan and inquiry scan are on.
-     *  Device is connectable and discoverable
-     *  @hide*/
-    public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = 3;
+    /**
+     * Broadcast Action: The state of the local Bluetooth adapter has been
+     * changed.
+     * <p>For example, Bluetooth has been turned on or off.
+     * <p>Contains the extra fields {@link #EXTRA_STATE} and {@link
+     * #EXTRA_PREVIOUS_STATE} containing the new and old states
+     * respectively.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_STATE_CHANGED =
+            "android.bluetooth.intent.action.STATE_CHANGED";
 
-    /** @hide */
-    public static final int RESULT_FAILURE = -1;
-    /** @hide */
-    public static final int RESULT_SUCCESS = 0;
+    /**
+     * Used as an int extra field in {@link #ACTION_STATE_CHANGED}
+     * intents to request the current power state. Possible values are:
+     * {@link #STATE_OFF},
+     * {@link #STATE_TURNING_ON},
+     * {@link #STATE_ON},
+     * {@link #STATE_TURNING_OFF},
+     */
+    public static final String EXTRA_STATE =
+            "android.bluetooth.intent.extra.STATE";
+    /**
+     * Used as an int extra field in {@link #ACTION_STATE_CHANGED}
+     * intents to request the previous power state. Possible values are:
+     * {@link #STATE_OFF},
+     * {@link #STATE_TURNING_ON},
+     * {@link #STATE_ON},
+     * {@link #STATE_TURNING_OFF},
+     */
+    public static final String EXTRA_PREVIOUS_STATE =
+            "android.bluetooth.intent.extra.PREVIOUS_STATE";
+
+    /**
+     * Indicates the local Bluetooth adapter is off.
+     */
+    public static final int STATE_OFF = 40;
+    /**
+     * Indicates the local Bluetooth adapter is turning on. However local
+     * clients should wait for {@link #STATE_ON} before attempting to
+     * use the adapter.
+     */
+    public static final int STATE_TURNING_ON = 41;
+    /**
+     * Indicates the local Bluetooth adapter is on, and ready for use.
+     */
+    public static final int STATE_ON = 42;
+    /**
+     * Indicates the local Bluetooth adapter is turning off. Local clients
+     * should immediately attempt graceful disconnection of any remote links.
+     */
+    public static final int STATE_TURNING_OFF = 43;
+
+    /**
+     * Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter
+     * has changed.
+     * <p>Contains the extra fields {@link #EXTRA_SCAN_MODE} and {@link
+     * #EXTRA_PREVIOUS_SCAN_MODE} containing the new and old scan modes
+     * respectively.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_SCAN_MODE_CHANGED =
+            "android.bluetooth.intent.action.SCAN_MODE_CHANGED";
+
+    /**
+     * Used as an int extra field in {@link #ACTION_SCAN_MODE_CHANGED}
+     * intents to request the current scan mode. Possible values are:
+     * {@link #SCAN_MODE_NONE},
+     * {@link #SCAN_MODE_CONNECTABLE},
+     * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE},
+     */
+    public static final String EXTRA_SCAN_MODE = "android.bluetooth.intent.extra.SCAN_MODE";
+    /**
+     * Used as an int extra field in {@link #ACTION_SCAN_MODE_CHANGED}
+     * intents to request the previous scan mode. Possible values are:
+     * {@link #SCAN_MODE_NONE},
+     * {@link #SCAN_MODE_CONNECTABLE},
+     * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE},
+     */
+    public static final String EXTRA_PREVIOUS_SCAN_MODE =
+            "android.bluetooth.intent.extra.PREVIOUS_SCAN_MODE";
+
+    /**
+     * Indicates that both inquiry scan and page scan are disabled on the local
+     * Bluetooth adapter. Therefore this device is neither discoverable
+     * nor connectable from remote Bluetooth devices.
+     */
+    public static final int SCAN_MODE_NONE = 50;
+    /**
+     * Indicates that inquiry scan is disabled, but page scan is enabled on the
+     * local Bluetooth adapter. Therefore this device is not discoverable from
+     * remote Bluetooth devices, but is connectable from remote devices that
+     * have previously discovered this device.
+     */
+    public static final int SCAN_MODE_CONNECTABLE = 51;
+    /**
+     * Indicates that both inquiry scan and page scan are enabled on the local
+     * Bluetooth adapter. Therefore this device is both discoverable and
+     * connectable from remote Bluetooth devices.
+     */
+    public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = 53;
 
     /** The user will be prompted to enter a pin
      * @hide */
@@ -97,6 +185,7 @@
      * such as "00:11:22:33:AA:BB".
      * <p>A {@link BluetoothDevice} will always be returned for a valid
      * hardware address, even if this adapter has never seen that device.
+     *
      * @param address valid Bluetooth MAC address
      * @throws IllegalArgumentException if address is invalid
      */
@@ -105,10 +194,12 @@
     }
 
     /**
-     * Is Bluetooth currently turned on.
+     * Return true if Bluetooth is currently enabled and ready for use.
+     * <p>Equivalent to:
+     * <code>getBluetoothState() == STATE_ON</code>
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
      *
-     * @return true if Bluetooth enabled, false otherwise.
-     * @hide
+     * @return true if the local adapter is turned on
      */
     public boolean isEnabled() {
         try {
@@ -118,28 +209,40 @@
     }
 
     /**
-     * Get the current state of Bluetooth.
+     * Get the current state of the local Bluetooth adapter.
+     * <p>Possible return values are
+     * {@link #STATE_OFF},
+     * {@link #STATE_TURNING_ON},
+     * {@link #STATE_ON},
+     * {@link #STATE_TURNING_OFF}.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
      *
-     * @return One of BLUETOOTH_STATE_ or BluetoothError.ERROR.
-     * @hide
+     * @return current state of Bluetooth adapter
      */
-    public int getBluetoothState() {
+    public int getState() {
         try {
             return mService.getBluetoothState();
         } catch (RemoteException e) {Log.e(TAG, "", e);}
-        return BluetoothError.ERROR;
+        return STATE_OFF;
     }
 
     /**
-     * Enable the Bluetooth device.
-     * Turn on the underlying hardware.
-     * This is an asynchronous call,
-     * BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION can be used to check if
-     * and when the device is sucessfully enabled.
-     * @return false if we cannot enable the Bluetooth device. True does not
-     * imply the device was enabled, it only implies that so far there were no
-     * problems.
-     * @hide
+     * Turn on the local Bluetooth adapter.
+     * <p>This powers on the underlying Bluetooth hardware, and starts all
+     * Bluetooth system services.
+     * <p>This is an asynchronous call: it will return immediatley, and
+     * clients should listen for {@link #ACTION_STATE_CHANGED}
+     * to be notified of subsequent adapter state changes. If this call returns
+     * true, then the adapter state will immediately transition from {@link
+     * #STATE_OFF} to {@link #STATE_TURNING_ON}, and some time
+     * later transition to either {@link #STATE_OFF} or {@link
+     * #STATE_ON}. If this call returns false then there was an
+     * immediate problem that will prevent the adapter from being turned on -
+     * such as Airplane mode, or the adapter is already turned on.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     *
+     * @return true to indicate adapter startup has begun, or false on
+     *         immediate error
      */
     public boolean enable() {
         try {
@@ -149,11 +252,22 @@
     }
 
     /**
-     * Disable the Bluetooth device.
-     * This turns off the underlying hardware.
+     * Turn off the local Bluetooth adapter.
+     * <p>This gracefully shuts down all Bluetooth connections, stops Bluetooth
+     * system services, and powers down the underlying Bluetooth hardware.
+     * <p>This is an asynchronous call: it will return immediatley, and
+     * clients should listen for {@link #ACTION_STATE_CHANGED}
+     * to be notified of subsequent adapter state changes. If this call returns
+     * true, then the adapter state will immediately transition from {@link
+     * #STATE_ON} to {@link #STATE_TURNING_OFF}, and some time
+     * later transition to either {@link #STATE_OFF} or {@link
+     * #STATE_ON}. If this call returns false then there was an
+     * immediate problem that will prevent the adapter from being turned off -
+     * such as the adapter already being turned off.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
      *
-     * @return true if successful, false otherwise.
-     * @hide
+     * @return true to indicate adapter shutdown has begun, or false on
+     *         immediate error
      */
     public boolean disable() {
         try {
@@ -162,7 +276,13 @@
         return false;
     }
 
-    /** @hide */
+    /**
+     * Returns the hardware address of the local Bluetooth adapter.
+     * <p>For example, "00:11:22:AA:BB:CC".
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+     *
+     * @return Bluetooth hardware address as string
+     */
     public String getAddress() {
         try {
             return mService.getAddress();
@@ -171,13 +291,11 @@
     }
 
     /**
-     * Get the friendly Bluetooth name of this device.
+     * Get the friendly Bluetooth name of the local Bluetooth adapter.
+     * <p>This name is visible to remote Bluetooth devices.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
      *
-     * This name is visible to remote Bluetooth devices. Currently it is only
-     * possible to retrieve the Bluetooth name when Bluetooth is enabled.
-     *
-     * @return the Bluetooth name, or null if there was a problem.
-     * @hide
+     * @return the Bluetooth name, or null on error
      */
     public String getName() {
         try {
@@ -187,14 +305,15 @@
     }
 
     /**
-     * Set the friendly Bluetooth name of this device.
+     * Set the friendly Bluetooth name of the local Bluetoth adapter.
+     * <p>This name is visible to remote Bluetooth devices.
+     * <p>Valid Bluetooth names are a maximum of 248 UTF-8 characters, however
+     * many remote devices can only display the first 40 characters, and some
+     * may be limited to just 20.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
      *
-     * This name is visible to remote Bluetooth devices. The Bluetooth Service
-     * is responsible for persisting this name.
-     *
-     * @param name the name to set
-     * @return     true, if the name was successfully set. False otherwise.
-     * @hide
+     * @param name a valid Bluetooth name
+     * @return     true if the name was set, false otherwise
      */
     public boolean setName(String name) {
         try {
@@ -204,28 +323,46 @@
     }
 
     /**
-     * Get the current scan mode.
-     * Used to determine if the local device is connectable and/or discoverable
-     * @return Scan mode, one of SCAN_MODE_* or an error code
-     * @hide
+     * Get the current Bluetooth scan mode of the local Bluetooth adaper.
+     * <p>The Bluetooth scan mode determines if the local adapter is
+     * connectable and/or discoverable from remote Bluetooth devices.
+     * <p>Possible values are:
+     * {@link #SCAN_MODE_NONE},
+     * {@link #SCAN_MODE_CONNECTABLE},
+     * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+     *
+     * @return scan mode
      */
     public int getScanMode() {
         try {
             return mService.getScanMode();
         } catch (RemoteException e) {Log.e(TAG, "", e);}
-        return BluetoothError.ERROR_IPC;
+        return SCAN_MODE_NONE;
     }
 
     /**
-     * Set the current scan mode.
-     * Used to make the local device connectable and/or discoverable
-     * @param scanMode One of SCAN_MODE_*
-     * @hide
+     * Set the Bluetooth scan mode of the local Bluetooth adapter.
+     * <p>The Bluetooth scan mode determines if the local adapter is
+     * connectable and/or discoverable from remote Bluetooth devices.
+     * <p>For privacy reasons, it is recommended to limit the duration of time
+     * that the local adapter remains in a discoverable scan mode. For example,
+     * 2 minutes is a generous time to allow a remote Bluetooth device to
+     * initiate and complete its discovery process.
+     * <p>Valid scan mode values are:
+     * {@link #SCAN_MODE_NONE},
+     * {@link #SCAN_MODE_CONNECTABLE},
+     * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     *
+     * @param mode valid scan mode
+     * @return     true if the scan mode was set, false otherwise
      */
-    public void setScanMode(int scanMode) {
+    public boolean setScanMode(int mode) {
         try {
-            mService.setScanMode(scanMode);
+            return mService.setScanMode(mode);
         } catch (RemoteException e) {Log.e(TAG, "", e);}
+        return false;
     }
 
     /** @hide */
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 1b7011c..1ab4389 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -44,6 +44,15 @@
 public final class BluetoothDevice implements Parcelable {
     private static final String TAG = "BluetoothDevice";
 
+    /**
+     * Sentinel error value for this class. Guaranteed to not equal any other
+     * integer constant in this class. Provided as a convenience for functions
+     * that require a sentinel error value, for example:
+     * <p><code>Intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+     * BluetoothAdapter.ERROR)</code>
+     */
+    public static final int ERROR = -1;
+
     /** We do not have a link key for the remote device, and are therefore not
      * bonded
      * @hide*/
@@ -65,7 +74,9 @@
      *  @hide */
     public static final int DEVICE_PICKER_FILTER_TYPE_TRANSFER = 2;
 
-    //TODO: Unify these result codes in BluetoothResult or BluetoothError
+    /** A bond attempt succeeded
+     * @hide */
+    public static final int BOND_SUCCESS = 0;
     /** A bond attempt failed because pins did not match, or remote device did
      * not respond to pin request in time 
      * @hide */
@@ -193,9 +204,9 @@
      * <p>The local adapter will automatically retrieve remote names when
      * performing a device scan, and will cache them. This method just returns
      * the name for this device from the cache.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
      *
      * @return the Bluetooth name, or null if there was a problem.
-     * @hide
      */
     public String getName() {
         try {
@@ -252,8 +263,8 @@
      * Get the bonding state of a remote device.
      *
      * Result is one of:
-     * BluetoothError.*
      * BOND_*
+     * ERROR
      *
      * @param address Bluetooth hardware address of the remote device to check.
      * @return Result code
@@ -263,7 +274,7 @@
         try {
             return sService.getBondState(mAddress);
         } catch (RemoteException e) {Log.e(TAG, "", e);}
-        return BluetoothError.ERROR_IPC;
+        return BluetoothDevice.ERROR;
     }
 
     /**
@@ -298,7 +309,7 @@
         try {
             return sService.getRemoteClass(mAddress);
         } catch (RemoteException e) {Log.e(TAG, "", e);}
-        return BluetoothError.ERROR_IPC;
+        return BluetoothDevice.ERROR;
     }
 
     /** @hide */
@@ -314,7 +325,7 @@
          try {
              return sService.getRemoteServiceChannel(mAddress, uuid);
          } catch (RemoteException e) {Log.e(TAG, "", e);}
-         return BluetoothError.ERROR_IPC;
+         return BluetoothDevice.ERROR;
     }
 
     /** @hide */
@@ -358,6 +369,7 @@
      * connection.
      * <p>Valid RFCOMM channels are in range 1 to 30.
      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+     *
      * @param channel RFCOMM channel to connect to
      * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
      * @throws IOException on error, for example Bluetooth not available, or
diff --git a/core/java/android/bluetooth/BluetoothError.java b/core/java/android/bluetooth/BluetoothError.java
deleted file mode 100644
index 2554bea..0000000
--- a/core/java/android/bluetooth/BluetoothError.java
+++ /dev/null
@@ -1,42 +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.bluetooth;
-
-/**
- * Bluetooth API error codes.
- *
- * Errors are always negative.
- *
- * @hide
- */
-public class BluetoothError {
-    /** No error */
-    public static final int SUCCESS = 0;
-
-    /** Generic error */
-    public static final int ERROR = -1000;
-
-    /** Bluetooth currently disabled */
-    public static final int ERROR_DISABLED = -1001;
-
-    /** IPC is not ready, for example service is not yet bound */
-    public static final int ERROR_IPC_NOT_READY = -1011;
-
-    /** Some other IPC error, for example a RemoteException */
-    public static final int ERROR_IPC = -1012;
-
-}
diff --git a/core/java/android/bluetooth/BluetoothIntent.java b/core/java/android/bluetooth/BluetoothIntent.java
index c39bc3d..8de19f5 100644
--- a/core/java/android/bluetooth/BluetoothIntent.java
+++ b/core/java/android/bluetooth/BluetoothIntent.java
@@ -20,17 +20,12 @@
 import android.annotation.SdkConstant.SdkConstantType;
 
 /**
- * The Android Bluetooth API is not finalized, and *will* change. Use at your
- * own risk.
+ * Bluetooth API constants.
  *
- * Manages the local Bluetooth device. Scan for devices, create bondings,
- * power up and down the adapter.
- *
+ * TODO: Deprecate this class
  * @hide
  */
 public interface BluetoothIntent {
-    public static final String SCAN_MODE =
-        "android.bluetooth.intent.SCAN_MODE";
     public static final String DEVICE =
         "android.bluetooth.intent.DEVICE";
     public static final String NAME =
@@ -41,10 +36,6 @@
         "android.bluetooth.intent.RSSI";
     public static final String CLASS =
         "android.bluetooth.intent.CLASS";
-    public static final String BLUETOOTH_STATE =
-        "android.bluetooth.intent.BLUETOOTH_STATE";
-    public static final String BLUETOOTH_PREVIOUS_STATE =
-        "android.bluetooth.intent.BLUETOOTH_PREVIOUS_STATE";
     public static final String HEADSET_STATE =
         "android.bluetooth.intent.HEADSET_STATE";
     public static final String HEADSET_PREVIOUS_STATE =
@@ -91,25 +82,10 @@
     public static final String DEVICE_PICKER_DEVICE_PICKER =
         "android.bluetooth.intent.action.DEVICE_PICKER";
 
-    /** Broadcast when the local Bluetooth device state changes, for example
-     *  when Bluetooth is enabled. Will contain int extra's BLUETOOTH_STATE and
-     *  BLUETOOTH_PREVIOUS_STATE. */
-    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
-    public static final String BLUETOOTH_STATE_CHANGED_ACTION =
-        "android.bluetooth.intent.action.BLUETOOTH_STATE_CHANGED";
-
     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     public static final String NAME_CHANGED_ACTION  =
         "android.bluetooth.intent.action.NAME_CHANGED";
 
-    /**
-     * Broadcast when the scan mode changes. Always contains an int extra
-     * named SCAN_MODE that contains the new scan mode.
-     */
-    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
-    public static final String SCAN_MODE_CHANGED_ACTION         =
-        "android.bluetooth.intent.action.SCAN_MODE_CHANGED";
-
     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     public static final String DISCOVERY_STARTED_ACTION          =
         "android.bluetooth.intent.action.DISCOVERY_STARTED";
diff --git a/core/java/android/bluetooth/IBluetoothA2dp.aidl b/core/java/android/bluetooth/IBluetoothA2dp.aidl
index e6c6be2..2df7f23 100644
--- a/core/java/android/bluetooth/IBluetoothA2dp.aidl
+++ b/core/java/android/bluetooth/IBluetoothA2dp.aidl
@@ -24,10 +24,10 @@
  * {@hide}
  */
 interface IBluetoothA2dp {
-    int connectSink(in BluetoothDevice device);
-    int disconnectSink(in BluetoothDevice device);
+    boolean connectSink(in BluetoothDevice device);
+    boolean disconnectSink(in BluetoothDevice device);
     BluetoothDevice[] getConnectedSinks();  // change to Set<> once AIDL supports
     int getSinkState(in BluetoothDevice device);
-    int setSinkPriority(in BluetoothDevice device, int priority);
+    boolean setSinkPriority(in BluetoothDevice device, int priority);
     int getSinkPriority(in BluetoothDevice device);
 }
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index d9fcb53..a24e0d21 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -25,7 +25,6 @@
 import android.bluetooth.BluetoothA2dp;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothError;
 import android.bluetooth.BluetoothIntent;
 import android.bluetooth.BluetoothUuid;
 import android.bluetooth.IBluetoothA2dp;
@@ -81,20 +80,20 @@
             String action = intent.getAction();
             BluetoothDevice device =
                     intent.getParcelableExtra(BluetoothIntent.DEVICE);
-            if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
-                int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
-                                               BluetoothError.ERROR);
+            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+                                               BluetoothAdapter.ERROR);
                 switch (state) {
-                case BluetoothAdapter.BLUETOOTH_STATE_ON:
+                case BluetoothAdapter.STATE_ON:
                     onBluetoothEnable();
                     break;
-                case BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF:
+                case BluetoothAdapter.STATE_TURNING_OFF:
                     onBluetoothDisable();
                     break;
                 }
             } else if (action.equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)) {
                 int bondState = intent.getIntExtra(BluetoothIntent.BOND_STATE,
-                                                   BluetoothError.ERROR);
+                                                   BluetoothDevice.ERROR);
                 switch(bondState) {
                 case BluetoothDevice.BOND_BONDED:
                     setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO);
@@ -134,7 +133,7 @@
 
         mAdapter = (BluetoothAdapter) context.getSystemService(Context.BLUETOOTH_SERVICE);
 
-        mIntentFilter = new IntentFilter(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
+        mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
         mIntentFilter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
         mIntentFilter.addAction(BluetoothIntent.REMOTE_DEVICE_CONNECTED_ACTION);
         mContext.registerReceiver(mReceiver, mIntentFilter);
@@ -273,7 +272,7 @@
         mAudioManager.setParameters(BLUETOOTH_ENABLED + "=false");
     }
 
-    public synchronized int connectSink(BluetoothDevice device) {
+    public synchronized boolean connectSink(BluetoothDevice device) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
         if (DBG) log("connectSink(" + device + ")");
@@ -284,11 +283,11 @@
                 BluetoothA2dp.STATE_CONNECTED,
                 BluetoothA2dp.STATE_PLAYING,
                 BluetoothA2dp.STATE_DISCONNECTING}).size() != 0) {
-            return BluetoothError.ERROR;
+            return false;
         }
 
         if (mAudioDevices.get(device) == null && !addAudioSink(device))
-            return BluetoothError.ERROR;
+            return false;
 
         int state = mAudioDevices.get(device);
 
@@ -296,44 +295,44 @@
         case BluetoothA2dp.STATE_CONNECTED:
         case BluetoothA2dp.STATE_PLAYING:
         case BluetoothA2dp.STATE_DISCONNECTING:
-            return BluetoothError.ERROR;
+            return false;
         case BluetoothA2dp.STATE_CONNECTING:
-            return BluetoothError.SUCCESS;
+            return true;
         }
 
         String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
         if (path == null)
-            return BluetoothError.ERROR;
+            return false;
 
         // State is DISCONNECTED
         if (!connectSinkNative(path)) {
-            return BluetoothError.ERROR;
+            return false;
         }
-        return BluetoothError.SUCCESS;
+        return true;
     }
 
-    public synchronized int disconnectSink(BluetoothDevice device) {
+    public synchronized boolean disconnectSink(BluetoothDevice device) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
         if (DBG) log("disconnectSink(" + device + ")");
 
         String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
         if (path == null) {
-            return BluetoothError.ERROR;
+            return false;
         }
 
         switch (getSinkState(device)) {
         case BluetoothA2dp.STATE_DISCONNECTED:
-            return BluetoothError.ERROR;
+            return false;
         case BluetoothA2dp.STATE_DISCONNECTING:
-            return BluetoothError.SUCCESS;
+            return true;
         }
 
         // State is CONNECTING or CONNECTED or PLAYING
         if (!disconnectSinkNative(path)) {
-            return BluetoothError.ERROR;
+            return false;
         } else {
-            return BluetoothError.SUCCESS;
+            return true;
         }
     }
 
@@ -359,15 +358,14 @@
                 BluetoothA2dp.PRIORITY_OFF);
     }
 
-    public synchronized int setSinkPriority(BluetoothDevice device, int priority) {
+    public synchronized boolean setSinkPriority(BluetoothDevice device, int priority) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
         if (!BluetoothDevice.checkBluetoothAddress(device.getAddress())) {
-            return BluetoothError.ERROR;
+            return false;
         }
         return Settings.Secure.putInt(mContext.getContentResolver(),
-                Settings.Secure.getBluetoothA2dpSinkPriorityKey(device.getAddress()), priority) ?
-                BluetoothError.SUCCESS : BluetoothError.ERROR;
+                Settings.Secure.getBluetoothA2dpSinkPriorityKey(device.getAddress()), priority);
     }
 
     private synchronized void onSinkPropertyChanged(String path, String []propValues) {
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java
index 8cef3a2..b5eb9ac 100644
--- a/core/java/android/server/BluetoothEventLoop.java
+++ b/core/java/android/server/BluetoothEventLoop.java
@@ -20,7 +20,6 @@
 import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothError;
 import android.bluetooth.BluetoothIntent;
 import android.bluetooth.BluetoothUuid;
 import android.content.Context;
@@ -169,7 +168,7 @@
 
     private void onCreatePairedDeviceResult(String address, int result) {
         address = address.toUpperCase();
-        if (result == BluetoothError.SUCCESS) {
+        if (result == BluetoothDevice.BOND_SUCCESS) {
             mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_BONDED);
             if (mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) {
                 mBluetoothService.getBondState().clearPinAttempts(address);
@@ -240,6 +239,11 @@
     }
 
     /*package*/ void onPropertyChanged(String[] propValues) {
+        if (mBluetoothService.isAdapterPropertiesEmpty()) {
+            // We have got a property change before
+            // we filled up our cache.
+            mBluetoothService.getAllProperties();
+        }
         String name = propValues[0];
         if (name.equals("Name")) {
             Intent intent = new Intent(BluetoothIntent.NAME_CHANGED_ACTION);
@@ -260,8 +264,8 @@
                     pairable.equals("true"),
                     discoverable.equals("true"));
             if (mode >= 0) {
-                Intent intent = new Intent(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
-                intent.putExtra(BluetoothIntent.SCAN_MODE, mode);
+                Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
+                intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, mode);
                 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
                 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
             }
@@ -366,7 +370,7 @@
         address = address.toUpperCase();
         mPasskeyAgentRequestData.put(address, new Integer(nativeData));
 
-        if (mBluetoothService.getBluetoothState() == BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF) {
+        if (mBluetoothService.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) {
             // shutdown path
             mBluetoothService.cancelPairingUserInput(address);
             return null;
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index b168850..6482c4c 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -27,7 +27,6 @@
 import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothError;
 import android.bluetooth.BluetoothHeadset;
 import android.bluetooth.BluetoothIntent;
 import android.bluetooth.IBluetooth;
@@ -102,7 +101,7 @@
             disableNative();
         }
 
-        mBluetoothState = BluetoothAdapter.BLUETOOTH_STATE_OFF;
+        mBluetoothState = BluetoothAdapter.STATE_OFF;
         mIsDiscovering = false;
         mAdapterProperties = new HashMap<String, String>();
         mDeviceProperties = new HashMap<String, Map<String,String>>();
@@ -128,7 +127,7 @@
 
     public boolean isEnabled() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
-        return mBluetoothState == BluetoothAdapter.BLUETOOTH_STATE_ON;
+        return mBluetoothState == BluetoothAdapter.STATE_ON;
     }
 
     public int getBluetoothState() {
@@ -153,9 +152,9 @@
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
 
         switch (mBluetoothState) {
-        case BluetoothAdapter.BLUETOOTH_STATE_OFF:
+        case BluetoothAdapter.STATE_OFF:
             return true;
-        case BluetoothAdapter.BLUETOOTH_STATE_ON:
+        case BluetoothAdapter.STATE_ON:
             break;
         default:
             return false;
@@ -163,7 +162,7 @@
         if (mEnableThread != null && mEnableThread.isAlive()) {
             return false;
         }
-        setBluetoothState(BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF);
+        setBluetoothState(BluetoothAdapter.STATE_TURNING_OFF);
 
         // Allow 3 seconds for profiles to gracefully disconnect
         // TODO: Introduce a callback mechanism so that each profile can notify
@@ -175,7 +174,7 @@
 
 
     private synchronized void finishDisable(boolean saveSetting) {
-        if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF) {
+        if (mBluetoothState != BluetoothAdapter.STATE_TURNING_OFF) {
             return;
         }
         mEventLoop.stop();
@@ -189,8 +188,8 @@
         }
 
         // update mode
-        Intent intent = new Intent(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
-        intent.putExtra(BluetoothIntent.SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
+        Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
+        intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
         mContext.sendBroadcast(intent, BLUETOOTH_PERM);
 
         mIsDiscovering = false;
@@ -200,7 +199,7 @@
             persistBluetoothOnSetting(false);
         }
 
-        setBluetoothState(BluetoothAdapter.BLUETOOTH_STATE_OFF);
+        setBluetoothState(BluetoothAdapter.STATE_OFF);
 
         // Log bluetooth off to battery stats.
         long ident = Binder.clearCallingIdentity();
@@ -237,13 +236,13 @@
         if (mIsAirplaneSensitive && isAirplaneModeOn()) {
             return false;
         }
-        if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_OFF) {
+        if (mBluetoothState != BluetoothAdapter.STATE_OFF) {
             return false;
         }
         if (mEnableThread != null && mEnableThread.isAlive()) {
             return false;
         }
-        setBluetoothState(BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON);
+        setBluetoothState(BluetoothAdapter.STATE_TURNING_ON);
         mEnableThread = new EnableThread(saveSetting);
         mEnableThread.start();
         return true;
@@ -251,7 +250,7 @@
 
     /** Forcibly restart Bluetooth if it is on */
     /* package */ synchronized void restart() {
-        if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_ON) {
+        if (mBluetoothState != BluetoothAdapter.STATE_ON) {
             return;
         }
         mRestart = true;
@@ -267,9 +266,9 @@
 
         if (DBG) log("Bluetooth state " + mBluetoothState + " -> " + state);
 
-        Intent intent = new Intent(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
-        intent.putExtra(BluetoothIntent.BLUETOOTH_PREVIOUS_STATE, mBluetoothState);
-        intent.putExtra(BluetoothIntent.BLUETOOTH_STATE, state);
+        Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
+        intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, mBluetoothState);
+        intent.putExtra(BluetoothAdapter.EXTRA_STATE, state);
         intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
 
         mBluetoothState = state;
@@ -357,8 +356,8 @@
             mEnableThread = null;
 
             setBluetoothState(res ?
-                              BluetoothAdapter.BLUETOOTH_STATE_ON :
-                              BluetoothAdapter.BLUETOOTH_STATE_OFF);
+                              BluetoothAdapter.STATE_ON :
+                              BluetoothAdapter.STATE_OFF);
 
             if (res) {
                 // Update mode
@@ -411,7 +410,7 @@
                         ));
 
         public synchronized void loadBondState() {
-            if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON) {
+            if (mBluetoothState != BluetoothAdapter.STATE_TURNING_ON) {
                 return;
             }
             String []bonds = null;
@@ -538,6 +537,10 @@
         }
     }
 
+    /*package*/ synchronized boolean isAdapterPropertiesEmpty() {
+        return mAdapterProperties.isEmpty();
+    }
+
     /*package*/synchronized void getAllProperties() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
         mAdapterProperties.clear();
@@ -629,17 +632,22 @@
     public synchronized boolean setScanMode(int mode) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
-        boolean pairable = false, discoverable = false;
-        String modeString = scanModeToBluezString(mode);
-        if (modeString.equals("off")) {
+        boolean pairable = false;
+        boolean discoverable = false;
+        switch (mode) {
+        case BluetoothAdapter.SCAN_MODE_NONE:
             pairable = false;
             discoverable = false;
-        } else if (modeString.equals("pariable")) {
+            break;
+        case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
             pairable = true;
             discoverable = false;
-        } else if (modeString.equals("discoverable")) {
+        case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
             pairable = true;
             discoverable = true;
+        default:
+            Log.w(TAG, "Requested invalid scan mode " + mode);
+            return false;
         }
         setPropertyBoolean("Pairable", pairable);
         setPropertyBoolean("Discoverable", discoverable);
@@ -705,7 +713,7 @@
     public synchronized int getScanMode() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
         if (!isEnabled())
-            return BluetoothError.ERROR;
+            return BluetoothAdapter.SCAN_MODE_NONE;
 
         boolean pairable = getProperty("Pairable").equals("true");
         boolean discoverable = getProperty("Discoverable").equals("true");
@@ -801,7 +809,7 @@
     public synchronized int getBondState(String address) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
         if (!BluetoothDevice.checkBluetoothAddress(address)) {
-            return BluetoothError.ERROR;
+            return BluetoothDevice.ERROR;
         }
         return mBondState.getBondState(address.toUpperCase());
     }
@@ -975,7 +983,7 @@
     public int getRemoteServiceChannel(String address, String uuid) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
         if (!BluetoothDevice.checkBluetoothAddress(address)) {
-            return BluetoothError.ERROR_IPC;
+            return BluetoothDevice.ERROR;
         }
         return getDeviceServiceChannelNative(getObjectPathFromAddress(address), uuid, 0x0004);
     }
@@ -1099,16 +1107,16 @@
         pw.println("\nmIsAirplaneSensitive = " + mIsAirplaneSensitive + "\n");
 
         switch(mBluetoothState) {
-        case BluetoothAdapter.BLUETOOTH_STATE_OFF:
+        case BluetoothAdapter.STATE_OFF:
             pw.println("\nBluetooth OFF\n");
             return;
-        case BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON:
+        case BluetoothAdapter.STATE_TURNING_ON:
             pw.println("\nBluetooth TURNING ON\n");
             return;
-        case BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF:
+        case BluetoothAdapter.STATE_TURNING_OFF:
             pw.println("\nBluetooth TURNING OFF\n");
             return;
-        case BluetoothAdapter.BLUETOOTH_STATE_ON:
+        case BluetoothAdapter.STATE_ON:
             pw.println("\nBluetooth ON\n");
         }
 
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 8a986fa..8446475 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -46,6 +46,7 @@
 import android.util.AttributeSet;
 import android.util.EventLog;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.Gravity;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -2048,6 +2049,10 @@
     protected int computeHorizontalScrollRange() {
         if (mDrawHistory) {
             return mHistoryWidth;
+        } else if (mLastWidthSent == mContentWidth) {
+            // special case to avoid rounding error. Otherwise we may get a
+            // faked scrollbar sometimes.
+            return getViewWidth();
         } else {
             return contentToViewDimension(mContentWidth);
         }
@@ -2061,7 +2066,14 @@
         if (mDrawHistory) {
             return mHistoryHeight;
         } else {
-            int height = contentToViewDimension(mContentHeight);
+            int height;
+            // special case to avoid rounding error. Otherwise we may get a
+            // faked scrollbar sometimes.
+            if (mLastHeightSent == mContentHeight) {
+                height = getViewHeight();
+            } else {
+                height = contentToViewDimension(mContentHeight);
+            }
             if (mFindIsUp) {
                 height += FIND_HEIGHT;
             }
@@ -2768,7 +2780,8 @@
                 mZoomScale = 0;
                 if (mNeedToAdjustWebTextView) {
                     mNeedToAdjustWebTextView = false;
-                    mWebTextView.setTextSize(contentToViewDimension(
+                    mWebTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
+                            contentToViewDimension(
                             nativeFocusCandidateTextSize()));
                     Rect bounds = nativeFocusCandidateNodeBounds();
                     Rect vBox = contentToView(bounds);
@@ -3333,7 +3346,8 @@
             // Initialize our generation number.
             mTextGeneration = 0;
         }
-        mWebTextView.setTextSize(contentToViewDimension(nativeFocusCandidateTextSize()));
+        mWebTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
+                contentToViewDimension(nativeFocusCandidateTextSize()));
         Rect visibleRect = new Rect();
         calcOurContentVisibleRect(visibleRect);
         // Note that sendOurVisibleRect calls viewToContent, so the coordinates
diff --git a/core/java/com/android/internal/app/ShutdownThread.java b/core/java/com/android/internal/app/ShutdownThread.java
index 4c9451e..9e1f325 100644
--- a/core/java/com/android/internal/app/ShutdownThread.java
+++ b/core/java/com/android/internal/app/ShutdownThread.java
@@ -185,7 +185,7 @@
         
         try {
             bluetoothOff = bluetooth == null ||
-                           bluetooth.getBluetoothState() == BluetoothAdapter.BLUETOOTH_STATE_OFF;
+                           bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
             if (!bluetoothOff) {
                 Log.w(TAG, "Disabling Bluetooth...");
                 bluetooth.disable(false);  // disable but don't persist new state
@@ -213,7 +213,7 @@
             if (!bluetoothOff) {
                 try {
                     bluetoothOff =
-                            bluetooth.getBluetoothState() == BluetoothAdapter.BLUETOOTH_STATE_OFF;
+                            bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
                 } catch (RemoteException ex) {
                     Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                     bluetoothOff = true;
diff --git a/core/java/com/android/internal/widget/NumberPicker.java b/core/java/com/android/internal/widget/NumberPicker.java
index 0424ced..ae08eca 100644
--- a/core/java/com/android/internal/widget/NumberPicker.java
+++ b/core/java/com/android/internal/widget/NumberPicker.java
@@ -36,7 +36,7 @@
 
 public class NumberPicker extends LinearLayout implements OnClickListener,
         OnFocusChangeListener, OnLongClickListener {
-        
+
     public interface OnChangedListener {
         void onChanged(NumberPicker picker, int oldVal, int newVal);
     }
@@ -51,7 +51,7 @@
      * most efficient way to do this; it avoids creating temporary objects
      * on every call to format().
      */
-    public static final NumberPicker.Formatter TWO_DIGIT_FORMATTER = 
+    public static final NumberPicker.Formatter TWO_DIGIT_FORMATTER =
             new NumberPicker.Formatter() {
                 final StringBuilder mBuilder = new StringBuilder();
                 final java.util.Formatter mFmt = new java.util.Formatter(mBuilder);
@@ -63,7 +63,7 @@
                     return mFmt.toString();
                 }
         };
-    
+
     private final Handler mHandler;
     private final Runnable mRunnable = new Runnable() {
         public void run() {
@@ -81,21 +81,21 @@
     private final InputFilter mNumberInputFilter;
 
     private String[] mDisplayedValues;
-    private int mStart;
-    private int mEnd;
-    private int mCurrent;
-    private int mPrevious;
+    protected int mStart;
+    protected int mEnd;
+    protected int mCurrent;
+    protected int mPrevious;
     private OnChangedListener mListener;
     private Formatter mFormatter;
     private long mSpeed = 300;
-    
+
     private boolean mIncrement;
     private boolean mDecrement;
-    
+
     public NumberPicker(Context context) {
         this(context, null);
     }
-    
+
     public NumberPicker(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
@@ -117,7 +117,7 @@
         mDecrementButton.setOnClickListener(this);
         mDecrementButton.setOnLongClickListener(this);
         mDecrementButton.setNumberPicker(this);
-        
+
         mText = (EditText) findViewById(R.id.timepicker_input);
         mText.setOnFocusChangeListener(this);
         mText.setFilters(new InputFilter[] {inputFilter});
@@ -127,7 +127,7 @@
             setEnabled(false);
         }
     }
-    
+
     @Override
     public void setEnabled(boolean enabled) {
         super.setEnabled(enabled);
@@ -135,19 +135,19 @@
         mDecrementButton.setEnabled(enabled);
         mText.setEnabled(enabled);
     }
-    
+
     public void setOnChangeListener(OnChangedListener listener) {
         mListener = listener;
     }
-    
+
     public void setFormatter(Formatter formatter) {
         mFormatter = formatter;
     }
-    
+
     /**
      * Set the range of numbers allowed for the number picker. The current
      * value will be automatically set to the start.
-     * 
+     *
      * @param start the start of the range (inclusive)
      * @param end the end of the range (inclusive)
      */
@@ -157,12 +157,12 @@
         mCurrent = start;
         updateView();
     }
-    
+
     /**
      * Set the range of numbers allowed for the number picker. The current
      * value will be automatically set to the start. Also provide a mapping
      * for values used to display to the user.
-     * 
+     *
      * @param start the start of the range (inclusive)
      * @param end the end of the range (inclusive)
      * @param displayedValues the values displayed to the user.
@@ -174,7 +174,7 @@
         mCurrent = start;
         updateView();
     }
-    
+
     public void setCurrent(int current) {
         mCurrent = current;
         updateView();
@@ -187,7 +187,7 @@
     public void setSpeed(long speed) {
         mSpeed = speed;
     }
-    
+
     public void onClick(View v) {
         validateInput(mText);
         if (!mText.hasFocus()) mText.requestFocus();
@@ -199,15 +199,15 @@
             changeCurrent(mCurrent - 1);
         }
     }
-    
+
     private String formatNumber(int value) {
         return (mFormatter != null)
                 ? mFormatter.toString(value)
                 : String.valueOf(value);
     }
- 
-    private void changeCurrent(int current) {
-        
+
+    protected void changeCurrent(int current) {
+
         // Wrap around the values if we go past the start or end
         if (current > mEnd) {
             current = mStart;
@@ -219,15 +219,15 @@
         notifyChange();
         updateView();
     }
-    
-    private void notifyChange() {
+
+    protected void notifyChange() {
         if (mListener != null) {
             mListener.onChanged(this, mPrevious, mCurrent);
         }
     }
 
-    private void updateView() {
-        
+    protected void updateView() {
+
         /* If we don't have displayed values then use the
          * current number else find the correct value in the
          * displayed values for the current number.
@@ -239,7 +239,7 @@
         }
         mText.setSelection(mText.getText().length());
     }
-    
+
     private void validateCurrentView(CharSequence str) {
         int val = getSelectedPos(str.toString());
         if ((val >= mStart) && (val <= mEnd)) {
@@ -253,7 +253,7 @@
     }
 
     public void onFocusChange(View v, boolean hasFocus) {
-        
+
         /* When focus is lost check that the text field
          * has valid values.
          */
@@ -280,12 +280,12 @@
      * to inform us when the long click has ended.
      */
     public boolean onLongClick(View v) {
-        
+
         /* The text view may still have focus so clear it's focus which will
          * trigger the on focus changed and any typed values to be pulled.
          */
         mText.clearFocus();
-        
+
         if (R.id.increment == v.getId()) {
             mIncrement = true;
             mHandler.post(mRunnable);
@@ -295,22 +295,22 @@
         }
         return true;
     }
-    
+
     public void cancelIncrement() {
         mIncrement = false;
     }
-    
+
     public void cancelDecrement() {
         mDecrement = false;
     }
-    
+
     private static final char[] DIGIT_CHARACTERS = new char[] {
         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
     };
-    
+
     private NumberPickerButton mIncrementButton;
     private NumberPickerButton mDecrementButton;
-    
+
     private class NumberPickerInputFilter implements InputFilter {
         public CharSequence filter(CharSequence source, int start, int end,
                 Spanned dest, int dstart, int dend) {
@@ -331,7 +331,7 @@
             return "";
         }
     }
-    
+
     private class NumberRangeKeyListener extends NumberKeyListener {
 
         // XXX This doesn't allow for range limits when controlled by a
@@ -339,12 +339,12 @@
         public int getInputType() {
             return InputType.TYPE_CLASS_NUMBER;
         }
-        
+
         @Override
         protected char[] getAcceptedChars() {
             return DIGIT_CHARACTERS;
         }
-        
+
         @Override
         public CharSequence filter(CharSequence source, int start, int end,
                 Spanned dest, int dstart, int dend) {
@@ -381,21 +381,21 @@
             return Integer.parseInt(str);
         } else {
             for (int i = 0; i < mDisplayedValues.length; i++) {
-                
+
                 /* Don't force the user to type in jan when ja will do */
                 str = str.toLowerCase();
                 if (mDisplayedValues[i].toLowerCase().startsWith(str)) {
                     return mStart + i;
                 }
             }
-            
+
             /* The user might have typed in a number into the month field i.e.
              * 10 instead of OCT so support that too.
              */
             try {
                 return Integer.parseInt(str);
             } catch (NumberFormatException e) {
-                
+
                 /* Ignore as if it's not a number we don't care */
             }
         }
diff --git a/include/media/stagefright/AMRExtractor.h b/include/media/stagefright/AMRExtractor.h
new file mode 100644
index 0000000..c8710d3
--- /dev/null
+++ b/include/media/stagefright/AMRExtractor.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AMR_EXTRACTOR_H_
+
+#define AMR_EXTRACTOR_H_
+
+#include <media/stagefright/MediaExtractor.h>
+
+namespace android {
+
+class String8;
+
+class AMRExtractor : public MediaExtractor {
+public:
+    AMRExtractor(const sp<DataSource> &source);
+
+    virtual size_t countTracks();
+    virtual sp<MediaSource> getTrack(size_t index);
+    virtual sp<MetaData> getTrackMetaData(size_t index);
+
+    static sp<MetaData> makeAMRFormat(bool isWide);
+
+protected:
+    virtual ~AMRExtractor();
+
+private:
+    sp<DataSource> mDataSource;
+    status_t mInitCheck;
+    bool mIsWide;
+
+    AMRExtractor(const AMRExtractor &);
+    AMRExtractor &operator=(const AMRExtractor &);
+};
+
+bool SniffAMR(
+        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+
+}  // namespace android
+
+#endif  // AMR_EXTRACTOR_H_
diff --git a/include/media/stagefright/MP3Extractor.h b/include/media/stagefright/MP3Extractor.h
index 4e1f3c3..11ba01d 100644
--- a/include/media/stagefright/MP3Extractor.h
+++ b/include/media/stagefright/MP3Extractor.h
@@ -30,9 +30,9 @@
     // Extractor assumes ownership of "source".
     MP3Extractor(const sp<DataSource> &source);
 
-    size_t countTracks();
-    sp<MediaSource> getTrack(size_t index);
-    sp<MetaData> getTrackMetaData(size_t index);
+    virtual size_t countTracks();
+    virtual sp<MediaSource> getTrack(size_t index);
+    virtual sp<MetaData> getTrackMetaData(size_t index);
 
 protected:
     virtual ~MP3Extractor();
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index ac45481..7f99553 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -138,6 +138,7 @@
     void setComponentRole();
 
     void setAMRFormat();
+    void setAMRWBFormat();
     void setAACFormat(int32_t numChannels, int32_t sampleRate);
 
     status_t setVideoPortFormatType(
diff --git a/keystore/jni/cert.c b/keystore/jni/cert.c
index 91114d6..90f872e 100644
--- a/keystore/jni/cert.c
+++ b/keystore/jni/cert.c
@@ -18,7 +18,6 @@
 #define LOG_TAG "CertTool"
 
 #include <stdio.h>
-#include <openssl/engine.h>
 #include <openssl/pem.h>
 #include <openssl/pkcs12.h>
 #include <openssl/rsa.h>
diff --git a/libs/rs/java/Fall/Android.mk b/libs/rs/java/Fall/Android.mk
deleted file mode 100644
index 6366f63..0000000
--- a/libs/rs/java/Fall/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Copyright (C) 2009 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
-
-LOCAL_PACKAGE_NAME := FallRS
-
-include $(BUILD_PACKAGE)
diff --git a/libs/rs/java/Fall/AndroidManifest.xml b/libs/rs/java/Fall/AndroidManifest.xml
deleted file mode 100644
index f646d0d..0000000
--- a/libs/rs/java/Fall/AndroidManifest.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.fall.rs">
-
-    <application android:label="FallRS">
-
-        <activity
-            android:screenOrientation="portrait"
-            android:name="Fall"
-            android:theme="@android:style/Theme.NoTitleBar">
-
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-
-        </activity>
-
-    </application>
-
-</manifest>
diff --git a/libs/rs/java/Fall/res/drawable-hdpi/leaves.png b/libs/rs/java/Fall/res/drawable-hdpi/leaves.png
deleted file mode 100644
index 9eddd66..0000000
--- a/libs/rs/java/Fall/res/drawable-hdpi/leaves.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Fall/res/drawable-hdpi/riverbed.jpg b/libs/rs/java/Fall/res/drawable-hdpi/riverbed.jpg
deleted file mode 100644
index 1698f28..0000000
--- a/libs/rs/java/Fall/res/drawable-hdpi/riverbed.jpg
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Fall/res/drawable-hdpi/sky.jpg b/libs/rs/java/Fall/res/drawable-hdpi/sky.jpg
deleted file mode 100644
index 565a63b..0000000
--- a/libs/rs/java/Fall/res/drawable-hdpi/sky.jpg
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Fall/res/raw/fall.c b/libs/rs/java/Fall/res/raw/fall.c
deleted file mode 100644
index e04e1ff..0000000
--- a/libs/rs/java/Fall/res/raw/fall.c
+++ /dev/null
@@ -1,478 +0,0 @@
-// Copyright (C) 2009 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.
-
-#pragma version(1)
-#pragma stateVertex(PVSky)
-#pragma stateFragment(PFBackground)
-#pragma stateFragmentStore(PFSBackground)
-
-#define RSID_STATE 0
-#define RSID_RIPPLE_MAP 1
-#define RSID_REFRACTION_MAP 2
-#define RSID_LEAVES 3
-#define RSID_DROP 4
-
-#define LEAF_STRUCT_FIELDS_COUNT 11
-#define LEAF_STRUCT_X 0
-#define LEAF_STRUCT_Y 1
-#define LEAF_STRUCT_SCALE 2
-#define LEAF_STRUCT_ANGLE 3
-#define LEAF_STRUCT_SPIN 4
-#define LEAF_STRUCT_U1 5
-#define LEAF_STRUCT_U2 6
-#define LEAF_STRUCT_ALTITUDE 7
-#define LEAF_STRUCT_RIPPLED 8
-#define LEAF_STRUCT_DELTAX 9
-#define LEAF_STRUCT_DELTAY 10
-
-#define LEAVES_TEXTURES_COUNT 4
-
-#define LEAF_SIZE 0.55f
-
-#define REFRACTION 1.333f
-#define DAMP 3
-
-#define DROP_RADIUS 2
-// The higher, the smaller the ripple
-#define RIPPLE_HEIGHT 10.0f
-
-float g_SkyOffsetX;
-float g_SkyOffsetY;
-
-struct vert_s {
-    float nx;
-    float ny;
-    float nz;
-    float s;
-    float t;
-    float x;
-    float y;
-    float z;
-};
-
-int offset(int x, int y, int width) {
-    return x + 1 + (y + 1) * (width + 2);
-}
-
-void dropWithStrength(int x, int y, int r, int s) {
-    int width = State->meshWidth;
-    int height = State->meshHeight;
-
-    if (x < r) x = r;
-    if (y < r) y = r;
-    if (x >= width - r) x = width - r - 1;
-    if (y >= height - r) y = height - r - 1;
-
-    x = width - x;
-
-    int rippleMapSize = State->rippleMapSize;
-    int index = State->rippleIndex;
-    int origin = offset(0, 0, width);
-
-    int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin);
-    int sqr = r * r;
-    float invs = 1.0f / s;
-
-    int h = 0;
-    for ( ; h < r; h += 1) {
-        int sqv = h * h;
-        int yn = origin + (y - h) * (width + 2);
-        int yp = origin + (y + h) * (width + 2);
-        int w = 0;
-        for ( ; w < r; w += 1) {
-            int squ = w * w;
-            if (squ + sqv < sqr) {
-                int v = -sqrtf((sqr - (squ + sqv)) << 16) * invs;
-                current[yn + x + w] = v;
-                current[yp + x + w] = v;
-                current[yn + x - w] = v;
-                current[yp + x - w] = v;
-            }
-        }
-    }
-}
-
-void drop(int x, int y, int r) {
-    dropWithStrength(x, y, r, 1);
-}
-
-void updateRipples() {
-    int rippleMapSize = State->rippleMapSize;
-    int width = State->meshWidth;
-    int height = State->meshHeight;
-    int index = State->rippleIndex;
-    int origin = offset(0, 0, width);
-
-    int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin);
-    int* next = loadArrayI32(RSID_RIPPLE_MAP, (1 - index) * rippleMapSize + origin);
-
-    storeI32(RSID_STATE, OFFSETOF_WorldState_rippleIndex, 1 - index);
-
-    int a = 1;
-    int b = width + 2;
-    int h = height;
-    while (h) {
-        int w = width;
-        while (w) {
-            int droplet = ((current[-b] + current[b] + current[-a] + current[a]) >> 1) - *next;
-            droplet -= (droplet >> DAMP);
-            *next = droplet;
-            current += 1;
-            next += 1;
-            w -= 1;
-        }
-        current += 2;
-        next += 2;
-        h -= 1;
-    }
-}
-
-int refraction(int d, int wave, int *map) {
-    int i = d;
-    if (i < 0) i = -i;
-    if (i > 512) i = 512;
-    int w = (wave + 0x10000) >> 8;
-    w &= ~(w >> 31);
-    int r = (map[i] * w) >> 3;
-    if (d < 0) {
-        return -r;
-    }
-    return r;
-}
-
-void generateRipples() {
-    int rippleMapSize = loadI32(RSID_STATE, OFFSETOF_WorldState_rippleMapSize);
-    int width = State->meshWidth;
-    int height = State->meshHeight;
-    int index = State->rippleIndex;
-    int origin = offset(0, 0, width);
-
-    int b = width + 2;
-
-    int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin);
-    int *map = loadArrayI32(RSID_REFRACTION_MAP, 0);
-    float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
-    struct vert_s *vert = (struct vert_s *)vertices;
-
-    float fw = 1.f / width;
-    float fh = 1.f / height;
-    float fy = (1.0f / 512.0f) * (1.0f / RIPPLE_HEIGHT);
-
-    int h = height - 1;
-    while (h >= 0) {
-        int w = width - 1;
-        int wave = *current;
-        int offset = h * width;
-        struct vert_s *vtx = vert + offset + w;
-
-        while (w >= 0) {
-            int nextWave = current[1];
-            int dx = nextWave - wave;
-            int dy = current[b] - wave;
-
-            int offsetx = refraction(dx, wave, map) >> 16;
-            int u = (width - w) + offsetx;
-            u &= ~(u >> 31);
-            if (u >= width) u = width - 1;
-
-            int offsety = refraction(dy, wave, map) >> 16;
-            int v = (height - h) + offsety;
-            v &= ~(v >> 31);
-            if (v >= height) v = height - 1;
-
-            vtx->s = u * fw;
-            vtx->t = v * fh;
-            vtx->z = dy * fy;
-            vtx --;
-
-            w -= 1;
-            current += 1;
-            wave = nextWave;
-        }
-        h -= 1;
-        current += 2;
-    }
-
-    // Compute the normals for lighting
-    int y = 0;
-    for ( ; y < height; y += 1) {
-        int x = 0;
-        int yOffset = y * width;
-        struct vert_s *v = vert;
-
-        for ( ; x < width; x += 1) {
-            struct vec3_s n1, n2, n3;
-            vec3Sub(&n1, (struct vec3_s *)&(v+1)->x, (struct vec3_s *)&v->x);
-            vec3Sub(&n2, (struct vec3_s *)&(v+width)->x, (struct vec3_s *)&v->x);
-            vec3Cross(&n3, &n1, &n2);
-            vec3Norm(&n3);
-
-            // Average of previous normal and N1 x N2
-            vec3Sub(&n1, (struct vec3_s *)&(v+width+1)->x, (struct vec3_s *)&v->x);
-            vec3Cross(&n2, &n1, &n2);
-            vec3Add(&n3, &n3, &n2);
-            vec3Norm(&n3);
-
-            v->nx = n3.x;
-            v->ny = n3.y;
-            v->nz = -n3.z;
-            v += 1;
-
-            // reset Z
-            //vertices[(yOffset + x) << 3 + 7] = 0.0f;
-        }
-    }
-}
-
-float averageZ(float x1, float x2, float y1, float y2, float* vertices,
-        int meshWidth, int meshHeight, float glWidth, float glHeight) {
-
-    x1 = ((x1 + glWidth * 0.5f) / glWidth) * meshWidth;
-    x2 = ((x2 + glWidth * 0.5f) / glWidth) * meshWidth;
-    y1 = ((y1 + glHeight * 0.5f) / glHeight) * meshHeight;
-    y2 = ((y2 + glHeight * 0.5f) / glHeight) * meshHeight;
-
-    int quadX1 = clamp(x1, 0, meshWidth);
-    int quadX2 = clamp(x2, 0, meshWidth);
-    int quadY1 = clamp(y1, 0, meshHeight);
-    int quadY2 = clamp(y2, 0, meshHeight);
-
-    float z = 0.0f;
-    int vertexCount = 0;
-
-    int y = quadY1;
-    for ( ; y < quadY2; y += 1) {
-        int x = quadX1;
-        int yOffset = y * meshWidth;
-        for ( ; x < quadX2; x += 1) {
-            z += vertices[(yOffset + x) << 3 + 7];
-            vertexCount += 1;
-        }
-    }
-
-    return 55.0f * z / vertexCount;
-}
-
-void drawLeaf(int index, float* vertices, int meshWidth, int meshHeight,
-        float glWidth, float glHeight) {
-
-    float *leafStruct = loadArrayF(RSID_LEAVES, index);
-
-    float x = leafStruct[LEAF_STRUCT_X];
-    float x1 = x - LEAF_SIZE;
-    float x2 = x + LEAF_SIZE;
-
-    float y = leafStruct[LEAF_STRUCT_Y];
-    float y1 = y - LEAF_SIZE;
-    float y2 = y + LEAF_SIZE;
-
-    float u1 = leafStruct[LEAF_STRUCT_U1];
-    float u2 = leafStruct[LEAF_STRUCT_U2];
-
-    float z1 = 0.0f;
-    float z2 = 0.0f;
-    float z3 = 0.0f;
-    float z4 = 0.0f;
-
-    float a = leafStruct[LEAF_STRUCT_ALTITUDE];
-    float s = leafStruct[LEAF_STRUCT_SCALE];
-    float r = leafStruct[LEAF_STRUCT_ANGLE];
-
-    float tz = 0.0f;
-    if (a > 0.0f) {
-        tz = -a;
-    } else {
-//        z1 = averageZ(x1, x, y1, y, vertices, meshWidth, meshHeight, glWidth, glHeight);
-//        z2 = averageZ(x, x2, y1, y, vertices, meshWidth, meshHeight, glWidth, glHeight);
-//        z3 = averageZ(x, x2, y, y2, vertices, meshWidth, meshHeight, glWidth, glHeight);
-//        z4 = averageZ(x1, x, y, y2, vertices, meshWidth, meshHeight, glWidth, glHeight);
-    }
-
-    x1 -= x;
-    x2 -= x;
-    y1 -= y;
-    y2 -= y;
-
-    float matrix[16];
-    matrixLoadIdentity(matrix);
-    matrixTranslate(matrix, x, y, tz);
-    matrixScale(matrix, s, s, 1.0f);
-    matrixRotate(matrix, r, 0.0f, 0.0f, 1.0f);
-    vpLoadModelMatrix(matrix);
-
-    drawQuadTexCoords(x1, y1, z1, u1, 1.0f,
-                      x2, y1, z2, u2, 1.0f,
-                      x2, y2, z3, u2, 0.0f,
-                      x1, y2, z4, u1, 0.0f);
-
-    float spin = leafStruct[LEAF_STRUCT_SPIN];
-    if (a <= 0.0f) {
-        float rippled = leafStruct[LEAF_STRUCT_RIPPLED];
-        if (rippled < 0.0f) {
-            drop(((x + glWidth * 0.5f) / glWidth) * meshWidth,
-                 meshHeight - ((y + glHeight * 0.5f) / glHeight) * meshHeight,
-                 DROP_RADIUS);
-            spin /= 4.0f;
-            leafStruct[LEAF_STRUCT_SPIN] = spin;
-            leafStruct[LEAF_STRUCT_RIPPLED] = 1.0f;
-        } else {
-//            dropWithStrength(((x + glWidth / 2.0f) / glWidth) * meshWidth,
-//                meshHeight - ((y + glHeight / 2.0f) / glHeight) * meshHeight,
-//                2, 5);
-        }
-        leafStruct[LEAF_STRUCT_X] = x + leafStruct[LEAF_STRUCT_DELTAX];
-        leafStruct[LEAF_STRUCT_Y] = y + leafStruct[LEAF_STRUCT_DELTAY];
-        r += spin;
-        leafStruct[LEAF_STRUCT_ANGLE] = r;
-    } else {
-        a -= 0.005f;
-        leafStruct[LEAF_STRUCT_ALTITUDE] = a;
-        r += spin * 2.0f;
-        leafStruct[LEAF_STRUCT_ANGLE] = r;
-    }
-
-    if (-LEAF_SIZE * s + x > glWidth / 2.0f || LEAF_SIZE * s + x < -glWidth / 2.0f ||
-        LEAF_SIZE * s + y < -glHeight / 2.0f) {
-
-        int sprite = randf(LEAVES_TEXTURES_COUNT);
-        leafStruct[LEAF_STRUCT_X] = randf2(-1.0f, 1.0f);
-        leafStruct[LEAF_STRUCT_Y] = glHeight / 2.0f + LEAF_SIZE * 2 * randf(1.0f);
-        leafStruct[LEAF_STRUCT_SCALE] = randf2(0.4f, 0.5f);
-        leafStruct[LEAF_STRUCT_SPIN] = degf(randf2(-0.02f, 0.02f)) / 4.0f;
-        leafStruct[LEAF_STRUCT_U1] = sprite / (float) LEAVES_TEXTURES_COUNT;
-        leafStruct[LEAF_STRUCT_U2] = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
-        leafStruct[LEAF_STRUCT_DELTAX] = randf2(-0.02f, 0.02f) / 60.0f;
-        leafStruct[LEAF_STRUCT_DELTAY] = -0.08f * randf2(0.9f, 1.1f) / 60.0f;
-    }
-}
-
-void drawLeaves() {
-    bindProgramFragment(NAMED_PFBackground);
-    bindProgramFragmentStore(NAMED_PFSLeaf);
-    bindProgramVertex(NAMED_PVSky);
-    bindTexture(NAMED_PFBackground, 0, NAMED_TLeaves);
-
-    int leavesCount = State->leavesCount;
-    int count = leavesCount * LEAF_STRUCT_FIELDS_COUNT;
-    int width = State->meshWidth;
-    int height = State->meshHeight;
-    float glWidth = State->glWidth;
-    float glHeight = State->glHeight;
-
-    float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
-
-    int i = 0;
-    for ( ; i < count; i += LEAF_STRUCT_FIELDS_COUNT) {
-        drawLeaf(i, vertices, width, height, glWidth, glHeight);
-    }
-
-    float matrix[16];
-    matrixLoadIdentity(matrix);
-    vpLoadModelMatrix(matrix);
-}
-
-void drawRiverbed() {
-    bindTexture(NAMED_PFBackground, 0, NAMED_TRiverbed);
-
-    drawTriangleMesh(NAMED_WaterMesh);
-}
-
-void drawSky() {
-    color(1.0f, 1.0f, 1.0f, 0.8f);
-
-    bindProgramFragment(NAMED_PFSky);
-    bindProgramFragmentStore(NAMED_PFSLeaf);
-    bindTexture(NAMED_PFSky, 0, NAMED_TSky);
-
-    float x = g_SkyOffsetX + State->skySpeedX;
-    float y = g_SkyOffsetY + State->skySpeedY;
-
-    if (x > 1.0f) x = 0.0f;
-    if (x < -1.0f) x = 0.0f;
-    if (y > 1.0f) y = 0.0f;
-
-    g_SkyOffsetX = x;
-    g_SkyOffsetY = y;
-
-    float matrix[16];
-    matrixLoadTranslate(matrix, x, y, 0.0f);
-    vpLoadTextureMatrix(matrix);
-
-    drawTriangleMesh(NAMED_WaterMesh);
-
-    matrixLoadIdentity(matrix);
-    vpLoadTextureMatrix(matrix);
-}
-
-void drawLighting() {
-    ambient(0.0f, 0.0f, 0.0f, 1.0f);
-    diffuse(0.0f, 0.0f, 0.0f, 1.0f);
-    specular(0.44f, 0.44f, 0.44f, 1.0f);
-    shininess(40.0f);
-
-    bindProgramFragmentStore(NAMED_PFSBackground);
-    bindProgramFragment(NAMED_PFLighting);
-    bindProgramVertex(NAMED_PVLight);
-
-    drawTriangleMesh(NAMED_WaterMesh);
-}
-
-void drawNormals() {
-    int width = State->meshWidth;
-    int height = State->meshHeight;
-
-    float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
-
-    bindProgramVertex(NAMED_PVSky);
-    bindProgramFragment(NAMED_PFLighting);
-
-    color(1.0f, 0.0f, 0.0f, 1.0f);
-
-    float scale = 1.0f / 10.0f;
-    int y = 0;
-    for ( ; y < height; y += 1) {
-        int yOffset = y * width;
-        int x = 0;
-        for ( ; x < width; x += 1) {
-            int offset = (yOffset + x) << 3;
-            float vx = vertices[offset + 5];
-            float vy = vertices[offset + 6];
-            float vz = vertices[offset + 7];
-            float nx = vertices[offset + 0];
-            float ny = vertices[offset + 1];
-            float nz = vertices[offset + 2];
-            drawLine(vx, vy, vz, vx + nx * scale, vy + ny * scale, vz + nz * scale);
-        }
-    }
-}
-
-int main(int index) {
-    if (Drop->dropX != -1) {
-        drop(Drop->dropX, Drop->dropY, DROP_RADIUS);
-        Drop->dropX = -1;
-        Drop->dropY = -1;
-    }
-
-    updateRipples();
-    generateRipples();
-    updateTriangleMesh(NAMED_WaterMesh);
-
-    drawRiverbed();
-    drawSky();
-    drawLighting();
-    drawLeaves();
-    //drawNormals();
-
-    return 1;
-}
diff --git a/libs/rs/java/Fall/src/com/android/fall/rs/Fall.java b/libs/rs/java/Fall/src/com/android/fall/rs/Fall.java
deleted file mode 100644
index b1d9b1d..0000000
--- a/libs/rs/java/Fall/src/com/android/fall/rs/Fall.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2009 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.fall.rs;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class Fall extends Activity {
-    private FallView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        mView = new FallView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        mView.onResume();
-    }
-
-    @Override
-    protected void onPause() {
-        super.onPause();
-        mView.onPause();
-
-        Runtime.getRuntime().exit(0);
-    }
-}
diff --git a/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java b/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java
deleted file mode 100644
index 33aa9ab..0000000
--- a/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Copyright (C) 2009 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.fall.rs;
-
-import android.content.res.Resources;
-import android.renderscript.RenderScript;
-import android.renderscript.ScriptC;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.Allocation;
-import android.renderscript.Sampler;
-import android.renderscript.Element;
-import android.renderscript.Light;
-import android.renderscript.Type;
-import static android.renderscript.Sampler.Value.LINEAR;
-import static android.renderscript.Sampler.Value.WRAP;
-import static android.renderscript.ProgramStore.DepthFunc.*;
-import static android.renderscript.ProgramStore.BlendDstFunc;
-import static android.renderscript.ProgramStore.BlendSrcFunc;
-import static android.renderscript.ProgramFragment.EnvMode.*;
-import static android.renderscript.Element.*;
-import android.graphics.BitmapFactory;
-import android.graphics.Bitmap;
-import static android.util.MathUtils.*;
-
-import java.util.TimeZone;
-
-class FallRS {
-    private static final int MESH_RESOLUTION = 48;
-
-    private static final int RSID_STATE = 0;
-
-    private static final int TEXTURES_COUNT = 3;
-    private static final int LEAVES_TEXTURES_COUNT = 4;
-    private static final int RSID_TEXTURE_RIVERBED = 0;
-    private static final int RSID_TEXTURE_LEAVES = 1;
-    private static final int RSID_TEXTURE_SKY = 2;
-
-    private static final int RSID_RIPPLE_MAP = 1;
-
-    private static final int RSID_REFRACTION_MAP = 2;
-
-    private static final int RSID_LEAVES = 3;
-    private static final int LEAVES_COUNT = 14;
-    private static final int LEAF_STRUCT_FIELDS_COUNT = 11;
-    private static final int LEAF_STRUCT_X = 0;
-    private static final int LEAF_STRUCT_Y = 1;
-    private static final int LEAF_STRUCT_SCALE = 2;
-    private static final int LEAF_STRUCT_ANGLE = 3;
-    private static final int LEAF_STRUCT_SPIN = 4;
-    private static final int LEAF_STRUCT_U1 = 5;
-    private static final int LEAF_STRUCT_U2 = 6;
-    private static final int LEAF_STRUCT_ALTITUDE = 7;
-    private static final int LEAF_STRUCT_RIPPLED = 8;
-    private static final int LEAF_STRUCT_DELTAX = 9;
-    private static final int LEAF_STRUCT_DELTAY = 10;
-
-    class Leaf {
-        float x;
-        float y;
-        float scale;
-        float angle;
-        float spin;
-        float u1;
-        float u2;
-        float altitude;
-        float rippled;
-        float deltaX;
-        float deltaY;
-    }
-
-    private static final int RSID_DROP = 4;
-
-    private Resources mResources;
-    private RenderScript mRS;
-
-    private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
-    private final int mWidth;
-    private final int mHeight;
-
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramFragment mPfBackground;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramFragment mPfLighting;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramFragment mPfSky;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramStore mPfsBackground;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramStore mPfsLeaf;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramVertex mPvLight;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private ProgramVertex mPvSky;
-
-    private Allocation mState;
-    private Allocation mDropState;
-    private DropState mDrop;
-    private Type mStateType;
-    private Type mDropType;
-    private int mMeshWidth;
-
-    private int mMeshHeight;
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private RenderScript.TriangleMesh mMesh;
-
-    private Allocation mRippleMap;
-    private Allocation mRefractionMap;
-
-    private Allocation mLeaves;
-    private float mGlHeight;
-
-    public FallRS(int width, int height) {
-        mWidth = width;
-        mHeight = height;
-        mOptionsARGB.inScaled = false;
-        mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
-    }
-
-    public void init(RenderScript rs, Resources res) {
-        mRS = rs;
-        mResources = res;
-        initRS();
-    }
-
-    private void initRS() {
-        createProgramVertex();
-        createProgramFragmentStore();
-        createProgramFragment();
-        createMesh();
-        createScriptStructures();
-        loadTextures();
-
-        ScriptC.Builder sb = new ScriptC.Builder(mRS);
-        sb.setType(mStateType, "State", RSID_STATE);
-        sb.setType(mDropType, "Drop", RSID_DROP);
-        sb.setScript(mResources, R.raw.fall);
-        sb.setRoot(true);
-
-        ScriptC script = sb.create();
-        script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-        script.setTimeZone(TimeZone.getDefault().getID());
-
-        script.bindAllocation(mState, RSID_STATE);
-        script.bindAllocation(mRippleMap, RSID_RIPPLE_MAP);
-        script.bindAllocation(mRefractionMap, RSID_REFRACTION_MAP);
-        script.bindAllocation(mLeaves, RSID_LEAVES);
-        script.bindAllocation(mDropState, RSID_DROP);
-
-        mRS.contextBindRootScript(script);
-    }
-
-    private void createMesh() {
-        final RenderScript rs = mRS;
-        rs.triangleMeshBegin(Element.NORM_ST_XYZ_F32, Element.INDEX_16);
-
-        int wResolution;
-        int hResolution;
-
-        final int width = mWidth;
-        final int height = mHeight;
-
-        if (width < height) {
-            wResolution = MESH_RESOLUTION;
-            hResolution = (int) (MESH_RESOLUTION * height / (float) width);
-        } else {
-            wResolution = (int) (MESH_RESOLUTION * width / (float) height);
-            hResolution = MESH_RESOLUTION;
-        }
-
-        mGlHeight = 2.0f * height / (float) width;
-        final float glHeight = mGlHeight;
-
-        float quadWidth = 2.0f / (float) wResolution;
-        float quadHeight = glHeight / (float) hResolution;
-
-        wResolution += 2;
-        hResolution += 2;
-
-        for (int y = 0; y <= hResolution; y++) {
-            final boolean shift = (y & 0x1) == 0;
-            final float yOffset = y * quadHeight - glHeight / 2.0f - quadHeight;
-            final float t = 1.0f - y / (float) hResolution;
-            for (int x = 0; x <= wResolution; x++) {
-                if (shift) {
-                    rs.triangleMeshAddVertex_XYZ_ST_NORM(
-                            -1.0f + x * quadWidth - quadWidth, yOffset, 0.0f,
-                            x / (float) wResolution, t,
-                            0.0f, 0.0f, -1.0f);
-                } else {
-                    rs.triangleMeshAddVertex_XYZ_ST_NORM(
-                            -1.0f + x * quadWidth - quadWidth * 0.5f, yOffset, 0.0f,
-                            x / (float) wResolution, t,
-                            0.0f, 0.0f, -1.0f);
-                }
-            }
-        }
-
-        for (int y = 0; y < hResolution; y++) {
-            final boolean shift = (y & 0x1) == 0;
-            final int yOffset = y * (wResolution + 1);
-            for (int x = 0; x < wResolution; x++) {
-                final int index = yOffset + x;
-                final int iWR1 = index + wResolution + 1;
-                if (shift) {
-                    rs.triangleMeshAddTriangle(index, index + 1, iWR1);
-                    rs.triangleMeshAddTriangle(index + 1, iWR1 + 1, iWR1);
-                } else {
-                    rs.triangleMeshAddTriangle(index, iWR1 + 1, iWR1);
-                    rs.triangleMeshAddTriangle(index, index + 1, iWR1 + 1);
-                }
-            }
-        }
-
-        mMesh = rs.triangleMeshCreate();
-        mMesh.setName("WaterMesh");
-
-        mMeshWidth = wResolution + 1;
-        mMeshHeight = hResolution + 1;
-    }
-
-    private void createScriptStructures() {
-        final int rippleMapSize = (mMeshWidth + 2) * (mMeshHeight + 2);
-
-        createState(rippleMapSize);
-        createRippleMap(rippleMapSize);
-        createRefractionMap();
-        createLeaves();
-    }
-
-    private void createLeaves() {
-        final float[] leaves = new float[LEAVES_COUNT * LEAF_STRUCT_FIELDS_COUNT];
-        mLeaves = Allocation.createSized(mRS, USER_FLOAT, leaves.length);
-        for (int i = 0; i < leaves.length; i += LEAF_STRUCT_FIELDS_COUNT) {
-            createLeaf(leaves, i);
-        }
-        mLeaves.data(leaves);
-    }
-
-    private void createRefractionMap() {
-        final int[] refractionMap = new int[513];
-        float ir = 1.0f / 1.333f;
-        for (int i = 0; i < refractionMap.length; i++) {
-            float d = (float) Math.tan(Math.asin(Math.sin(Math.atan(i * (1.0f / 256.0f))) * ir));
-            refractionMap[i] = (int) Math.floor(d * (1 << 16) + 0.5f);
-        }
-        mRefractionMap = Allocation.createSized(mRS, USER_I32, refractionMap.length);
-        mRefractionMap.data(refractionMap);
-    }
-
-    private void createRippleMap(int rippleMapSize) {
-        final int[] rippleMap = new int[rippleMapSize * 2];
-        mRippleMap = Allocation.createSized(mRS, USER_I32, rippleMap.length);
-        mRippleMap.data(rippleMap);
-    }
-
-    static class WorldState {
-        public int frameCount;
-        public int width;
-        public int height;
-        public int meshWidth;
-        public int meshHeight;
-        public int rippleMapSize;
-        public int rippleIndex;
-        public int leavesCount;
-        public float glWidth;
-        public float glHeight;
-        public float skySpeedX;
-        public float skySpeedY;
-    }
-
-    static class DropState {
-        public int dropX;
-        public int dropY;
-    }
-
-    private void createState(int rippleMapSize) {
-        WorldState worldState = new WorldState();
-        worldState.width = mWidth;
-        worldState.height = mHeight;
-        worldState.meshWidth = mMeshWidth;
-        worldState.meshHeight = mMeshHeight;
-        worldState.rippleMapSize = rippleMapSize;
-        worldState.rippleIndex = 0;
-        worldState.leavesCount = LEAVES_COUNT;
-        worldState.glWidth = 2.0f;
-        worldState.glHeight = mGlHeight;
-        worldState.skySpeedX = random(-0.001f, 0.001f);
-        worldState.skySpeedY = random(0.00008f, 0.0002f);
-
-        mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
-        mState = Allocation.createTyped(mRS, mStateType);
-        mState.data(worldState);
-
-        mDrop = new DropState();
-        mDrop.dropX = -1;
-        mDrop.dropY = -1;
-
-        mDropType = Type.createFromClass(mRS, DropState.class, 1, "DropState");
-        mDropState = Allocation.createTyped(mRS, mDropType);
-        mDropState.data(mDrop);
-    }
-
-    private void createLeaf(float[] leaves, int index) {
-        int sprite = random(LEAVES_TEXTURES_COUNT);
-        //noinspection PointlessArithmeticExpression
-        leaves[index + LEAF_STRUCT_X] = random(-1.0f, 1.0f);
-        leaves[index + LEAF_STRUCT_Y] = random(-mGlHeight / 2.0f, mGlHeight / 2.0f);
-        leaves[index + LEAF_STRUCT_SCALE] = random(0.4f, 0.5f);
-        leaves[index + LEAF_STRUCT_ANGLE] = random(0.0f, 360.0f);
-        leaves[index + LEAF_STRUCT_SPIN] = degrees(random(-0.02f, 0.02f)) / 4.0f;
-        leaves[index + LEAF_STRUCT_U1] = sprite / (float) LEAVES_TEXTURES_COUNT;
-        leaves[index + LEAF_STRUCT_U2] = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
-        leaves[index + LEAF_STRUCT_ALTITUDE] = -1.0f;
-        leaves[index + LEAF_STRUCT_RIPPLED] = 1.0f;
-        leaves[index + LEAF_STRUCT_DELTAX] = random(-0.02f, 0.02f) / 60.0f;
-        leaves[index + LEAF_STRUCT_DELTAY] = -0.08f * random(0.9f, 1.1f) / 60.0f;
-    }
-
-    private void loadTextures() {
-        final Allocation[] textures = new Allocation[TEXTURES_COUNT];
-        textures[RSID_TEXTURE_RIVERBED] = loadTexture(R.drawable.riverbed, "TRiverbed");
-        textures[RSID_TEXTURE_LEAVES] = loadTextureARGB(R.drawable.leaves, "TLeaves");
-        textures[RSID_TEXTURE_SKY] = loadTextureARGB(R.drawable.sky, "TSky");
-
-        final int count = textures.length;
-        for (int i = 0; i < count; i++) {
-            final Allocation texture = textures[i];
-            texture.uploadToTexture(0);
-        }
-    }
-
-    private Allocation loadTexture(int id, String name) {
-        final Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources,
-                id, RGB_565, false);
-        allocation.setName(name);
-        return allocation;
-    }
-
-    private Allocation loadTextureARGB(int id, String name) {
-        Bitmap b = BitmapFactory.decodeResource(mResources, id, mOptionsARGB);
-        final Allocation allocation = Allocation.createFromBitmap(mRS, b, RGBA_8888, false);
-        allocation.setName(name);
-        return allocation;
-    }
-
-    private void createProgramFragment() {
-        Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
-        sampleBuilder.setMin(LINEAR);
-        sampleBuilder.setMag(LINEAR);
-        sampleBuilder.setWrapS(WRAP);
-        sampleBuilder.setWrapT(WRAP);
-        Sampler sampler = sampleBuilder.create();
-
-        ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
-        builder.setTexEnable(true, 0);
-        builder.setTexEnvMode(REPLACE, 0);
-        mPfBackground = builder.create();
-        mPfBackground.setName("PFBackground");
-        mPfBackground.bindSampler(sampler, 0);
-
-        builder = new ProgramFragment.Builder(mRS, null, null);
-        builder.setTexEnable(false, 0);
-        mPfLighting = builder.create();
-        mPfLighting.setName("PFLighting");
-        mPfLighting.bindSampler(sampler, 0);
-
-        builder = new ProgramFragment.Builder(mRS, null, null);
-        builder.setTexEnable(true, 0);
-        builder.setTexEnvMode(MODULATE, 0);
-        mPfSky = builder.create();
-        mPfSky.setName("PFSky");
-        mPfSky.bindSampler(sampler, 0);
-    }
-
-    private void createProgramFragmentStore() {
-        ProgramStore.Builder builder = new ProgramStore.Builder(mRS, null, null);
-        builder.setDepthFunc(ALWAYS);
-        builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
-        builder.setDitherEnable(false);
-        builder.setDepthMask(true);
-        mPfsBackground = builder.create();
-        mPfsBackground.setName("PFSBackground");
-
-        builder = new ProgramStore.Builder(mRS, null, null);
-        builder.setDepthFunc(ALWAYS);
-        builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
-        builder.setDitherEnable(false);
-        builder.setDepthMask(true);
-        mPfsLeaf = builder.create();
-        mPfsLeaf.setName("PFSLeaf");
-    }
-
-    private void createProgramVertex() {
-        ProgramVertex.MatrixAllocation pvOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS);
-        pvOrthoAlloc.setupProjectionNormalized(mWidth, mHeight);
-
-        Light light = new Light.Builder(mRS).create();
-        light.setPosition(0.0f, 2.0f, -8.0f);
-
-        ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null);
-        builder.addLight(light);
-        mPvLight = builder.create();
-        mPvLight.bindAllocation(pvOrthoAlloc);
-        mPvLight.setName("PVLight");
-
-        builder = new ProgramVertex.Builder(mRS, null, null);
-        builder.setTextureMatrixEnable(true);
-        mPvSky = builder.create();
-        mPvSky.bindAllocation(pvOrthoAlloc);
-        mPvSky.setName("PVSky");
-    }
-
-    void addDrop(float x, float y) {
-        mDrop.dropX = (int) ((x / mWidth) * mMeshWidth);
-        mDrop.dropY = (int) ((y / mHeight) * mMeshHeight);
-        mDropState.data(mDrop);
-    }
-}
diff --git a/libs/rs/java/Fall/src/com/android/fall/rs/FallView.java b/libs/rs/java/Fall/src/com/android/fall/rs/FallView.java
deleted file mode 100644
index 7468d2b..0000000
--- a/libs/rs/java/Fall/src/com/android/fall/rs/FallView.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2009 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.fall.rs;
-
-import android.content.Context;
-import android.view.SurfaceHolder;
-import android.view.MotionEvent;
-import android.view.KeyEvent;
-import android.renderscript.RenderScript;
-import android.renderscript.RSSurfaceView;
-
-class FallView extends RSSurfaceView {
-    private FallRS mRender;
-
-    public FallView(Context context) {
-        super(context);
-        setFocusable(true);
-        setFocusableInTouchMode(true);
-    }
-
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-
-        RenderScript RS = createRenderScript(false);
-        mRender = new FallRS(w, h);
-        mRender.init(RS, getResources());
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent event) {
-        switch (event.getAction()) {
-            case MotionEvent.ACTION_DOWN:
-            case MotionEvent.ACTION_MOVE:
-                mRender.addDrop(event.getX(), event.getY());
-                try {
-                    Thread.sleep(16);
-                } catch (InterruptedException e) {
-                    // Ignore
-                }
-                break;
-        }
-        return true;
-    }
-}
diff --git a/media/libstagefright/AMRExtractor.cpp b/media/libstagefright/AMRExtractor.cpp
new file mode 100644
index 0000000..4772aca
--- /dev/null
+++ b/media/libstagefright/AMRExtractor.cpp
@@ -0,0 +1,238 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "AMRExtractor"
+#include <utils/Log.h>
+
+#include <media/stagefright/AMRExtractor.h>
+#include <media/stagefright/DataSource.h>
+#include <media/stagefright/MediaBufferGroup.h>
+#include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/MediaErrors.h>
+#include <media/stagefright/MediaSource.h>
+#include <media/stagefright/MetaData.h>
+#include <utils/String8.h>
+
+namespace android {
+
+class AMRSource : public MediaSource {
+public:
+    AMRSource(const sp<DataSource> &source, bool isWide);
+
+    virtual status_t start(MetaData *params = NULL);
+    virtual status_t stop();
+
+    virtual sp<MetaData> getFormat();
+
+    virtual status_t read(
+            MediaBuffer **buffer, const ReadOptions *options = NULL);
+
+protected:
+    virtual ~AMRSource();
+
+private:
+    sp<DataSource> mDataSource;
+    bool mIsWide;
+
+    off_t mOffset;
+    int64_t mCurrentTimeUs;
+    bool mStarted;
+    MediaBufferGroup *mGroup;
+
+    AMRSource(const AMRSource &);
+    AMRSource &operator=(const AMRSource &);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+AMRExtractor::AMRExtractor(const sp<DataSource> &source)
+    : mDataSource(source),
+      mInitCheck(NO_INIT) {
+    String8 mimeType;
+    float confidence;
+    if (SniffAMR(mDataSource, &mimeType, &confidence)) {
+        mInitCheck = OK;
+        mIsWide = (mimeType == "audio/amr-wb");
+    }
+}
+
+AMRExtractor::~AMRExtractor() {
+}
+
+size_t AMRExtractor::countTracks() {
+    return mInitCheck == OK ? 1 : 0;
+}
+
+sp<MediaSource> AMRExtractor::getTrack(size_t index) {
+    if (mInitCheck != OK || index != 0) {
+        return NULL;
+    }
+
+    return new AMRSource(mDataSource, mIsWide);
+}
+
+sp<MetaData> AMRExtractor::getTrackMetaData(size_t index) {
+    if (mInitCheck != OK || index != 0) {
+        return NULL;
+    }
+
+    return makeAMRFormat(mIsWide);
+}
+
+// static
+sp<MetaData> AMRExtractor::makeAMRFormat(bool isWide) {
+    sp<MetaData> meta = new MetaData;
+    meta->setCString(kKeyMIMEType, isWide ? "audio/amr-wb" : "audio/3gpp");
+    meta->setInt32(kKeyChannelCount, 1);
+    meta->setInt32(kKeySampleRate, isWide ? 16000 : 8000);
+
+    return meta;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+AMRSource::AMRSource(const sp<DataSource> &source, bool isWide)
+    : mDataSource(source),
+      mIsWide(isWide),
+      mOffset(mIsWide ? 9 : 6),
+      mCurrentTimeUs(0),
+      mStarted(false),
+      mGroup(NULL) {
+}
+
+AMRSource::~AMRSource() {
+    if (mStarted) {
+        stop();
+    }
+}
+
+status_t AMRSource::start(MetaData *params) {
+    CHECK(!mStarted);
+
+    mOffset = mIsWide ? 9 : 6;
+    mCurrentTimeUs = 0;
+    mGroup = new MediaBufferGroup;
+    mGroup->add_buffer(new MediaBuffer(128));
+    mStarted = true;
+
+    return OK;
+}
+
+status_t AMRSource::stop() {
+    CHECK(mStarted);
+
+    delete mGroup;
+    mGroup = NULL;
+
+    mStarted = false;
+    return OK;
+}
+
+sp<MetaData> AMRSource::getFormat() {
+    return AMRExtractor::makeAMRFormat(mIsWide);
+}
+
+status_t AMRSource::read(
+        MediaBuffer **out, const ReadOptions *options) {
+    *out = NULL;
+
+    uint8_t header;
+    ssize_t n = mDataSource->read_at(mOffset, &header, 1);
+
+    if (n < 1) {
+        return ERROR_IO;
+    }
+
+    MediaBuffer *buffer;
+    status_t err = mGroup->acquire_buffer(&buffer);
+    if (err != OK) {
+        return err;
+    }
+
+    if (header & 0x83) {
+        // Padding bits must be 0.
+
+        return ERROR_MALFORMED;
+    }
+
+    unsigned FT = (header >> 3) & 0x0f;
+
+    if (FT > 8 || (!mIsWide && FT > 7)) {
+        return ERROR_MALFORMED;
+    }
+
+    static const size_t kFrameSizeNB[8] = {
+        95, 103, 118, 134, 148, 159, 204, 244
+    };
+    static const size_t kFrameSizeWB[9] = {
+        132, 177, 253, 285, 317, 365, 397, 461, 477
+    };
+
+    size_t frameSize = mIsWide ? kFrameSizeWB[FT] : kFrameSizeNB[FT];
+
+    // Round up bits to bytes and add 1 for the header byte.
+    frameSize = (frameSize + 7) / 8 + 1;
+
+    n = mDataSource->read_at(mOffset, buffer->data(), frameSize);
+
+    if (n != (ssize_t)frameSize) {
+        buffer->release();
+        buffer = NULL;
+
+        return ERROR_IO;
+    }
+
+    buffer->set_range(0, frameSize);
+    buffer->meta_data()->setInt32(
+            kKeyTimeUnits, (mCurrentTimeUs + 500) / 1000);
+    buffer->meta_data()->setInt32(
+            kKeyTimeScale, 1000);
+
+    mOffset += frameSize;
+    mCurrentTimeUs += 20000;  // Each frame is 20ms
+
+    *out = buffer;
+
+    return OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+bool SniffAMR(
+        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+    char header[9];
+
+    if (source->read_at(0, header, sizeof(header)) != sizeof(header)) {
+        return false;
+    }
+
+    if (!memcmp(header, "#!AMR\n", 6)) {
+        *mimeType = "audio/3gpp";
+        *confidence = 0.5;
+
+        return true;
+    } else if (!memcmp(header, "#!AMR-WB\n", 9)) {
+        *mimeType = "audio/amr-wb";
+        *confidence = 0.5;
+
+        return true;
+    }
+
+    return false;
+}
+
+}  // namespace android
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index 20b0da2..c3a4722 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -2,6 +2,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:=                 \
+        AMRExtractor.cpp          \
         CachingDataSource.cpp     \
         DataSource.cpp            \
         FileSource.cpp            \
diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp
index 02a276b..daac539 100644
--- a/media/libstagefright/DataSource.cpp
+++ b/media/libstagefright/DataSource.cpp
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <media/stagefright/AMRExtractor.h>
 #include <media/stagefright/DataSource.h>
 #include <media/stagefright/MediaErrors.h>
 #include <media/stagefright/MP3Extractor.h>
@@ -84,6 +85,7 @@
 void DataSource::RegisterDefaultSniffers() {
     RegisterSniffer(SniffMP3);
     RegisterSniffer(SniffMPEG4);
+    RegisterSniffer(SniffAMR);
 }
 
 }  // namespace android
diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp
index 5f78e12..8afa8e1 100644
--- a/media/libstagefright/MediaExtractor.cpp
+++ b/media/libstagefright/MediaExtractor.cpp
@@ -18,6 +18,7 @@
 #define LOG_TAG "MediaExtractor"
 #include <utils/Log.h>
 
+#include <media/stagefright/AMRExtractor.h>
 #include <media/stagefright/DataSource.h>
 #include <media/stagefright/MP3Extractor.h>
 #include <media/stagefright/MPEG4Extractor.h>
@@ -47,6 +48,9 @@
         return new MPEG4Extractor(source);
     } else if (!strcasecmp(mime, "audio/mpeg")) {
         return new MP3Extractor(source);
+    } else if (!strcasecmp(mime, "audio/3gpp")
+            || !strcasecmp(mime, "audio/amr-wb")) {
+        return new AMRExtractor(source);
     }
 
     return NULL;
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index d01d6af..2e02697 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -49,6 +49,8 @@
     { "audio/mpeg", "OMX.PV.mp3dec" },
     { "audio/3gpp", "OMX.TI.AMR.decode" },
     { "audio/3gpp", "OMX.PV.amrdec" },
+    { "audio/amr-wb", "OMX.TI.WBAMR.decode" },
+    { "audio/amr-wb", "OMX.PV.amrdec" },
     { "audio/mp4a-latm", "OMX.TI.AAC.decode" },
     { "audio/mp4a-latm", "OMX.PV.aacdec" },
     { "video/mp4v-es", "OMX.qcom.video.decoder.mpeg4" },
@@ -65,6 +67,7 @@
 static const CodecInfo kEncoderInfo[] = {
     { "audio/3gpp", "OMX.TI.AMR.encode" },
     { "audio/3gpp", "OMX.PV.amrencnb" },
+    { "audio/amr-wb", "OMX.TI.WBAMR.encode" },
     { "audio/mp4a-latm", "OMX.TI.AAC.encode" },
     { "audio/mp4a-latm", "OMX.PV.aacenc" },
     { "video/mp4v-es", "OMX.qcom.video.encoder.mpeg4" },
@@ -317,6 +320,9 @@
     if (!strcasecmp("audio/3gpp", mime)) {
         codec->setAMRFormat();
     }
+    if (!strcasecmp("audio/amr-wb", mime)) {
+        codec->setAMRWBFormat();
+    }
     if (!strcasecmp("audio/mp4a-latm", mime)) {
         int32_t numChannels, sampleRate;
         CHECK(meta->findInt32(kKeyChannelCount, &numChannels));
@@ -673,6 +679,7 @@
     static const MimeToRole kMimeToRole[] = {
         { "audio/mpeg", "audio_decoder.mp3", "audio_encoder.mp3" },
         { "audio/3gpp", "audio_decoder.amrnb", "audio_encoder.amrnb" },
+        { "audio/amr-wb", "audio_decoder.amrwb", "audio_encoder.amrwb" },
         { "audio/mp4a-latm", "audio_decoder.aac", "audio_encoder.aac" },
         { "video/avc",  "video_decoder.avc", "video_encoder.avc" },
         { "video/mp4v-es", "video_decoder.mpeg4", "video_encoder.mpeg4" },
@@ -1548,6 +1555,37 @@
     }
 }
 
+void OMXCodec::setAMRWBFormat() {
+    if (!mIsEncoder) {
+        OMX_AUDIO_PARAM_AMRTYPE def;
+        InitOMXParams(&def);
+        def.nPortIndex = kPortIndexInput;
+
+        status_t err =
+            mOMX->get_parameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
+
+        CHECK_EQ(err, OK);
+
+        def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
+        def.eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
+
+        err = mOMX->set_parameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
+        CHECK_EQ(err, OK);
+    }
+
+    ////////////////////////
+
+    if (mIsEncoder) {
+        sp<MetaData> format = mSource->getFormat();
+        int32_t sampleRate;
+        int32_t numChannels;
+        CHECK(format->findInt32(kKeySampleRate, &sampleRate));
+        CHECK(format->findInt32(kKeyChannelCount, &numChannels));
+
+        setRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
+    }
+}
+
 void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate) {
     if (mIsEncoder) {
         setRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
@@ -1621,6 +1659,15 @@
             break;
         }
 
+        case OMX_COLOR_Format16bitARGB4444:
+        case OMX_COLOR_Format16bitARGB1555:
+        case OMX_COLOR_Format16bitRGB565:
+        case OMX_COLOR_Format16bitBGR565:
+        {
+            def.nBufferSize = width * height * 2;
+            break;
+        }
+
         default:
             CHECK(!"Should not be here. Unknown color format.");
             break;
diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java
index 10680dd..f3127f3 100644
--- a/services/java/com/android/server/status/StatusBarPolicy.java
+++ b/services/java/com/android/server/status/StatusBarPolicy.java
@@ -19,7 +19,6 @@
 import android.app.AlertDialog;
 import android.bluetooth.BluetoothA2dp;
 import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothError;
 import android.bluetooth.BluetoothHeadset;
 import android.bluetooth.BluetoothIntent;
 import android.bluetooth.BluetoothPbap;
@@ -362,7 +361,7 @@
                     || action.equals(Intent.ACTION_POWER_CONNECTED)) {
                 onBatteryOkay(intent);
             }
-            else if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION) ||
+            else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
                     action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION) ||
                     action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION) ||
                     action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) {
@@ -507,7 +506,7 @@
         filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
         filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
         filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
-        filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
+        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
         filter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION);
         filter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION);
         filter.addAction(BluetoothPbap.PBAP_STATE_CHANGED_ACTION);
@@ -1072,10 +1071,9 @@
         int iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth;
 
         String action = intent.getAction();
-        if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
-            int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
-                                           BluetoothError.ERROR);
-            mBluetoothEnabled = state == BluetoothAdapter.BLUETOOTH_STATE_ON;
+        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
+            mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
         } else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) {
             mBluetoothHeadsetState = intent.getIntExtra(BluetoothIntent.HEADSET_STATE,
                     BluetoothHeadset.STATE_ERROR);